Skip to content

Instantly share code, notes, and snippets.

View btompkins's full-sized avatar

Brendan Tompkins btompkins

View GitHub Profile
@btompkins
btompkins / gist:4392572
Last active December 10, 2015 06:08
Nancy Bootstrapper for using the NServiceBus' container.
using System;
using System.Collections.Generic;
using System.Linq;
using NServiceBus;
using NServiceBus.ObjectBuilder.Common;
using Nancy;
using Nancy.Bootstrapper;
using Nancy.Diagnostics;
public class NServiceBusContainerBootstrapper : NancyBootstrapperWithRequestContainerBase<IContainer>
location ^~ /cgi-bin/munin-cgi-graph/ {
fastcgi_split_path_info ^(/cgi-bin/munin-cgi-graph)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fastcgi-graph.sock;
include fastcgi_params;
}
location /munin/static/ {
alias /etc/munin/static/;
}
spawn-fcgi -s /var/run/munin/fastcgi-graph.sock -U www-data \
-u munin -g munin /usr/lib/cgi-bin/munin-cgi-graph
spawn-fcgi -s /var/run/munin/fastcgi-html.sock -U www-data \
-u munin -g munin /usr/lib/cgi-bin/munin-cgi-html
public class Location
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
public class LocationProcessor : Processor<string, string, Location>
{
public LocationProcessor()
{
var client = new HttpClient();
client.DefaultHeaders.Accept.Add("text/xml");
var resp = client.Get("http://contoso.com/contacts/1");
resp.Content.ReadAsXmlSerializable<Contact>();
[ServiceContract]
public class DocumentResource
{
[WebGet(UriTemplate="{name}")]
public Document Get(string name, HttpResponseMessage resp)
{
Document doc;
[ServiceContract]
public class HelloWorldResource {
[WebGet(UriTemplate="")]
public void Get(HttpRequestMessage req, HttpResponseMessage resp) {
if (req.IfNoneMatch.Contains("HW")) {
resp.StatusCode = HttpStatusCode.NotModified;
return;
}
public IEnumerable<Order> GetApprovedOrders()
{
string address = "http://contoso.com/orders";
HttpClient client = new HttpClient(address);
WebQuery<Order> orders = client.CreateQuery<Contact>();
return orders.Where<Order>(o=>o.State == OrderState.Approved). OrderBy(o=o.OrderID);
}
[WebGet(UriTemplate = "")]
[QueryComposition]
public IEnumerable<Contact> Get()
{
return contacts.AsQueryable();
}
public class JsonValueSampleConfiguration : HostConfiguration
{
public override void RegisterRequestProcessorsForOperation( HttpOperationDescription operation, IList<Processor> processors, MediaTypeProcessorMode mode)
{
processors.Add(new FormUrlEncodedProcessor(operation, mode));
}
public override void RegisterResponseProcessorsForOperation( HttpOperationDescription operation, IList<Processor> processors, MediaTypeProcessorMode mode)
{
processors.ClearMediaTypeProcessors();