Skip to content

Instantly share code, notes, and snippets.

@jchannon
jchannon / gist:1226807
Created September 19, 2011 15:50
Dynamic JSON
{
"Code": "6150",
"xs:schema": {
"@": {
"id": "NewDataSet",
"targetNamespace": "SECURITY_GROUPS",
"xmlns:mstns": "SECURITY_GROUPS",
"xmlns": "SECURITY_GROUPS",
"xmlns:xs": "http://www.w3.org/2001/XMLSchema",
"xmlns:msdata": "urn:schemas-microsoft-com:xml-msdata",
public class MyClass
{
public IDb MyDB {get;set;}
public MyClass(ISys A) {}
public DoSomething()
{
if (MyDB != null)
..
else
@jchannon
jchannon / gist:1931579
Created February 28, 2012 09:38
Thread Safety
for (int i = 0; i < 100; i++)
{
ManualResetEvent allGo = new ManualResetEvent(false);
var model = new MyClass();
object starter = new object();
int waiting = 20;
int failures = 0;
Exception firstException = null;
Thread[] threads = new Thread[20];
for (int j = 0; j < 10; j++)
LoggingRule rule2 = new LoggingRule("*", fileTarget);
rule2.EnableLoggingForLevel(LogLevel.Info);
LoggingRule rule3 = new LoggingRule("*", debugfileTarget);
rule3.EnableLoggingForLevel(LogLevel.Debug);
rule3.EnableLoggingForLevel(LogLevel.Error);
rule3.EnableLoggingForLevel(LogLevel.Fatal);
rule3.EnableLoggingForLevel(LogLevel.Trace);
rule3.EnableLoggingForLevel(LogLevel.Warn);
@jchannon
jchannon / gist:2158920
Created March 22, 2012 15:13
TDD Driving me nuts
public class MainEntryPointClass : BaseClass
{
private ILogic Logic;
public MainEntryPointClass(ILogic Logic)
{
this.Logic = Logic;
}
public MainEntryPointClass () : this(new Logic(new Timer(), new FileLogger()))
{
public class MainEntryPointClass : BaseClass
{
private ILogic Logic;
public MainEntryPointClass(ILogic Logic)
{
this.Logic = Logic;
}
public MainEntryPointClass () : this(new Logic())
{
public class MainEntryPointClass : BaseClass
{
private ILogic Logic;
private IFileLogger FileLogger;
public MainEntryPointClass () : this(new Logic())
{
}
public IFileLogger FileLogger { get; set; } // For property injection for TDD or (e.g.) AutoFac
@jchannon
jchannon / gist:2171067
Created March 23, 2012 14:21 — forked from ianbattersby/gist:2159466
Factory Pattern FTW!
public class MainEntryPointClass : BaseClass
{
private ILogicFactory LogicFactory;
public MainEntryPointClass(ILogicFactory LogicFactory)
{
LogicFactory = LogicFactory;
}
public MainEntryPointClass() : this(new LogicFactory())
public class Logger : ILogger
{
public void WriteData(string Data)
{
var task = Task.Factory.Startnew(() => WriteDataAsync(Data));
}
private void WriteDataAsync(string Data)
{
//Write to file
public void DoSomething(string Data)
{
int localVar = int.Parse(Data.ToString)); //BOOM! Exception
}
//I need to make sure I handle this otherwise users aren't going to be happy
public void DoSomething(string Data)
{
try