Skip to content

Instantly share code, notes, and snippets.

View thecodejunkie's full-sized avatar

Andreas Håkansson thecodejunkie

View GitHub Profile
namespace NancyEmbeddedTest
{
using System;
using System.Collections.Generic;
using System.Reflection;
using Nancy;
using Nancy.Bootstrapper;
using Nancy.ViewEngines;
public class Modules : NancyModule
@thecodejunkie
thecodejunkie / gist:7569861
Created November 20, 2013 19:51
Sample IResponseProcessor that enables you to return an ordinary response for text/html requests, using the Negotiator.WithMediaRangeModel method
public class ResponseResponseProcessor : IResponseProcessor
{
public IEnumerable<Tuple<string, MediaRange>> ExtensionMappings
{
get
{
return Enumerable.Empty<Tuple<string, MediaRange>>();
}
}
@thecodejunkie
thecodejunkie / ModelValidationError.cs
Created November 7, 2013 21:10
Revised ModelValidationResult spike
/// <summary>
/// A validation error.
/// </summary>
public class ModelValidationError
{
private readonly Func<IEnumerable<string>, string> errorMessageFormatter;
/// <summary>
/// Initializes a new instance of the <see cref="ModelValidationError"/> class.
/// </summary>
@thecodejunkie
thecodejunkie / new.json
Created November 6, 2013 20:58
Changing the way that ModelValidatorDecriptor returns rule information. It is now grouped per model property and it also includes the type name of the model the rules are associated with
{
"ModelType":"Nancy.Demo.Validation.Models.Product",
"Rules":{
"Name":[
{
"MemberNames":[
"Name"
],
"RuleType":"NotEmpty"
},
var existingCustomer = session.Query<Customer>()
.FetchMany(c => c.DeliveryAddresses)
.SingleOrDefault(c => c.CustomerId.Equals(imported.CustomerId));
var existingCustomer = session.Query<Customer>()
.FetchMany(c => c.Users)
.FetchMany(c => c.DeliveryAddresses)
.AsEnumerable()
.SingleOrDefault(c => c.CustomerId.Equals(importedCustomer.CustomerId));
@thecodejunkie
thecodejunkie / gist:6782971
Created October 1, 2013 18:35
Should emit a file in UTF8 without BOM but the BOM is in the file =/
var encoding =
new UTF8Encoding(false);
File.WriteAllText(Path.Combine(outputFolder, SourceFile), result.Body.AsString(), encoding);
@thecodejunkie
thecodejunkie / gist:6298564
Created August 21, 2013 18:48
Sample of how to create HTML extensions for the Nancy Razor view engine
/// <summary>
/// Contains extension methods for the <see cref="Expression"/> type.
/// </summary>
public static class ExpressionExtensions
{
/// <summary>
/// Retrieves the member that an expression is defined for.
/// </summary>
/// <param name="expression">The expression to retreive the member from.</param>
/// <returns>A <see cref="MemberInfo"/> instance if the member could be found; otherwise <see langword="null"/>.</returns>
var page = require('webpage').create();
var system = require('system');
var address;
address = system.args[1];
console.log(address);
page.open(address, function(status) {
console.log(status);
@thecodejunkie
thecodejunkie / DynamicModelBinder.cs
Created May 5, 2013 19:41
Binding to a DynamicDictionary
using System;
using System.Collections.Generic;
using System.Linq;
using Nancy.ModelBinding;
public class DynamicModelBinder : IModelBinder
{
public object Bind(NancyContext context, Type modelType, object instance, BindingConfig configuration, params string[] blackList)
{
var data =