Skip to content

Instantly share code, notes, and snippets.

View RhysC's full-sized avatar

Rhys Campbell RhysC

  • Perth; Australia
View GitHub Profile
@RhysC
RhysC / OwinSample.cs
Created September 12, 2014 06:02
OWIN sample midlewares in a console app
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using OwinSpike.Simple.Console;
//Console app
//NuGet packages :
//<package id="Microsoft.Owin.SelfHost" version="3.0.0" targetFramework="net45" />
@RhysC
RhysC / ClientStartUp.cs
Created September 24, 2014 10:09
Claims not coming back from identity server
using System.Collections.Generic;
using System.IdentityModel.Tokens;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using OauthScratch.MvcOwinClient;
using Owin;
@RhysC
RhysC / Log4NetAppenderFactory.cs
Created October 14, 2014 07:50
RestTest - sample console app for receiving HTTP Posts and logging said posts. Posting to http://localhost.fiddler:9000/api/test will allow you to see the request in fiddler
using System.IO;
using log4net.Appender;
using log4net.Core;
using log4net.Layout;
namespace RestTest.Logging
{
public static class Log4NetAppenderFactory
{
private static readonly PatternLayout PatternLayout = new PatternLayout("[%-5level][%date][%thread][%logger]: %message%newline");
@RhysC
RhysC / LinqpadAsAWebserver.linq
Created October 17, 2014 04:17
Linqpad continues to be the coolest thing ever - WEBAPI in Linqpad with out all the drama. Logs all posts
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.Net.Http.dll</Reference>
<NuGetReference>Microsoft.AspNet.WebApi.OwinSelfHost</NuGetReference>
<Namespace>Microsoft.Owin.Hosting</Namespace>
<Namespace>Owin</Namespace>
<Namespace>System.Web.Http</Namespace>
<Namespace>System.Net.Http</Namespace>
<Namespace>System.Net</Namespace>
</Query>
@RhysC
RhysC / RedisRx.linq
Created October 21, 2014 12:02
LinqPad sample of Redis Pub sub using StackExchange.Redis and RX
<Query Kind="Program">
<NuGetReference>Newtonsoft.Json</NuGetReference>
<NuGetReference>Rx-Main</NuGetReference>
<NuGetReference>StackExchange.Redis</NuGetReference>
<Namespace>System.Reactive.Linq</Namespace>
<Namespace>System.Reactive.Disposables</Namespace>
<Namespace>StackExchange.Redis</Namespace>
</Query>
void Main()
@RhysC
RhysC / CSharpObjectDefinition.cs
Created October 31, 2014 02:55
Code generator from JSON Schema - swap out the impl of ObjectDef to write, view model, dtos etc
using System;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
namespace JsonSchemaToCode
{
public class CSharpObjectDefinition : ObjectDefinition
{
public override string ToString()
@RhysC
RhysC / ObjectNotFoundExceptionFilterAttribute.cs
Created November 11, 2014 07:15
Error Handling 404 in Asp.Net MVC 5
using System.Web.Mvc;
namespace YourWebsite.Filters
{
public class ObjectNotFoundExceptionFilterAttribute : ActionFilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
if (filterContext.Exception is NHibernate.ObjectNotFoundException)
{
@RhysC
RhysC / InlineFileAttribute.cs
Created December 8, 2014 05:33
Show file as web page, not an automatic download | MVC Asp.net filter
public class InlineFileAttribute : ActionFilterAttribute
{
private const string ContentDisposition = "Content-Disposition";
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
var headers = filterContext.HttpContext.Response.Headers;
if (!string.IsNullOrWhiteSpace(headers[ContentDisposition]))
headers[ContentDisposition] = headers[ContentDisposition].Replace("attachment", "inline");
base.OnResultExecuted(filterContext);
@RhysC
RhysC / ErrorHandlingInAspnet.spec
Created December 16, 2014 09:24
My hopes and dreams for error handling in Asp.net - defined in cukes
Feature: Error handling in asp.net
Errors occur in web apps and we need to be able to handle the exceptions (e.g. log them) and show customers appropriate messages in a meaning full and consistent manner.
These test assume Accept:text/html or equivalent
#RHYSC -I don't mind how the error information is surfaced but it should be accessible in a common and clean manner
#these specs can be extrapolated out to the other error codes too
Scenario: 404 on static files
Given a static file ~/test.html does not exist
When we navigating to ~/test.html
Then the on error event should be raised by XYZ with path information and 404 http status code
@RhysC
RhysC / JsR#Templates
Last active August 29, 2015 14:19
Javascript Resharper Templates
//iife - Immediately Invoked Function Expression (JS)
(function(){
$END$
})();;