CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets for: Glenn Block
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Json;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Web;
by Glenn Block   February 19, 2012 @ 9:13pm
Tags:
237 Views
no comments
 
C#
 
[TestClass]
public class RavenDbRepositoryTests
{
    private RavenDbRepository repo;
    private const string collectionName = "tests";
    private const string serverUri = "http://localhost:8080";
    private FakeHandler handler;
 
    [TestInitialize]
by Glenn Block   February 19, 2012 @ 9:09pm
Tags:
53 Views
no comments
 
C#
public class FakeHandler : System.Net.Http.DelegatingHandler
{
    public HttpRequestMessage LastRequest { get; set; }
    public HttpResponseMessage Response { get; set; }
 
    protected override System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
    {
        LastRequest = request;
        if (Response == null)
            Response = base.Send(request, cancellationToken);
by Glenn Block   February 19, 2012 @ 8:02pm
Tags:
182 Views
no comments
 
C#
[InheritedExport]
public interface ICompositionRoot {
  void Compose() 
}
 
public class Bootstrapper : IDisposable {
  private CompositionContainer _container;
 
  public Composer(CompositionContainer container) {
  }
by Glenn Block   October 15, 2011 @ 10:53am
Tags:
355 Views
no comments
 
C#
public class MefConfiguration : HttpConfiguration
{
    public MefConfiguration(CompositionContainer container)
    {
        SetServiceInstanceProvider((t, i, m) =>
        {
            var contract = AttributedModelServices.GetContractName(t);
            var identity = AttributedModelServices.GetTypeIdentity(t);
 
            // force non-shared so that every service doesn't need to have a [PartCreationPolicy] attribute.
by Glenn Block   August 30, 2011 @ 10:47pm
Tags:
194 Views
no comments
 
C#
protected void Application_Start(object sender, EventArgs e)
{
    // use MEF for providing instances
    var catalog = new AssemblyCatalog(typeof(Global).Assembly);
    var container = new CompositionContainer(catalog);
    var config = new MefConfiguration(container);
    RouteTable.Routes.SetDefaultHttpConfiguration(config);
 
    config.Formatters.AddRange(
            new ContactPngFormatter(),
by Glenn Block   August 30, 2011 @ 10:43pm
Tags:
265 Views
no comments
 
C#
public class ETagHandler : DelegatingHandler
{
    internal static ConcurrentDictionary<string, EntityTagHeaderValue> ETagCache = new ConcurrentDictionary<string, EntityTagHeaderValue>();
 
    protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
    {
        if (request.Method == HttpMethod.Get)
        {
            // should we ignore trailing slash
            string resource = request.RequestUri.ToString();
by Glenn Block   August 04, 2011 @ 11:17am
Tags:
272 Views
no comments
 
C#
public class static XamlComposer {
  public static void SetComposer(ICompositionRootComposer composer){
  }
 
  public static void Compose<T>(ICompositionRoot<T> root) {
    //resolve T from the container and set root.Component.
  }
} 
 
public class AuditBehavior : DependencyObject, ICompositionRoot<AuditBehaviorComponent>
by Glenn Block   August 01, 2011 @ 2:34pm
Tags:
100 Views
no comments
 
C#
    public class ForceJsonHandler : DelegatingHandler
    {
        protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            if (ShouldForceJson(request))
            {
                request.Headers.Accept.Clear(); //clear the accept and replace it to use JSON.
                request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            }
            return base.SendAsync(request, cancellationToken);
by Glenn Block   July 11, 2011 @ 1:31am
Tags:
761 Views
3 comments
 
C#
[ServiceContract]
public class ContactResource
{
    IContactRepository repository;
 
    public ContactResource(IContactRepository repository)
    {
        this.repository = repository;
    }
by Glenn Block   May 26, 2011 @ 1:21pm
Tags:
280 Views
no comments
 
C#
public class MyConfig : HttpHostConfiguration {
  public HttpHostConfiguration
  {
    SetRequestOperationHandlers(new myHandler());
    SetResponsOperationHandlers(new anotherHandler());
  }
}
by Glenn Block   March 31, 2011 @ 10:31am
Tags:
214 Views
no comments
 
C#
var builder = HttpHostConfiguration.Create().
    RequestHandlers.
      Add(new SpecialRequestHandler()).
      Add(new AnotherRequestHandler()).
      When((o,s)=>o.Name.StartsWith("Foo")
    ResponseHanders.
      Add(new GlobalRequestHandler()).
      Always()
 
by Glenn Block   March 31, 2011 @ 10:23am
Tags:
265 Views
2 comments
 
C#
public class UriExtensionProcessor : Processor<HttpRequestMessage,Uri>
{
    private IEnumerable<Tuple<string,string>> extensionMappings;
 
    public UriExtensionProcessor(IEnumerable<Tuple<string, string>> extensionMappings)
    {
        this.extensionMappings = extensionMappings;
        this.OutArguments[0].Name = HttpPipelineFormatter.ArgumentUri;
    }
 
by Glenn Block   March 07, 2011 @ 4:58am
Tags:
180 Views
no comments
 
C#
public interface IRequestFactory
{
    IRequest Create(Stream body);
}
 
public class RequestFactory : IRequestFactory
{
    public IRequest Create(Stream body)
    {
        var wcfRequest = WebOperationContext.Current.IncomingRequest;
by Glenn Block   December 17, 2010 @ 1:07am
Tags:
470 Views
no comments
 
C#
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[ServiceContract]
public class WcfOwinHost
{
    private IApplication _application;
    private IRequestFactory _requestFactory;
    private IResponseMessageFactory _responseFactory;
 
    public WcfApplication(IApplication application, IRequestFactory requestFactory, IResponseMessageFactory responseFactory)
    {
by Glenn Block   December 17, 2010 @ 1:02am
Tags:
400 Views
no comments
 
C#
class Program
{
    static void Main(string[] args)
    {
        var host = new WebServiceHost(typeof (Application), new Uri("http://localhost"));
        host.Open();
        Console.WriteLine("Server is running");
        Console.ReadLine();
        host.Close();
    }
by Glenn Block   December 16, 2010 @ 12:00am
Tags:
390 Views
no comments
 
C#
public class OrderMediaTypeProcessor : MediaTypeProcessor
{
    public OrderMediaTypeProcessor(HttpOperationDescription operation, MediaTypeProcessorMode mode)
        :base(operation, mode)
    {
        
    }
 
    public override IEnumerable<string> SupportedMediaTypes
    {
by Glenn Block   November 11, 2010 @ 1:53am
Tags:
444 Views
no comments
 
C#
public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        var builder = new ContainerBuilder();
        builder.RegisterType<ContactResource>();
        builder.RegisterType<ContactsResource>();
        builder.RegisterType<ContactRepository>().As<IContactRepository>();
 
        var configuration = new ContactManagerConfiguration(builder.Build());
by Glenn Block   November 10, 2010 @ 7:39am
Tags: WCF
538 Views
7 comments
 
C#
public interface IEntityTag
{
    string EntityTag {get;}
}
 
public class TypedETagResponseProcessor : Processor<object,HttpResponseMessage, object>
{
 
    private static ConcurrentDictionary<Uri, string> etags;
by Glenn Block   November 03, 2010 @ 12:01am
Tags:
253 Views
2 comments
 
C#
// Generates ETags automatically based on the return value.
 
public interface IEntityTag
{
    string EntityTag {get;}
}
 
public class ETagResponseProcessor : Processor
{
    private ProcessorArgument returnValue;
by Glenn Block   November 02, 2010 @ 4:44pm
Tags:
400 Views
5 comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate