Skip to content

Instantly share code, notes, and snippets.

Avatar
🐻
Still learning...

Sean G. Wright seangwright

🐻
Still learning...
View GitHub Profile
@seangwright
seangwright / EmailMacroMethodContainer.cs
Created Jan 21, 2021
Reusable Xperience Email Transformations
View EmailMacroMethodContainer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using CMS;
using CMS.Helpers;
using CMS.MacroEngine;
using CMS.PortalEngine;
using CMS.SiteProvider;
using Sandbox.Infrastructure.Emails;
@seangwright
seangwright / web.config
Created Jan 19, 2021
Sample web.config from Kentico Xperience 13.0 Content Management application
View web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- Content staging BEGIN -->
<section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<!-- Content staging END -->
<!-- AjaxControlToolkit BEGIN -->
<section name="ajaxControlToolkit" type="AjaxControlToolkit.AjaxControlToolkitConfigSection, AjaxControlToolkit" requirePermission="false" />
<!-- AjaxControlToolkit END -->
</configSections>
@seangwright
seangwright / README.md
Created May 6, 2020
README sample for Kentico projects
View README.md

project-code-name

Kentico 12 MVC application for <...>

Current Kentico

12.0.68

.NET Framework

@seangwright
seangwright / settings.json
Last active Oct 21, 2019
VS Code workspace settings for a Kentico 12 MVC + Vue.js CLI project
View settings.json
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"node_modules": true,
"obj": true,
"bin": true,
View PageTypeRouteAttributeCacheHelperCacheHelper.cs
public static class PageTypeRouteAttributeCacheHelper
{
public static readonly Dictionary<string, ControllerActionPair> ClassNameLookup;
static PageTypeRouteAttributeCacheHelper()
{
var controllerTypes = typeof(PageTypeRouteAttributeCacheHelper)
.Assembly
.GetTypes()
.Where(t =>
@seangwright
seangwright / JsonDotNetValueProviderFactory.cs
Created Jun 26, 2019
Custom Json Serialization for ASP.NET MVC
View JsonDotNetValueProviderFactory.cs
/// <summary>
/// From https://github.com/garysharp/Disco/commit/1dfa3f4f15fe4fc093e90e4cd490dd06cc30cf07
/// </summary>
public class JsonDotNetValueProviderFactory : ValueProviderFactory
{
private readonly JsonSerializerSettings serializerSettings;
public JsonDotNetValueProviderFactory(JsonSerializerSettings serializerSettings)
{
Guard.Against.Null(serializerSettings, nameof(serializerSettings));
@seangwright
seangwright / ApiExceptionResult.cs
Last active Jun 26, 2019
Error Handling in Web Api 2
View ApiExceptionResult.cs
public class ApiExceptionResult : IHttpActionResult
{
private static readonly MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/json");
private readonly ApiError errorResponse;
private readonly JsonMediaTypeFormatter jsonMediaTypeFormatter;
private readonly HttpRequestMessage requestMessage;
private readonly HttpStatusCode statusCode;
public ApiExceptionResult(HttpRequestMessage requestMessage, HttpStatusCode statusCode, ApiError errorResponse, JsonMediaTypeFormatter jsonMediaTypeFormatter)
@seangwright
seangwright / KenticoMvcApp.csproj
Last active Jun 26, 2019
WebApi2 Swashbuckle integration
View KenticoMvcApp.csproj
<!-- Add this to ensure the XML comments are picked up by the Swashbuckle integration -->
<PropertyGroup>
<DocumentationFile>bin\KenticoMvcApp.xml</DocumentationFile>
</PropertyGroup>
View UserInfoTests.cs
[TextFixture]
public class UserInfoTests : UnitTests
{
[Test]
public void IsAuthorized_Will_Return_True_When_User_Is_In_All_Roles(
int userId,
string userName,
int siteId,
string siteName,
int roleId1,
@seangwright
seangwright / DependencyResolverConfig.cs
Last active Jul 10, 2019
Kentico 12: Design Patterns Part 4 - Adding Dependency Injection to the CMS
View DependencyResolverConfig.cs
public static class DependencyResolverConfig
{
public static IContainer BuildContainer()
{
var builder = new ContainerBuilder();
// My registration classes use a "fluent" interface, always returning the ContainerBuilder
// so the next call can be chained off the previous
var container = builder
.RegisterApplicationTypes()