Skip to content

Instantly share code, notes, and snippets.

@seburgi
seburgi / gist:7153920
Last active December 26, 2015 12:49
example for async controller action with NServiceBus
[HttpPost]
public async Task<ActionResult> Edit(ApplicationDto model)
{
if (ModelState.IsValid)
{
AppErrorCodes errorCode = await
Bus.Send(new UpdateApplication
{
Id = model.Id,
Name = model.Name,
@seburgi
seburgi / gist:7151225
Last active December 26, 2015 12:29
Default config for all endpoints
public class DefaultEndpointConfig : IWantToRunBeforeConfiguration
{
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public void Init()
{
SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
Configure.With().Log4Net()
.DefiningCommandsAs(type => !type.IsAbstract && !type.IsInterface && typeof(Base.Messages.ICommand).IsAssignableFrom(type))
.DefiningEventsAs(type => !type.IsAbstract && !type.IsInterface && typeof(Base.Messages.IEvent).IsAssignableFrom(type))
@seburgi
seburgi / gist:5366479
Created April 11, 2013 19:31
Generates a hashcode for simple objects that depends on its contents.
public class HashCodeGenerator<T>
{
private readonly List<Func<T, object>> _getters = new List<Func<T, object>>();
public HashCodeGenerator()
{
PropertyInfo[] properties = typeof(T).GetProperties();
foreach (var p in properties)
{
@seburgi
seburgi / gist:3795015
Created September 27, 2012 16:39
Find missing rectangles
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace FillEmptySpaceWithRectangles
{
internal class Program
{
private static void Main(string[] args)
@seburgi
seburgi / gist:1607610
Created January 13, 2012 17:21
A wrapper for IAtomicWriter (see Lokad.CQRS.Sample) that calls a provided action after successful updates/deletes
internal class PublishingAtomicWriter<TKey, TEntity> : IAtomicWriter<TKey, TEntity> where TEntity : class
{
private readonly IClientNotificationService _clients;
private readonly IAtomicWriter<TKey, TEntity> _writer;
private readonly Action<TKey, TEntity> _publishAction;
public PublishingAtomicWriter(IAtomicWriter<TKey, TEntity> writer, Action<TKey, TEntity> publishAction)
{
if (publishAction == null) throw new ArgumentNullException("publishAction");
@seburgi
seburgi / gist:1605014
Created January 13, 2012 07:39
Lokad.CQRS.Sample + ZeroMQ = client update notifications (https://groups.google.com/d/topic/lokad/kD53JYzkV0o/discussion)
// see Google Groups topic at https://groups.google.com/d/topic/lokad/kD53JYzkV0o/discussion
// example event handler in a projection
// _clients is an instance of IClientNotificationService
public void When(Source<NewAppointmentRegistered> source)
{
NewAppointmentRegistered e = source.Event;
DateTime dateTime = e.DateTime.Date;
_writer.UpdateEnforcingNew(dateTime, dayDto => AddNewAppointmentToDayDto(dayDto, e.Id, ...));