Skip to content

Instantly share code, notes, and snippets.

View micklaw's full-sized avatar
🏴󠁧󠁢󠁳󠁣󠁴󠁿
In contract until Jun 21

Michael Law micklaw

🏴󠁧󠁢󠁳󠁣󠁴󠁿
In contract until Jun 21
View GitHub Profile
public static void Method<T>(string something) {
}
@micklaw
micklaw / gist:fb6dbdd50510a659025e
Created May 3, 2015 14:41
Umbraco route startup
public static void RegisterRoutes(RouteCollection routes)
{
var umbraco = new Route("{*url}", new RouteValueDictionary() { }, new RouteValueDictionary() { { "url", new YomegoCMSRouteConstraint() } }, new YomegoCMSRouteHandler());
routes.Add(umbraco);
}
public class YomegoCMSRouteConstraint : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
return IsRoutable(httpContext);
}
private bool PopulateContext(CoreApp<CoreServiceContainer> app, HttpContextBase context, string url, UmbracoRouteAttribute contentType = null)
{
// [ML ] -If this request has previously been routed, do nothing and route as context is populated
@micklaw
micklaw / gist:0e3b4167651b1bb4ee07
Created May 3, 2015 14:59
Umbraco routing IHttpHandler
public class YomegoCMSHandler : IHttpHandler
{
public bool IsReusable { get; private set; }
private RequestContext _requestContext { get; set; }
public YomegoCMSHandler(RequestContext requestContext)
{
_requestContext = requestContext;
[UmbracoRoute("Home", Action = "Index")] // [ML] - index not required really, just added for demo purposes
public class Homepage : Page
{
public Homepage(IPublishedContent content) : base(content) { }
public string Title { get; set; }
}
@micklaw
micklaw / gist:a9e41b513fd7dfd69ea8
Created May 8, 2015 15:37
Inject Examine Fields
public void InjectToExamineNode(int id, Dictionary<string, string> newFields = null)
{
if (newFields.HasContent())
{
var content = new Content(id);
if (content.Id > 0)
{
var doc = content.ToXDocument(false).Root;
@micklaw
micklaw / gist:bb9d2395e4598c3a73b7
Created May 8, 2015 15:40
Custom Examine Indexer
public class CustomIndexer : UmbracoContentIndexer
{
public override void ReIndexNode(XElement node, string type)
{
this.EnqueueIndexOperation(new IndexOperation
{
Operation = IndexOperationType.Add,
Item = new IndexItem(node, type, (string)node.Attribute("id"))
});
@micklaw
micklaw / gist:198864d9bc9087b3f755
Created May 8, 2015 15:43
Save new Examine Fields Event
void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
// [ML] - Grab any properties that have been injected via IndexingNodeDataEventArgs 'node' and input them
if (e.IndexType == IndexTypes.Content)
{
foreach (var node in e.Node.Elements())
{
if (!e.Fields.ContainsKey(node.Name.LocalName))
{
@micklaw
micklaw / gist:c159c4d05d09dd4d341c
Last active August 29, 2015 14:22
Archetype Value Resolver
namespace Our.Umbraco.Ditto.Resolvers.Archetype.Resolvers
{
public class ArchetypeValueResolver : DittoValueResolver<ArchetypeResolverAttribute>
{
public override object ResolveValue(ITypeDescriptorContext context, ArchetypeResolverAttribute attribute, CultureInfo culture)
{
var content = context.Instance as IPublishedContent;
var descriptor = context.PropertyDescriptor;
if (content != null && descriptor != null)
namespace Ditto.Resolvers.Sample.Models.Archetypes
{
public class PriceList : ArchetypeFieldsetModel
{
public string Title { get; set; }
public int Quantity { get; set; }
public string Price { get; set; }