Skip to content

Instantly share code, notes, and snippets.

View alanmac's full-sized avatar

Alan Mac Kenna alanmac

View GitHub Profile
public IPublishedContent GetGlobalContentNode()
{
return (IPublishedContent)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem("Application.BusinessLogic.Services.GetGlobalContentNode", () => {
var settingsNode = GetNonPageContentNode();
//Get the child folder node - Configuration Folder
var configFolder = settingsNode.Children.SingleOrDefault(x => x.DocumentTypeAlias == Constants.DocTypes.SiteConfigurationFolder);
if (configFolder == null) { return null; }
var globalNode = Getto.Get("theCacheKey", () => MyTreeCrawler.GetGlobalContentNode());
Caching result of https://gist.github.com/anthonydotnet/bbffa6db42d9bc933cfde053df67571d
public IPublishedContent GetGlobalContentNode()
{
const string CacheKey = "Application.BusinessLogic.Services.GetGlobalContentNode";
var globalContentNode = HttpContext.Current.Items[CacheKey] as IPublishedContent;
if (globalContentNode == null)
{
var settingsNode = GetNonPageContentNode();
@dawoe
dawoe / DefaultController.cs
Created November 7, 2017 08:20
Donut Cache examples from Umbraco UK Festival talk "The need for speed"
public class DefaultController : RenderMvcController
{
[UmbracoDonutOutputCache(CacheProfile = "LongPageCache",
Options = OutputCacheOptions.NoCacheLookupForPosts &
OutputCacheOptions.ReplaceDonutsInChildActions, Order = 100)]
public override ActionResult Index(RenderModel model)
{
return base.Index(model);
}
}
@tompipe
tompipe / NestedContentEditorGroupHandler.cs
Created October 7, 2016 12:17
Nested Content Property Editor Grouping
public class NestedContentEditorGroupHandler : ApplicationEventHandler
{
protected override void OnApplicationStarted(object sender, EventArgs e)
{
base.OnApplicationStarted(sender, e);
var dtMap = Mapper.FindTypeMapFor<IDataTypeDefinition, DataTypeBasic>();
dtMap?.AddAfterMapAction((s, d) =>
{
var src = (IDataTypeDefinition) s;
@JimBobSquarePants
JimBobSquarePants / ImageProcessorPreProcessor.cs
Created July 23, 2015 15:40
Demonstration code for Preprocessing uploaded images with Umbraco
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ImageProcessorPreProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Attaches ImageProcessor to the Media.Saving event to ensure that uploaded files do not exceed
// a maximum size.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

By using my Skybrud.Umbraco.GridData package (which introduces a strongly typed model for the Grid), indexing the new Grid in Umbraco 7.2 is quite easy.

At Skybrud.dk we typically create a class named ExamineIndexer that takes care of the Examine related events. This class should be initalized during Umbraco startup like this:

using Umbraco.Core;

namespace FanoeTest {

 public class Startup : ApplicationEventHandler {
@alindgren
alindgren / XMLSitemap.cshtml
Last active May 15, 2020 17:42
XML sitemap for Umbraco 7 (based on Cultiv Search Engine Sitemap package). See http://www.alexlindgren.com/archive/dynamically-generated-xml-sitemaps-with-umbraco-7/
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Linq;
@{
Layout = null;
Response.ContentType = "text/xml";
}<?xml version='1.0' encoding='UTF-8' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
@ListChildNodes(Umbraco.TypedContent(UmbracoContext.Current.PageId).AncestorOrSelf(1))
@leekelleher
leekelleher / ForceEmptyRecycleBin.sql
Last active July 18, 2020 11:15
Umbraco: Force empty the Recycle Bin
-- Uncomment below to verify the number of nodes returned is the same as the number of nodes that is in the Recycle Bin
-- SELECT * FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20
-- Delete all 'related' nodes and table contents...
DELETE FROM cmsPreviewXml WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsContentVersion WHERE contentId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsDocument WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsContentXML WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsContent WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsPropertyData WHERE contentNodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)