Skip to content

Commit

Permalink
lots o stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Wigfield committed Sep 7, 2011
1 parent a6dbdc2 commit 5725b10
Show file tree
Hide file tree
Showing 54 changed files with 8,878 additions and 394 deletions.
Binary file added lib/MongoDB.Driver.dll
Binary file not shown.
Binary file modified lib/SimpleCqrs.EventStore.MongoDb.dll
Binary file not shown.
Binary file modified lib/SimpleCqrs.Unity.dll
Binary file not shown.
Binary file added lib/SimpleCqrs.Utilites.dll
Binary file not shown.
Binary file modified lib/SimpleCqrs.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions src/gleanBoard/Domain/AggregateRoots/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public void CreateLane(Guid id, string name, int position)
Apply(new LaneCreatedEvent {AggregateRootId = Id, Lane = id, Name = name, Postion = position});
}

public void CreateCard(Guid id, Guid lane, string title, int position)
public void CreateCard(Guid id, Guid lane, string title, int position, string description)
{
Apply(new CardCreatedEvent {AggregateRootId = Id, Card = id, Lane = lane, Title = title, Postion = position});
Apply(new CardCreatedEvent {AggregateRootId = Id, Card = id, Lane = lane, Title = title, Postion = position, Description = description});
}

public void MoveCard(Guid card, Guid fromLane, Guid toLane, int position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CreateCardCommandHandler(IDomainRepository repository)
public override void Handle(CreateCardCommand command)
{
var board = _repository.GetById<Board>(command.Board);
board.CreateCard(command.Id, command.Lane, command.Title, command.Position);
board.CreateCard(command.Id, command.Lane, command.Title, command.Position, command.Description);
_repository.Save(board);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void Handle(SignUpCommand command)
board.CreateLane(backlogId,"Backlog",0);
board.CreateLane(Guid.NewGuid(),"Doing", 1);
board.CreateLane(Guid.NewGuid(),"Done", 2);
board.CreateCard(Guid.NewGuid(), backlogId, "Test Card", 0);
board.CreateCard(Guid.NewGuid(), backlogId, "Test Card", 0, "Welcome");
_repository.Save(account);
_repository.Save(board);
}
Expand Down
1 change: 1 addition & 0 deletions src/gleanBoard/Domain/Commands/CreateCardCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class CreateCardCommand : ICommand
public Guid Lane { get; set; }
public string Title { get; set; }
public int Position { get; set; }
public string Description { get; set; }
}
}
1 change: 1 addition & 0 deletions src/gleanBoard/Domain/Events/AccountCreatedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class AccountCreatedEvent : DomainEvent
public string UserName { get; set; }
public string Password { get; set; }
}

}
23 changes: 23 additions & 0 deletions src/gleanBoard/Domain/Events/CardCreatedConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using gleanBoard.Domain.Events.Converters;
using SimpleCqrs.Eventing;

namespace gleanBoard.Domain.Events
{
public class CardCreatedConverter : IEventConverter<CardCreatedEvent_v1, CardCreatedEvent>
{
public CardCreatedEvent Convert(CardCreatedEvent_v1 sourceEvent)
{
return new CardCreatedEvent
{
AggregateRootId = sourceEvent.AggregateRootId,
EventDate = sourceEvent.EventDate,
Sequence = sourceEvent.Sequence,
Card = sourceEvent.Card,
Description = "No Description",
Lane = sourceEvent.Lane,
Postion = sourceEvent.Postion,
Title = sourceEvent.Title
};
}
}
}
4 changes: 4 additions & 0 deletions src/gleanBoard/Domain/Events/CardCreatedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class CardCreatedEvent : DomainEvent
public Guid Lane { get; set; }
public string Title { get; set; }
public int Postion { get; set; }
public string Description { get; set; }

public override int GetHashCode() { return -2051383496; }

}

}
16 changes: 16 additions & 0 deletions src/gleanBoard/Domain/Events/Converters/CardCreatedEvent_v1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using SimpleCqrs.Eventing;

