Skip to content

Instantly share code, notes, and snippets.

View darrelmiller's full-sized avatar

Darrel darrelmiller

View GitHub Profile
@darrelmiller
darrelmiller / gist:10682188
Created April 14, 2014 20:56
Create an AppFunc for a WebApi application
public static Func<IDictionary<string, object>, Task> CreateWebApiAppFunc(HttpConfiguration config)
{
var app = new HttpServer(config);
var options = new HttpMessageHandlerOptions()
{
MessageHandler = app,
BufferPolicySelector = new OwinBufferPolicySelector(),
ExceptionLogger = new WebApiExceptionLogger(),
ExceptionHandler = new WebApiExceptionHandler()
};
public class NullJsonHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var response = await base.SendAsync(request, cancellationToken);
if (response.Content == null)
{
response.Content = new StringContent("{}");
public static class TaskHelper
{
public static Task<T> RunWithCancel<T>(Func<CancellationToken,T> function, CancellationToken token)
{
return Task.Run(() => function(token),token);
}
}
1) Remove all nuget packages with any relationship to the package having a problem
2) Ensure that no project still has a DLL reference to assemblies from those nuget packages
3) Remove all binding redirects related to these nuget packages
4) Add nuget packages, one at a time, in order of dependencies. (i.e. Don't let any nuget package automatically pull in another)
5) Add binding redirects for anything that still has a problem
6) Enjoy the build successful
public class RunscopePassagewayHandler : DelegatingHandler {
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
if (request.RequestUri.Host.Contains("passageway.io")) {
var uriWithoutPort = request.RequestUri.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Port, UriFormat.UriEscaped);
request.RequestUri = new Uri(uriWithoutPort);
}
return base.SendAsync(request, cancellationToken);
}
}
class Program
{
static void Main(string[] args)
{
ServicePointManager.DefaultConnectionLimit = 2;
var tasks = new Task[10];
for (int i = 0; i < 10; i++)
{
tasks[i] = Run();
@darrelmiller
darrelmiller / gist:8548166
Created January 21, 2014 20:54
How to tell Web API 2.1 to allow errors to propagate up the MessageHandler pipeline so all exceptions can be converted to HttpResponseMessages in one place.
class Program
{
static void Main(string[] args)
{
var server = WebApp.Start("http://localhost:1002/", (app) =>
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Services.Replace(typeof(IExceptionHandler), new RethrowExceptionHandler());
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Salesforce.Common.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Salesforce.Common
GET http://finance.services.appex.bing.com/Market.svc/AppTileV2?symbols=127.10.0000&contentType=0&tileType=0&locale=en-ca&symbolTypes= HTTP/1.1
User-Agent: Microsoft-WNS/6.3
Host: finance.services.appex.bing.com
Pragma: no-cache
=>
HTTP/1.1 200 OK
Content-Length: 1126
Content-Type: application/xml; charset=utf-8
Last-Modified: Fri, 10 Jan 2014 21:51:25 GMT
Server Software: Microsoft-HTTPAPI/2.0
Server Hostname: OAK
Server Port: 1001
Document Path: /CacheableResource
Document Length: 22 bytes
Concurrency Level: 1000
Time taken for tests: 4.499 seconds
Complete requests: 60000