This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RazorHelpers | |
{ | |
// This approach is using WebPages, where there is no concept of a Controller | |
public static string RenderTemplate(string template, object model) | |
{ | |
var page = WebPageBase.CreateInstanceFromVirtualPath("~/templates/" + template + ".cshtml"); | |
var context = new WebPageContext(new HttpContextWrapper(HttpContext.Current), page, null); | |
var htmlWriter = new StringWriter(); | |
// Access your model through PageData["Model"] in the view | |
context.PageData["Model"] = model; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web.Routing; | |
using Umbraco.Web.Mvc; | |
public class CustomRenderControllerFactory : RenderControllerFactory | |
{ | |
// Attempt to resolve an alternative controller | |
// This methods is called for all controllers in the request pipeline including surface controllers and possibly third party controllers. | |
// We need to make sure we only hijack the actual Umbraco page request. | |
public override Type GetControllerType(RequestContext requestContext, string controllerName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspiration taken from http://zslabs.com/articles/svg-background-fill/ | |
// Note that this will replace all provided attributes in all elements in the svg, currently limited to two parameters | |
.icon-color(@src, @color, @attr) { | |
@escape-color: escape("@{color}"); | |
@data-uri: data-uri('image/svg+xml;charset=UTF-8', "@{src}"); | |
@attr1: extract(@attr, 1); | |
@attr2: extract(@attr, 2); | |
@val1: replace("@{data-uri}", "@{attr1}%3D%22(.*?)%22", "@{attr1}%3D%22@{escape-color}%22", "gi"); | |
@val2: replace("@{val1}", "@{attr2}%3D%22(.*?)%22", "@{attr2}%3D%22@{escape-color}%22", "gi"); | |
background-image: e(@val2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var breakpoints = { | |
xs: 480, | |
sm: 768, | |
md: 992, | |
lg: 1200 | |
}, | |
currentWidth = 0, | |
currentBreakpoint = "", | |
breakpointMethods = []; // array of methods to be run whenever a breakpoint change is registered |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @RowCount int, @tablename varchar(100) | |
declare @Tables table ( | |
PK int IDENTITY(1,1), | |
tablename varchar(100), | |
processed bit | |
) | |
INSERT into @Tables (tablename) | |
SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' and TABLE_NAME not like 'dt%' order by TABLE_NAME asc | |
declare @Space table ( | |
name varchar(100), rows nvarchar(100), reserved varchar(100), data varchar(100), index_size varchar(100), unused varchar(100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var contentService = ApplicationContext.Current.Services.ContentService; | |
var roots = contentService.GetRootContent(); | |
IContent nodeItem = null; | |
foreach (var root in roots) | |
{ | |
nodeItem = contentService.GetDescendants(root).FirstOrDefault(x => x.Properties.FirstOrDefault(y => y.Alias == "somePropertyAlias").Value.ToString() == "SomeValue"); | |
if (nodeItem != null) | |
break; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UmbracoHooks : IApplicationEventHandler | |
{ | |
private static readonly List<int> PublishFixes = new List<int>(); | |
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
ContentService.Publishing += (sender, args) => | |
{ | |
foreach (var contentItem in args.PublishedEntities) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ReIndexEntity(IContentBase entity) | |
{ | |
if (entity is IContent) | |
{ | |
ExamineManager.Instance.ReIndexNode((entity as IContent).ToXml(), "content"); | |
} | |
else if (entity is IMedia) | |
{ | |
ExamineManager.Instance.ReIndexNode((entity as IMedia).ToXml(), "media"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool TryFindContent(PublishedContentRequest contentRequest) | |
{ | |
if (contentRequest.Is404) | |
{ | |
var site = SiteHelpers.GetSite(); | |
var page404 = site.Get404Page(); | |
if (page404 != null) | |
{ | |
contentRequest.PublishedContent = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(page404.Id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContextHelpers | |
{ | |
public static UmbracoContext EnsureUmbracoContext() { | |
if (UmbracoContext.Current != null) | |
{ | |
return UmbracoContext.Current; | |
} | |
var httpContext = new HttpContextWrapper(HttpContext.Current ?? new HttpContext(new SimpleWorkerRequest("temp.aspx", "", new StringWriter()))); | |