Skip to content

Instantly share code, notes, and snippets.

https://gist.github.com/pcibraro/b31f46b5ba2df74a6f868251230df977
<http:request-config name="HTTP_Azure_Bridge" host="#[flowVars.settings[0].azure_bridge_host]" port="#[flowVars.settings[0].azure_bridge_port]" doc:name="HTTP Request Configuration" basePath="/SUBSCRIPTIONID" connectionIdleTimeout="60000" responseTimeout="60000">
<oauth2:client-credentials-grant-type clientId="${clientid}" clientSecret="${secret}">
<oauth2:token-request tokenUrl="${token_url}"/>
<tls:context>
<tls:trust-store insecure="true"/>
</tls:context>
</oauth2:client-credentials-grant-type>
<http:raml-api-configuration location="AzureManagementApi.raml"/>
</http:request-config>
class Program
{
static void Main(string[] args)
{
using (Isolated<Work> isolated = new Isolated<Work>())
{
isolated.Value.CallEdge();
}
}
}
@pcibraro
pcibraro / HawkHandler
Created July 24, 2013 17:45
Katana Authentication Handler for Hawk
public class HawkAuthenticationHandler : AuthenticationHandler<HawkAuthenticationOptions>
{
private readonly ILogger logger;
public HawkAuthenticationHandler(ILogger logger)
{
this.logger = logger;
}
protected override Task<AuthenticationTicket> AuthenticateCore()
@pcibraro
pcibraro / gist:5293844
Created April 2, 2013 16:47
A logging handler for the HttpClient in ASP.NET Web API. It logs the body content to a file. That code can be replaced for some other stream.
public class LogginHandler : DelegatingHandler
{
public LogginHandler(HttpMessageHandler inner)
: base(inner)
{
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
using (var fs = new FileStream("c:\\temp\\log.txt", FileMode.Create, FileAccess.Write))
@pcibraro
pcibraro / gist:5285734
Created April 1, 2013 15:52
AttributeRouting in ASP.NET Web API for Hypermedia Web APIs. Links user user/picture (It's a child resource)
RoutePrefix("user")]
public class UserController : ApiController
{
public UserController()
{
}
[GET("", RouteName="GetUser")]
public UserProfile Get()
@pcibraro
pcibraro / gist:4074119
Created November 14, 2012 19:16
Await in Foreach
public async Task<IEnumerable<SearchResult>> Get()
{
var providers = this.locator.GetAllProviders(resource);
var allResults = new List<SearchResult>();
foreach (var provider in providers)
{
var results = await provider.Search("foo");
@pcibraro
pcibraro / gist:1853986
Created February 17, 2012 15:17
DisposableEnumerable
public class DisposableEnumerable<T> : IEnumerable<T>
{
IEnumerable<T> source;
public DisposableEnumerable(IEnumerable<T> source)
{
this.source = source;
}
public IEnumerator<T> GetEnumerator()