Skip to content

Instantly share code, notes, and snippets.

View darrelmiller's full-sized avatar

Darrel darrelmiller

View GitHub Profile
public class RequestPreprocessor : DelegatingHandler {
public RequestPreprocessor(HttpMessageHandler handler) {
this.InnerHandler = handler;
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
request.Content.LoadIntoBufferAsync().RunSynchronously();
// Do your stuff!
[[ch_the_application]]
== The Application ==
Up to this point we have discussed the tools that you can use to build Web APIs. We have discussed the fundamentals of the HTTP protocol, the basics of using _ASP.NET Web API_ and how the architectural pieces fit together. This is essential knowledge, but not the primary objective of this book. This book is about how to build _evolvable_ Web APIs. This chapter is the where we begin to talk about how to create a Web API that can evolve over period of years. A long enough period of time that business concerns will change and technology will change.
Rather than discuss the issues in abstract scenarios, we decided that we must walk the walk and build an API that demonstrates the concepts we wish to convey. This API will concern a domain that should be familar to every developer and we believe is sufficiently realistic that it could be adpoted in real world scenarios.
Before delving into the details of the domain, we will ensure that evolvability is something we
CookieContainer cookieJar = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler
{
CookieContainer = cookieJar,
AllowAutoRedirect = true
};
handler.UseCookies = true;
handler.UseDefaultCredentials = false;
@darrelmiller
darrelmiller / gist:4711532
Last active December 12, 2015 04:08
Convert attributes to elements throughout a document
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*">
<xsl:element name="{name()}"><xsl:value-of select="."/></xsl:element>
</xsl:template>
<xsl:template match="/ | @* |node()">
<xsl:copy>
<xsl:apply-templates select="* | @* | node()"/>
CREATE FUNCTION GetProgressionReviewHours(@AsOfDate DateTime)
RETURNS @Hours TABLE (Employee_Id int,
EmployeeContract_Id int,
ProgressionReviewPeriod int,
WorkedHours numeric(18,2),
TotalHours numeric(18,2))
BEGIN
INSERT INTO @Hours
Here's a report that show the weight of material currently being worked on...
SELECT CASE WHEN @@LANGID = 0 THEN cat.Description ELSE cat.Description_2 END AS ChargeAccountType,
ca.Code AS ChargeAccount_Code,
ca.Description AS ChargeAccount_Description,
ROUND(pw.TotalWeight / 2000.0,2) AS TotalWeight,
ROUND(pw.BoltWeight /2000.0,2) AS BoltWeight,
ROUND(pw.ReleasedWeight / 2000.0,2) AS ReleasedWeight,
ROUND(pw.FabricatedWeight / 2000.0,2) AS FabricatedWeight,
public class BingMapLink : Link
{
public BingMapLink()
{
Target = new Uri("http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{lat},{long}/{level}?mapSize={mapsize}&key={apikey}");
SetParameter("level", 10);
SetParameter("mapsize", "500, 500");
}
using System;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Routing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestRoutes
{
[TestClass]
public class RouteTests {
<Hpr>
<pages>
<page>
<type>DefFeatures</type>
<href>6.2/615/WW/en-us/0/76/features.json</href>
</page>
<page>
<type>MSFeatures</type>
<href>6.2.1.0/100/CA/en-us/MS/232/features9bc05c7c-e8b6-4341-a379-bc3d042e6458.json</href>
</page>
config.Routes.Add("default", new TreeRoute("",new TreeRoute("home").To<HomeController>(),
new TreeRoute("contact",
new TreeRoute("{id}",
new TreeRoute("address",
new TreeRoute("{addressid}").To<ContactAddressController>())
).To<ContactController>())
)
);