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 / CucumberToBddfy.linq
Last active August 29, 2015 14:27
Cucumber feature file to BDDFy fluent Api
<Query Kind="Program">
<Namespace>System.Globalization</Namespace>
</Query>
void Main()
{
Func<string,string> ToTitleCase= new CultureInfo("en-US",false).TextInfo.ToTitleCase;
var stepMethods = new List<string>();
var classSb = new StringBuilder();
classSb.AppendLine("using System;");
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using Autofac;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Connection;
using NHibernate.Dialect;
@RhysC
RhysC / EfWithXmlConsoleApplication.cs
Created June 30, 2015 02:49
EF with XML properties
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Data.Entity;
namespace EfWithXmlConsoleApplication
{
class Program
@RhysC
RhysC / IdempotencyUnitOfWorkManager.cs
Created June 22, 2015 07:56
Idempotency in NSeviceBus using Azure Table Storage and IManageUnitOfwork (brain dump)
using System;
using System.Collections.Generic;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using NServiceBus;
using NServiceBus.UnitOfWork;
namespace MyCommon.UnitOfWorkManagers
{
public interface IBaseMessage
@RhysC
RhysC / Windows service Logging User sessions
Last active August 29, 2015 14:23
Windows service logging user session starts (note this is a project type of windows service, not all files show)
This Page Intentionally Left Blank
@RhysC
RhysC / GetApplicationsAndServicesOnLocalMachine.linq
Created June 8, 2015 03:09
Get all installed applications and service on local machine (linqpad script)
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.ServiceProcess.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Configuration.Install.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Windows.Forms.dll</Reference>
<Namespace>System.ServiceProcess</Namespace>
<Namespace>Microsoft.Win32</Namespace>
</Query>
void Main()
{
@RhysC
RhysC / EntyFrameworkAudit.cs
Created June 3, 2015 00:51
Sample Entity Framework (EF) auditable records
public class YourApplicationDbContextBase : DbContext
{
//...
public override int SaveChanges()
{
var changeSet = ChangeTracker.Entries<IAuditable>();
if (changeSet != null)
SetAuditDetails(changeSet);
@RhysC
RhysC / JsR#Templates
Last active August 29, 2015 14:19
Javascript Resharper Templates
//iife - Immediately Invoked Function Expression (JS)
(function(){
$END$
})();;
@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 / 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);