public static bool HandleCommand(Aggregate aggregate, string aggregateId, Command command) { string modelName = ModelNameGetter.GetModelName(aggregate.GetType()); try { Event[] results = aggregate.execute(command); EventStore.AppendAllEventsFor(modelName, aggregateId, results); foreach (Event evt in results) { aggregate.hydrate(evt); } //TODO okay, good. so it looks as though each read model does indeed respond to each event. //you can make a special read model for each character and have that in addition to the read models for each character, //it doesn't really matter. foreach (Reducer reducer in reducers) { foreach (Event evt in results) { reducer.Reduce(evt, ModelRepository.GetTable(reducer.ModelName)); } } return(true); } catch (ValidationException e) { Debug.Log(e.Message); } return(false); }
public static ServerResponse AdvanceStory(string characterName, string playerId, string input) { Command command = new AdvanceStory(characterName, playerId, input); Aggregate character = AggregateRepository.GetOrCreate(typeof(CharacterAggregate), characterName); bool success = CommandHandler.HandleCommand(character, characterName, command); ServerResponse response = new ServerResponse(characterName, ModelNameGetter.GetModelName(character.GetType()), !success); return(response); }
public static ServerResponse CreateCharacter(string characterName, string characterGreeting) { Command command = new CreateCharacter(characterName, characterGreeting); Aggregate character = AggregateRepository.GetOrCreate(typeof(CharacterAggregate), characterName); bool success = CommandHandler.HandleCommand(character, characterName, command); ServerResponse response = new ServerResponse(characterName, ModelNameGetter.GetModelName(character.GetType()), !success); return(response); }
public static ServerResponse AddNodeToStory(string characterName, string storyLineId, string introductoryText, string[] playerResponses, string[] characterResponses, Event[] eventsToPublishOnReaching = null) { Command command = new AddNodeToStory(characterName, storyLineId, introductoryText, playerResponses, characterResponses, eventsToPublishOnReaching); Aggregate character = AggregateRepository.GetOrCreate(typeof(CharacterAggregate), characterName); bool success = CommandHandler.HandleCommand(character, characterName, command); ServerResponse response = new ServerResponse(characterName, ModelNameGetter.GetModelName(character.GetType()), !success); return(response); }
public override void Initialize() { data = new Dictionary<string, Dictionary<string, LinkedList<Event>>> (); Assembly assembly = Assembly.GetExecutingAssembly (); foreach (Type type in assembly.GetTypes()) { if (type.BaseType == typeof(ReadModel)) { CreateStreamsFor (ModelNameGetter.GetModelName (type)); } } }
public static ServerResponse BeginGame() { string playerId = System.Guid.NewGuid().ToString(); //stub in for now; eventually have a text field where player can enter name string playerName = "Chase"; Command command = new BeginNewGame(playerId, playerName); Aggregate player = new PlayerAggregate(); bool success = CommandHandler.HandleCommand(player, playerId, command); ServerResponse response = new ServerResponse(playerId, ModelNameGetter.GetModelName(player.GetType()), !success); return(response); }
public override void Initialize() { repository = new Dictionary <string, ModelTable> (); Assembly assembly = Assembly.GetExecutingAssembly(); foreach (Type type in assembly.GetTypes()) { if (type.BaseType == typeof(ReadModel)) { CreateTable(ModelNameGetter.GetModelName(type)); } } }
public static Aggregate GetOrCreate(Type aggregateType, string aggregateId) { string modelName = ModelNameGetter.GetModelName(aggregateType); Aggregate aggregate; AggregateTable table = GetTable(modelName); try{ aggregate = table.GetAggregate(aggregateId); } catch (KeyNotFoundException k) { ConstructorInfo cInfo = aggregateType.GetConstructor(Type.EmptyTypes); aggregate = (Aggregate)cInfo.Invoke(Type.EmptyTypes); table.InsertAggregate(aggregateId, aggregate); } return(aggregate); }
public Reducer() { this.modelName = ModelNameGetter.GetModelName(this.GetType()); }