Skip to content

Instantly share code, notes, and snippets.

View SimonCropp's full-sized avatar

Simon Cropp SimonCropp

View GitHub Profile
@SimonCropp
SimonCropp / sample
Created April 21, 2011 05:32
named loggers in NLog
public static class LoggingFactory
{
static LoggingFactory()
{
var name = Assembly.GetEntryAssembly().GetName().Name;
var fileTarget = new FileTarget{FileName = string.Format("${{basedir}}/{0}_${{logger}}.log", name),Layout = "${message}"};
var fileRule = new LoggingRule("*", LogLevel.Debug, fileTarget);
var config = new LoggingConfiguration();
@SimonCropp
SimonCropp / ClientConsole
Created May 19, 2011 02:34
non blocking client server with httplistener
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace ClientConsole
{
static class Program
{
@SimonCropp
SimonCropp / gist:1124188
Created August 3, 2011 23:57
NSubstitute and avoiding calling the constructor
class Program
{
static void Main(string[] args)
{
var person = Substitute.For<Person>();
person.Name = "sdsdf";
Console.WriteLine(person.Name);
}
}
@SimonCropp
SimonCropp / gist:1196839
Created September 6, 2011 07:25
ResiliencyTests
[TestFixture]
public class ResiliencyTests
{
[Test]
public void Foo()
{
using (var disabledItems = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\14.0\Outlook\Resiliency\DisabledItems"))
{
foreach (var valueName in disabledItems.GetValueNames())
{
public class Class1 :INotifyPropertyChanged
{
public bool IsExistingProject { get; set; }
public bool CanSaveProject{get { return !IsExistingProject; }}
public event PropertyChangedEventHandler PropertyChanged;
}
@SimonCropp
SimonCropp / gist:1283627
Created October 13, 2011 07:13
nancy AsUnSafeFile
public static class FormatterExtensions
{
public static Response AsUnSafeFile(this IResponseFormatter formatter, string filePath, Request request)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new Exception("filePath not defiend");
}
@SimonCropp
SimonCropp / gist:1308672
Created October 24, 2011 09:34
string concat tests
[TestFixture]
public class TestStringMethods
{
string bar = "Sdfsdf";
int reps = 1000000;
string foo = "dsfsd";
[Test]
public void Format()
@SimonCropp
SimonCropp / gist:1344356
Created November 7, 2011 06:56
multiport kayak
protected override void OnStart(string[] args)
{
var ports = new [] { 91, 8091 };
foreach (var port in ports)
{
try
{
ListenOnThread(port);
}
catch(Exception exception)
<UsingTask TaskName="NotifyPropertyWeaverMsBuildTask.WeavingTask" AssemblyFile="$(SolutionDir)Tools\NotifyPropertyWeaverMsBuildTask.dll" />
<Target AfterTargets="CopyFilesToOutputDirectory" Name="NotifyPropertyWeaver">
<NotifyPropertyWeaverMsBuildTask.WeavingTask TargetPath="$(TargetPath)"/>
<Copy SourceFiles="$(TargetPath)" DestinationFiles="@(IntermediateAssembly)"/>
</Target>
var path = @"F:\Code\CecilTest\TargetLibrary\bin\Debug\TargetLibrary.dll";
var moduleDefinition = ModuleDefinition.ReadModule(path);
var typeDefinition = moduleDefinition.Types.First(x => x.Name.EndsWith("Class1"));
var voidType = Type.GetType("System.Void");
var voidTypeReference = moduleDefinition.Import(voidType);
var methodDefinition = new MethodDefinition(".ctor", MethodAttributes.Public, voidTypeReference);
typeDefinition.Methods.Add(methodDefinition);
moduleDefinition.Write(path);