Skip to content

Instantly share code, notes, and snippets.

View howarddierking's full-sized avatar

Howard Dierking howarddierking

View GitHub Profile
@howarddierking
howarddierking / EtagMessageHandler.cs
Created July 1, 2011 23:52
sample message handler for managing etags in web api
public class EtagMessageHandler : DelegatingChannel
{
readonly IETagStore _eTagStore;
public EtagMessageHandler(HttpMessageChannel innerChannel) : base(innerChannel) {
Trace.WriteLine("EtagMessageHandler - Ctor");
_eTagStore = new InMemoryETagStore();
}
Get-ChildItem $wcfsource -Exclude "*.StyleCop" -Recurse | %{Copy-Item $_.FullName -Destination ($hgroot + $_.FullName.Substring($wcfsource.Length)) -Force}
@howarddierking
howarddierking / gist:1209919
Created September 11, 2011 18:16
powershell script for transforming a codebase
Import-Module Pscx
# the variables you'll likely need to change on your local machine
$afroot = "D:\AppFabric"
$hgroot = 'D:\Programming Projects'
# $hgremote = "https://hg01.codeplex.com/wcf"
$hgremote = "D:\Programming Projects\wcf-codeplex-baseline_RC2"
# derived paths
$afwcfsource = $afroot + "\private\source\WCF"
@howarddierking
howarddierking / gist:1209930
Created September 11, 2011 18:22
Project file transformation
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl b"
xmlns:b="http://schemas.microsoft.com/developer/msbuild/2003">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="/b:Project">
<xsl:copy>
@howarddierking
howarddierking / customMTF_skeleton.cs
Created September 14, 2011 18:56
custom media type formatter - skeleton
class MyCustomMediaTypeFormatter : MediaTypeFormatter
{
public MyCustomMediaTypeFormatter() {
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/vnd.howard.fancyformat"));
}
protected override object OnReadFromStream(Type type, Stream stream, HttpContentHeaders contentHeaders) {
//stuff
}
@howarddierking
howarddierking / OAuthFacebookOperationHandler.cs
Created October 12, 2011 00:41
Web API Operation Handler for initiating a server-driven OAuth2 workflow with Facebook
public class OAuthFacebookOpHandler : HttpOperationHandler<HttpRequestMessage, HttpRequestMessage> {
readonly Uri _facebookBaseAuthUri = new Uri("https://www.facebook.com/dialog/oauth");
readonly AuthorizeAttribute _authorizationAttribute;
readonly string _facebookAppId;
public OAuthFacebookOpHandler() : base("response") { }
public OAuthFacebookOpHandler(AuthorizeAttribute authorizeAttribute, string appId) : this() {
_authorizationAttribute = authorizeAttribute;
_facebookAppId = appId;
@howarddierking
howarddierking / get-oauth.js
Created October 12, 2011 03:20
jQuery to handle an OAuth challenge response
function GetCommentsWithOAuth(){
viewModel.comments([]);
$.ajax({ url: "/services/comments/oauth",
accepts: "application/json",
cache: false,
statusCode: {
200: function(data){
viewModel.comments(data);
},
@howarddierking
howarddierking / OAuthFacebookMessageHandler.cs
Created October 12, 2011 03:35
Web API Message Handler for processing Facebook OAuth2 auth code responses
public class OAuthFacebookMessageHandler : DelegatingHandler
{
static readonly Uri FacebookBaseGraphUri = new Uri("https://graph.facebook.com/me");
static readonly Uri FacebookAccessTokenBaseUri = new Uri("https://graph.facebook.com/oauth/access_token");
readonly string _facebookAppId;
readonly string _facebookAppSecret;
public OAuthFacebookMessageHandler(string appId, string secret) {
_facebookAppId = appId;
_facebookAppSecret = secret;
@howarddierking
howarddierking / RegistrationHelpers.cs
Created October 12, 2011 03:47
Web API helper extension methods for OAuth registration
public static void RegisterOAuth(this HttpConfiguration config, FacebookOAuthClient client) {
var existingFactory = config.RequestHandlers;
config.RequestHandlers = (c, e, od) => {
if (existingFactory != null)
existingFactory(c, e, od);
var authorizeAttribute = od.Attributes.OfType<AuthorizeAttribute>().FirstOrDefault();
if (authorizeAttribute == null) return;
if (od.Name == "GetCommentsOauth") {
@howarddierking
howarddierking / InvalidAsyncServiceContract.cs
Created November 30, 2011 19:38
Invalid WCF async service contract
[ServiceContractAttribute(Namespace = "http://microsoft.samples")]
public interface ISampleService
{
[OperationContractAttribute]
string SampleMethod(string msg);
[OperationContractAttribute(AsyncPattern = true)]
IAsyncResult BeginSampleMethod(string msg, AsyncCallback callback,
object asyncState);