namespace gleanBoard.Domain.Events.Converters
{
public class CardCreatedEvent_v1 : DomainEvent
{
public Guid Card { get; set; }
public Guid Lane { get; set; }
public string Title { get; set; }
public int Postion { get; set; }

public override int GetHashCode() { return 1726483226;}

}
}
51 changes: 28 additions & 23 deletions src/gleanBoard/Domain/Views/BoardView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,47 @@ public BoardView(ViewRepository repo)
_repo = repo;
}

public void Handle(BoardCreatedEvent domainEvent)
{
var board = new Resources.Board
{
Id = domainEvent.AggregateRootId,
Name = domainEvent.Name
};
_repo.Save(board);
}

public void Handle(CardCreatedEvent domainEvent)
{
var board = _repo.Get<Resources.Board>();
var lane = board.Lanes.First(x => x.Id == domainEvent.Lane);
if (lane.Cards == null)
lane.Cards = new List<Resources.Card>();

lane.Cards.Add(new Resources.Card
{
Id = domainEvent.Card,
Title = domainEvent.Title
});
if (domainEvent.Postion > lane.Cards.Count)
domainEvent.Postion = lane.Cards.Count();

lane.Cards.Insert(domainEvent.Postion,
new Resources.Card
{
Id = domainEvent.Card,
Title = domainEvent.Title,
Description = domainEvent.Description
});
_repo.Save(board);
}

public void Handle(BoardCreatedEvent domainEvent)
public void Handle(LaneCreatedEvent domainEvent)
{
var board = _repo.Get<Resources.Board>();
if (board == null)
board = new Resources.Board();
if (board.Lanes == null)
board.Lanes = new List<Resources.Lane>();

board.Id = domainEvent.AggregateRootId;
board.Name = domainEvent.Name;
board.Lanes.Insert(domainEvent.Postion, new Resources.Lane
{
Id = domainEvent.Lane,
Name = domainEvent.Name
});
_repo.Save(board);
}

Expand All @@ -62,18 +80,5 @@ public void Handle(CardMovedEvent domainEvent)
_repo.Save(board);
}

public void Handle(LaneCreatedEvent domainEvent)
{
var board = _repo.Get<Resources.Board>();
if (board.Lanes == null)
board.Lanes = new List<Resources.Lane>();

board.Lanes.Insert(domainEvent.Postion, new Resources.Lane
{
Id = domainEvent.Lane,
Name = domainEvent.Name
});
_repo.Save(board);
}
}
}
8 changes: 5 additions & 3 deletions src/gleanBoard/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SimpleCqrs.Eventing;
using gleanBoard.Domain.Events;
using gleanBoard.Resources;
using SimpleCqrs;
using SimpleCqrs.Commanding;
using SimpleCqrs.Unity;
Expand All @@ -18,6 +16,10 @@ protected override IEventStore GetEventStore(IServiceLocator serviceLocator)
return new SimpleCqrs.EventStore.MongoDb.MongoEventStore("mongodb://localhost", serviceLocator.Resolve<ITypeCatalog>());
}

protected override System.Collections.Generic.IEnumerable<System.Reflection.Assembly> GetAssembliesToScan(IServiceLocator serviceLocator)
{
return AppDomain.CurrentDomain.GetAssemblies().Where(_ => _.GlobalAssemblyCache == false);
}
}

public static class Runtime
Expand Down
3 changes: 2 additions & 1 deletion src/gleanBoard/Handlers/CardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ public class NewCardData
public string Lane { get; set; }
public string Title { get; set; }
public int Position { get; set; }
public string Description { get; set; }
}

public class CardHandler
{
public NewCard Post(NewCardData data)
{
var id = Guid.NewGuid();
Runtime.Bus.Send(new CreateCardCommand {Id = id, Board = Guid.Parse(data.Board), Lane = Guid.Parse(data.Lane), Title = data.Title, Position = data.Position});
Runtime.Bus.Send(new CreateCardCommand {Id = id, Board = Guid.Parse(data.Board), Lane = Guid.Parse(data.Lane), Title = data.Title, Position = data.Position, Description = data.Description});

return new NewCard {Id = id.ToString(), Lane = data.Lane, Title = data.Title};
}
Expand Down
4 changes: 2 additions & 2 deletions src/gleanBoard/Handlers/MoveCardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class MoveLaneData
public int Position { get; set; }
}

