Skip to content

Instantly share code, notes, and snippets.

@mortenbock
mortenbock / ConfigFactory.cs
Created June 1, 2015 11:49
Generic Ditto take 2
using Our.Umbraco.Ditto;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
namespace MappingDemo.Custom.Mvc
{
public class ConfigFactory : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
@mortenbock
mortenbock / DittoTemplatePage.cs
Created June 1, 2015 10:56
Generic Ditto views
using System.Web.Mvc;
using Our.Umbraco.Ditto;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
namespace MappingDemo.Custom.Mvc
{
public abstract class DittoTemplatePage<T> : UmbracoTemplatePage where T : class
public static string GetOptionalMediaUrl(this INode node, string propertyAlias)
{
int? mediaId = node.GetOptionalNullableValue<int>(propertyAlias);
if (mediaId.HasValue)
{
XPathNodeIterator media = library.GetMedia(mediaId.Value, false);
//we look at both //Image and //node, because some media items may not have been saved since the schema changed.
var file = media.Current.SelectSingleNode("//Image/umbracoFile | //node/data[@alias='umbracoFile']");
if (file != null)
return file.InnerXml;
@mortenbock
mortenbock / Constrain.cs
Created October 10, 2013 20:32
Constraining images with imageprocessor
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using ImageProcessor;
using ImageProcessor.Helpers.Extensions;
using ImageProcessor.Processors;
using ImageProcessor.Web.Config;
namespace Demo.ImageProcessors
@mortenbock
mortenbock / Bootstrapper.cs
Created September 21, 2013 16:04
MiniProfiler.UmbracoMvc proof of concept. Blogpost here: http://www.mortenbock.dk/post/Profiling-MVC-views-in-Umbraco-6
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Web.Mvc;
namespace UmbMvcMiniProfiler
{
public class Bootstrapper : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
@mortenbock
mortenbock / MyModel.cs
Created August 1, 2013 21:12
Custom viewmodel in Umbraco
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace UmbSample.Models
{
public class MyModel
{
public string Title { get; set; }
<!-- Ensure Compatability for old log4net version, that has different public key.-->
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
<codeBase version="1.2.10.0" href="bin\log4netv1.2.10.0\log4net.dll" />
</dependentAssembly>
@mortenbock
mortenbock / gist:4017307
Created November 5, 2012 13:58
Extraction sample
//Original
myCollection
.Select(i=> new Foo(i))
.Where(f=>f.IsSomething)
.Select(f=>f.Name);
//Mark these two lines
.Select(i=> new Foo(i))
.Where(f=>f.IsSomething)
@mortenbock
mortenbock / ImageUrlProvider.cs
Created October 4, 2012 17:52
ImageGen sample implementation
namespace UmbImageDemo
{
public class ImageUrlProvider : IImageUrlProvider
{
public string Name
{
get { return "imageGen"; }
}
public string GetImageUrlFromMedia(int mediaId, IDictionary<string, string> parameters)
@mortenbock
mortenbock / umbracoimage.md
Created September 28, 2012 18:11
Ideas for usage of umbraco:image

Suggested sample usage of umbraco:Image

All attributes from the normal <img /> can be used. The idea then is to let different providers help generate the correct src attribute, based on the parameters given by the user. The reason for using an options attribute for input to the provider, is that you might want the server to render the image at a certain size, but not actually have the width attribute on the rendered image.

I have restricted it to images for now. It might be possible to create an umbraco:Media that would handle videos or sound as well, but I think images are the most valuable thing to operate with.

I have created some samples of how I think it could be used.

Regular image