Skip to content

Instantly share code, notes, and snippets.

Morten Bock mortenbock

Block or report user

Report or block mortenbock

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ConfigFactory.cs
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)
{
View DittoTemplatePage.cs
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
View gist:e21f4a00e068c02f0ab1
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 Oct 10, 2013
Constraining images with imageprocessor
View Constrain.cs
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
View Bootstrapper.cs
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 Aug 1, 2013
Custom viewmodel in Umbraco
View MyModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace UmbSample.Models
{
public class MyModel
{
public string Title { get; set; }
View gist:6086963
<!-- 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>
View gist:4017307
//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 Oct 4, 2012
ImageGen sample implementation
View ImageUrlProvider.cs
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 Sep 28, 2012
Ideas for usage of umbraco:image
View umbracoimage.md

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

You can’t perform that action at this time.