Skip to content

Instantly share code, notes, and snippets.

@davidknipe
davidknipe / EPiServer-Powerslice-Example-Slices.cs
Last active Aug 29, 2015
EPiServer Powerslice example slides
View EPiServer-Powerslice-Example-Slices.cs
[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
public class PagesSlice : ContentSliceBase<StandardPage>
{
public override string Name
{
get { return "Pages"; }
}
}
[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
@davidknipe
davidknipe / Auth0SynchronizingUserService.cs
Created Feb 15, 2015
Custom SynchronizingUserService implementation for Auth0 when using EPiServer
View Auth0SynchronizingUserService.cs
public class Auth0SynchronizingUserService : SynchronizingUserService
{
public override Task SynchronizeAsync(ClaimsIdentity identity)
{
//Transform the passed http:/schemas.auth0.com/roles claims to System.Security.Claims
foreach (var claim in identity.Claims)
{
if (claim.Type == "http://schemas.auth0.com/roles")
{
identity.AddClaim(new Claim(ClaimTypes.Role, claim.Value));
View Example-Auth0-rule.js
function (user, context, callback) {
user.roles = [];
if (user.name.indexOf('Jones') > -1)
{
user.roles.push('WebAdmins');
user.roles.push('WebEditors');
}
// all users are member of public
@davidknipe
davidknipe / Index.cshtml
Last active Aug 29, 2015
Claims helper block
View Index.cshtml
@model ListAllClaimsModel
<div>
<h3>@Model.BlockTitle</h3>
<table class="table table-striped table-condensed">
@*<thead>
<tr>
<th>Claims</th>
</tr>
@davidknipe
davidknipe / PriceEventListenerInit.cs
Last active Aug 29, 2015
Example PriceEvent listener for the PriceEvents for EPiServer Commerce
View PriceEventListenerInit.cs
[InitializableModule]
[ModuleDependency( typeof(EPiServer.Web. InitializationModule))]
public class PriceEventListenerInit : IInitializableModule
{
public void Initialize( InitializationEngine context)
{
var priceEvents = ServiceLocator.Current.GetInstance<IPriceEvents>();
priceEvents.PriceChanged += contentEvents_PriceChanged;
}
@davidknipe
davidknipe / AddMetaClass.cs
Created Mar 5, 2015
Create an EPiServer Commerce Metafield programmatically and add it to a Metaclass in Business Foundation
View AddMetaClass.cs
/// <summary>
/// Programmatically create a new MetaField on the Contact MetaClass <seealso href="http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/8/Business-Foundation/Business-Meta-Model/MetaField-class/"/>
/// </summary>
private void setupMetaField()
{
MetaClassManager metaModel = DataContext.Current.MetaModel;
foreach (MetaClass mc in metaModel.MetaClasses)
{
if (mc.Name == "Contact")
{
@davidknipe
davidknipe / DebugAwareContentOutputCacheAttribute.cs
Created Mar 11, 2015
Debugger aware ContentOutputCacheAttribute for EPiServer - only output caches if a debugger is not attached
View DebugAwareContentOutputCacheAttribute.cs
public class DebugAwareContentOutputCacheAttribute : ContentOutputCacheAttribute
{
public override bool Disable
{
get
{
if (System.Diagnostics.Debugger.IsAttached)
{
return true;
}
@davidknipe
davidknipe / CustomIDatabaseFactory
Last active Aug 29, 2015
Custom IDatabaseFactory implementation for EPiServer
View CustomIDatabaseFactory
public class CustomIDatabaseFactory : SqlDatabaseFactory, IDatabaseFactory
{
public new IDatabaseHandler CreateDefaultHandler()
{
SiteDataSettingsElement currentSiteSettings = this.GetCurrentSiteSettings();
ConnectionStringSettings connectionStringSettings = EPiServerDataStoreSection.ConfigurationInstance.ConnectionStrings.ConnectionStrings[currentSiteSettings.ConnectionStringName];
if (connectionStringSettings == null)
{
throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, "No connection string found with the configured name '{0}'.", new object[] { currentSiteSettings.ConnectionStringName }));
}
@davidknipe
davidknipe / OverrideIDatabaseFactoryImpl
Last active Aug 29, 2015
Override default EPiServer IDatabaseFactory implementation
View OverrideIDatabaseFactoryImpl
[InitializableModule]
[ModuleDependency(typeof(ServiceContainerInitialization))]
public class OverrideIDatabaseFactoryImpl : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context)
{
context.Container.Configure(x => { x.For<IDatabaseFactory>().Use<CustomIDatabaseFactory>(); });
}
public void Initialize(InitializationEngine context) { }
@davidknipe
davidknipe / CreateNewProject.cs
Last active Aug 29, 2015
Create an EPiServer Project programmatically
View CreateNewProject.cs
/// <summary>
/// Create a project programmatically
/// </summary>
/// <param name="projectName">The name of the project, e.g. "Weekly article updates"</param>
/// <param name="userName">The username of the person creating the project</param>
/// <returns>The newly created project, null if a project with that name already exists</returns>
public Project CreateNewProject(string projectName, string userName)
{
var repo = ServiceLocator.Current.GetInstance<ProjectRepository>();
var newProject = new Project();
You can’t perform that action at this time.