Skip to content

Instantly share code, notes, and snippets.

View darrelmiller's full-sized avatar

Darrel darrelmiller

View GitHub Profile
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);
}
}
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 static class TaskHelper
{
public static Task<T> RunWithCancel<T>(Func<CancellationToken,T> function, CancellationToken token)
{
return Task.Run(() => function(token),token);
}
}
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("{}");
@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()
};
@darrelmiller
darrelmiller / gist:10682407
Created April 14, 2014 21:00
Create Owin host from HttpListener
public static IDisposable CreateHttpListenerServer(Uri baseAddress, Func<IDictionary<string, object>, Task> appFunc)
{
var props = new Dictionary<string, object>();
var address = Address.Create();
address.Host = baseAddress.Host;
address.Port = baseAddress.Port.ToString();
address.Scheme = baseAddress.Scheme;
address.Path = baseAddress.AbsolutePath;
public class JsonStringController : ApiController
{
public HttpResponseMessage Post([FromBody]string jsonBody)
{
var myobject = Newtonsoft.Json.JsonConvert.DeserializeObject<MyObject>(jsonBody)
return new HttpResponseMessage(HttpStatusCode.Created);
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
var webApiconfig = new HttpConfiguration();
webApiconfig.Routes.MapHttpRoute("test","Test",new {controller="Test"});
app.UseWebApi(webApiconfig);
// Turn cross domain on
var config = new HubConfiguration { EnableCrossDomain = true };
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes" />
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="* | @* | node()" />
</xsl:copy>
</xsl:template>
@darrelmiller
darrelmiller / gist:d688282dfe8167fcc101
Created June 11, 2014 20:56
Embedded Resource Content
public class EmbeddedContent : HttpContent
{
private readonly Stream _Stream;
public EmbeddedContent(Type locatorType, string filename, MediaTypeHeaderValue contentType = null)
{
Headers.ContentType = contentType ?? new MediaTypeHeaderValue("application/octet-stream");