This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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()"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CookieContainer cookieJar = new CookieContainer(); | |
HttpClientHandler handler = new HttpClientHandler | |
{ | |
CookieContainer = cookieJar, | |
AllowAutoRedirect = true | |
}; | |
handler.UseCookies = true; | |
handler.UseDefaultCredentials = false; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UnitTests { | |
[Fact] | |
public void RoundTripUserAgent() { | |
var request = new HttpRequestMessage(); | |
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("foo", "1.2")); | |
var userAgent = request.Headers.UserAgent.ToString(); | |
var strongUserAgent = ProductInfoHeaderValue.Parse(userAgent); | |
Assert.Equal("foo", strongUserAgent.Product.Name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Web API using WCF to Self-host | |
//Time to create init Server and Start HttpListener: 0 | |
//Time for roundtrip: 302 body = {"Foo":"Bar"} | |
//Time for 2nd roundtrip (new WebRequest): 0 Body = {"Foo":"Bar"} | |
//Servicestack | |
//Time to create init AppHost and Start HttpListener: 129 | |
//Time for roundtrip: 176 body = {"Foo":"Bar"} | |
//Time for 2nd roundtrip (new WebRequest): 0 Body = {"Foo":"Bar"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
using System.Web.Http.SelfHost; | |
namespace WebApiSelfHost | |
{ | |
class Program | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HttpResponseMessage<T> : HttpResponseMessage | |
{ | |
public HttpResponseMessage(HttpRequestMessage request, T value) | |
{ | |
var config = request.GetConfiguration(); | |
var contentNegotiator = config.Services.GetContentNegotiator(); | |
var connegResult = contentNegotiator.Negotiate( | |
typeof(T), request, config.Formatters | |
); | |
request.CreateResponse(HttpStatusCode.Accepted, value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, | |
CancellationToken cancellationToken) | |
{ | |
var tcs = new TaskCompletionSource<HttpResponseMessage>(); | |
Interlocked.Increment(ref count); | |
var response = new HttpResponseMessage(HttpStatusCode.OK) | |
{ | |
Content = new StringContent("HELLO WORLD") | |
}; |