Skip to content

Instantly share code, notes, and snippets.

View JefClaes's full-sized avatar

Jef Claes JefClaes

View GitHub Profile
@JefClaes
JefClaes / gist:3052349
Created July 5, 2012 08:44
Extensions methods to create a top level menu based on areaname convention
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using System.Reflection;
namespace TopMenuBasedOnAreas.HtmlHelpers
{
@JefClaes
JefClaes / gist:3860582
Created October 9, 2012 18:34
Command an query handlers
[TestMethod()]
public void Foo_should_start_mspaint()
{
var cmdHandler = new Mock<ICommandHandler>();
var qryHandler = new Mock<IQueryHandler>();
var controller = new Controller(cmdHandler.Object, qryHandler.Object);
controller.Foo("mspaint.exe");
@JefClaes
JefClaes / gist:4156855
Created November 27, 2012 20:38
Generic FlatFileReader draft
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestReader
{
class Program
{
static void Main(string[] args)
@JefClaes
JefClaes / gist:4363612
Created December 23, 2012 14:17
Attempt to not have to separate command and command data to get some DI going. Most commands don't have dependencies which need to be injected (RavenDB in-memory store).
public class CommandHandler : ICommandHandler
{
private IKernel _kernel;
public CommandHandler() { }
public CommandHandler(IKernel kernel)
{
_kernel = kernel;
}
@JefClaes
JefClaes / gist:4366674
Created December 23, 2012 23:21
Quick-and-dirty errorhandler
public class LoggingErrorHandler : IErrorHandler
{
public void Handle(Nancy.HttpStatusCode statusCode, Nancy.NancyContext context)
{
object error;
var gotException = context.Items.TryGetValue(NancyEngine.ERROR_EXCEPTION, out error);
if (!gotException)
return;
@JefClaes
JefClaes / gist:4505798
Created January 10, 2013 21:06
Stacktrace WebMatrix crash - for @JustinBeckwith
The UI first reported an NPM error on installing twitter-bootstrap-node, but there were no details in the dialog. Ignoring that, WebMatrix crashed a bit after.
I found this in the eventlog.
PROCESS_CRASH
The process terminated unexpectedly.
Exception:System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.AggregateException: One or more errors occurred. ---> NodeNpm.NpmException: Failed: npm reported an error.
at NodeNpm.NpmApi.ListChildren()
@JefClaes
JefClaes / gist:4716622
Created February 5, 2013 18:44
Naïve ES take 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NaiveEventSourcing
{
class Program
{
static void Main(string[] args)
@JefClaes
JefClaes / gist:5039087
Last active December 14, 2015 05:59
Queries
namespace Infrastructure
{
public interface IQueryHandler<TIn, TOut>
where TIn : class
where TOut : class
{
TOut Execute(TIn query);
}
}
@JefClaes
JefClaes / gist:5301262
Created April 3, 2013 13:36
Four eyes principle applied with commands
1. When the user adds an accountnumber, a command gets sent which isn't handled yet.
2. When a supervisor logs on, he gets a list of commands to approve or decline, including the AddAccountNumber.
3. When the supervisor approves the AddAccountNumber command, it will be handled.
@JefClaes
JefClaes / gist:5375605
Created April 12, 2013 22:16
Best attempt at four eyes principal
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Ninject;
namespace ModelingFourEyes
{