Skip to content

Instantly share code, notes, and snippets.

View HenrikFrystykNielsen's full-sized avatar

Henrik Frystyk Nielsen HenrikFrystykNielsen

View GitHub Profile
@HenrikFrystykNielsen
HenrikFrystykNielsen / SelfHostWithAssembliesResolver.cs
Created June 10, 2012 23:56
ASP.NET Web API: Controlling assemblies loaded by providing own AssembliesResolver
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using System.Web.Http.SelfHost;
namespace SelfHost
{
@HenrikFrystykNielsen
HenrikFrystykNielsen / SampleHandler.cs
Created June 14, 2012 16:38
Sample HttpMessageHandler doing async retrieval using .NET 4.5
using System;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace SelfHost.MessageHandlers
{
/// <summary>
/// This sample HttpMessageHandler illustrates how to perform an async operation as part of the
@HenrikFrystykNielsen
HenrikFrystykNielsen / CardStatus.cs
Created June 27, 2012 14:07
Asynchronous HTML form data submit using async/await in .NET 4.5 and FormUrlEncodedContent
using System;
using System.Collections.Generic;
using System.Net.Http;
namespace CardStatus
{
class Program
{
static async void RunCheck(int antragsnummer)
{
@HenrikFrystykNielsen
HenrikFrystykNielsen / SampleFilter.cs
Created June 28, 2012 17:57
Sample ActionFilter with pre- and post-action synchronous processing
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
namespace ActionFilter
{
public class SampleFilter : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
}
@HenrikFrystykNielsen
HenrikFrystykNielsen / HttpContentProcessor.cs
Created July 2, 2012 18:19
Sample showing a DelegatingHandler which plugs in a special HttpContent wrapper for saving response content to local disk and perform asynchronous post-processing on that file. This allows content from a response to be post-processed, for example to send
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace ResponseEntityProcessor.Handlers
{
/// <summary>
/// Wraps an inner <see cref="HttpContent"/> and forces the content to be written
@HenrikFrystykNielsen
HenrikFrystykNielsen / Program.cs
Created September 5, 2012 20:43
Tweaked perf run
using System;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.SelfHost;
namespace leveldb_sharp_sample
{
public class WebHost
@HenrikFrystykNielsen
HenrikFrystykNielsen / WebApiConfig
Created March 28, 2014 15:33
Gist of how to hook in additional OWIN authentication providers
using System.Web.Http;
using Autofac;
using Microsoft.WindowsAzure.Mobile.Service;
using Microsoft.WindowsAzure.Mobile.Service.Config;
using Owin;
namespace henrikntest09Service
{
public static class WebApiConfig
{
@HenrikFrystykNielsen
HenrikFrystykNielsen / WebApiConfig.cs
Created April 3, 2014 03:18
Workaround for lost NotificationHub ConnectionString. The NotificationHub ConnectionString can get lost after the app has been running for a while. We will be updating the service shortly but in the mean time here is a workaround that fixes the issue.
public static class WebApiConfig
{
public static void Register()
{
ConfigOptions options = new ConfigOptions();
HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));
// Workaround for notification hub connection string going missing.
IServiceSettingsProvider settingsProvider = config.DependencyResolver.GetServiceSettingsProvider();
ServiceSettingsDictionary settings = settingsProvider.GetServiceSettings();
@HenrikFrystykNielsen
HenrikFrystykNielsen / gist:a0b9a51645633b7919a1
Created November 5, 2015 06:01
WebHookSender: Register custom WebHookManager using Autofac
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
@HenrikFrystykNielsen
HenrikFrystykNielsen / DbWebHookStore
Last active September 26, 2016 01:20
Sample SqlWebHookStore structuring allowing for other DbContext and Entity definitions
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core;
using System.Data.Entity.Infrastructure;