public CardMoved Post(MoveLaneData data)
public bool Post(MoveLaneData data)
{
Runtime.Bus.Send(new MoveCardCommand { Board = Guid.Parse(data.Board), Card = Guid.Parse(data.Card), From = Guid.Parse(data.From), To = Guid.Parse(data.To), Position = data.Position });
return new CardMoved {Result = true};
return true;
}

}
Expand Down
18 changes: 11 additions & 7 deletions src/gleanBoard/Handlers/RebuildViewsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System;
using System.Collections.Generic;
using gleanBoard.Domain.Events;
using SimpleCqrs.Eventing;

namespace gleanBoard.Handlers
{
public class RebuildData
{
public DateTime? AsOf { get; set; }
}

public class RebuildViewsHandler
{
public RebuildViews Get()
public bool Get(RebuildData data)
{
var events = Runtime.Locator.Resolve<IEventStore>().GetEventsByEventTypes(new List<Type> { typeof(BoardCreatedEvent), typeof(CardCreatedEvent), typeof(LaneCreatedEvent), typeof(CardMovedEvent) }, DateTime.Now.AddYears(-1), DateTime.Now);
Runtime.Locator.Resolve<IEventBus>().PublishEvents(events);
return new RebuildViews {Result = true};
Runtime.Locator.Resolve<SimpleCqrs.Utilites.DomainEventReplayer>().ReplayEventsForHandlerType(
typeof(Domain.Views.BoardView),
DateTime.Now.AddYears(-1),
data.AsOf.GetValueOrDefault(DateTime.Now));
return true;
}
}
}
11 changes: 3 additions & 8 deletions src/gleanBoard/Handlers/SignUpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ public class SignUpData
public class SignUpHandler
{

public Signup Get()
{
return new Signup {Result = true};
}

public Signup Post(SignUpData data)
public bool Post(SignUpData data)
{
if (data.Password != data.PasswordConfirm)
return new Signup { Result = false };
return false;

Runtime.Bus.Send(new SignUpCommand {Username = data.UserName, Password = data.Password});
return new Signup { Result = true };
return false;
}
}
}
65 changes: 65 additions & 0 deletions src/gleanBoard/MyModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Web.Compilation;
using gleanBoard.Handlers;
using Nancy;
using Nancy.ModelBinding;

namespace gleanBoard
{

public class MyModule : NancyModule
{

public MyModule()
{

Get["/"] = _ =>
{
var replay = Runtime.Locator.Resolve<SimpleCqrs.Utilites.DomainEventReplayer>();
var ll =
replay.ExpandEventTypesWithAncestors(
replay.GetDomainEventTypesHandledByHandler(typeof(Domain.Views.BoardView)));

return View["Views/Home.cshtml"];
};

Get["/board"] = _ =>
{
return View["Views/Board.cshtml", new BoardHandler().Get()];
};

Get["/tools/rebuildviews/{AsOf}"] = _ =>
{
var asOf = DateTime.Now;
DateTime.TryParse(_.AsOf, out asOf);
return View[new RebuildViewsHandler().Get(new RebuildData{ AsOf = asOf })];
};

Get["/signup"] = _ =>
{
return View["Views/SignUp.cshtml"];
};

Post["/signup"] = _ =>
{
return View[new SignUpHandler().Post(this.Bind<SignUpData>())];
};

Post["/card/create"] = _ =>
{
return View[new CardHandler().Post(this.Bind<NewCardData>())];
};

Post["/card/move"] = _ =>
{
return View[new MoveCardHandler().Post(this.Bind<MoveCardHandler.MoveLaneData>())];
};

Post["/lane/create"] = _ =>
{
return View[new LaneHandler().Post(this.Bind<NewLaneData>())];
};
}

}
}
1 change: 1 addition & 0 deletions src/gleanBoard/Resources/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Card
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}

}
8 changes: 2 additions & 6 deletions src/gleanBoard/Resources/NewCard.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace gleanBoard.Resources
namespace gleanBoard.Resources
{
public class NewCard
{
public string Id { get; set; }
public string Title { get; set; }
public string Lane { get; set; }
public string Description { get; set; }
}
}
Loading

0 comments on commit 5725b10

Please sign in to comment.