public QueryResult Process(IMessage _, IMessageContextModel ctx) { var model = ctx as SelectDueCardContextModel; var result = new ProgressQueryResult { Bins = new ProgressQueryResult.Bin[Math.Max(model.Bins.Length, model.Config?.Bins.Length+2 ?? 0)] }; for(var i = 0; i < result.Bins.Length; i++) result.Bins[i] = new ProgressQueryResult.Bin { Count = i < model.Bins.Length ? model.Bins[i].Length : 0 }; if (model.Config != null) for (var i = 1; i < result.Bins.Length; i++) { var j = i - 1; if (j < model.Config.Bins.Length) { result.Bins[i].LowerDueThreshold = model.Config.Bins[j].LowerDueThreshold; result.Bins[i].UpperDueThreshold = model.Config.Bins[j].UpperDueThreshold; } } if (model.DueBinIndex > 0 && model.DueBinIndex < result.Bins.Length) result.Bins[model.DueBinIndex].IsDue = true; return result; }
public QueryResult Process(IMessage msg, IMessageContextModel ctx) { var model = ctx as AllTodosQueryCtxModel; var todos = model.Todos.Select(Map); return(new AllTodosQueryResult { Todos = todos.ToArray() }); }
public QueryResult Process(IMessage msg, IMessageContextModel ctx) { var model = ctx as DueCardContextModel; if (model.DueCard != null) { return(model.DueCard); } return(new DueCardNotFoundQueryResult()); }
public (CommandStatus, Event[], string, Notification[]) Process(IMessage msg, IMessageContextModel ctx, string version) { var model = ctx as SyncContextModel; var events0 = Sync_flashcards(model).ToArray(); var events1 = Sync_config(model); return(Calculate_success_stats(), events0.Concat(events1).ToArray(), "", new Notification[0]); SyncSuccess Calculate_success_stats() { var stats = new SyncSuccess { Added = events0.Count(e => e is NewCardEncountered), Changed = events0.Count(e => e is CardWasChanged), Missing = events0.Count(e => e is CardFoundMissing), }; stats.TotalCount = model.Flashcards.Count + stats.Added - stats.Missing; return(stats); } }
public (CommandStatus, Event[], string, Notification[]) Process(IMessage msg, IMessageContextModel ctx, string version) => (new Success(),
public (CommandStatus, Event[], string, Notification[]) Process(IMessage msg, IMessageContextModel ctx, string version) { var cmd = msg as RegisterAnswerCommand; var model = ctx as RegisterAnswerContextModel; if (model.CardsInBins.ContainsKey(cmd.CardId) is false) { return(new Failure($"Cannot register answer for unknown card '{cmd.CardId}'!"), new Event[0], "", new Notification[0]); } Event[] events; if (cmd.CorrectlyAnswered) { events = new Event[] { new QuestionAnsweredCorrectly { CardId = cmd.CardId }, new CardMovedTo { CardId = cmd.CardId, BinIndex = model.CardsInBins[cmd.CardId] + 1 } }; } else { events = new Event[] { new QuestionAnsweredIncorrectly { CardId = cmd.CardId }, new CardMovedTo { CardId = cmd.CardId, BinIndex = 1 } }; } return(new Success(), events, "", new Notification[0]); }
public (CommandStatus, Event[], string, Notification[]) Process(IMessage msg, IMessageContextModel ctx, string version) { var cmd = msg as CheckTodoCmd; var model = ctx as CheckTodoCmdCtxModel; if (model.Ids.Contains(cmd.Id) is false) { return(new Failure("Todo item not registered as active."), new Event[0], "", new Notification[0]); } var notifications = new Notification[0]; if (model.Ids.Length == 1) { notifications = new Notification[] { new FreeCapacityAvailableNotification() } } ; return(new Success(), new Event[] { new TodoChecked { TodoId = cmd.Id } }, "", notifications); } }
(CommandStatus, Event[], string, Notification[]) Process_with_notifications(IMessage msg, IMessageContextModel ctx, string version) { var value = (msg as MyCommand).Parameter + (ctx as MyCommandCtx).Value; return(new Success(), new[] { new MyEvent { Reversed = new string(value.Reverse().ToArray()) }, (Event) new YourEvent { Count = value.Length } }, "", new[] { new MyNotification { Original = (msg as MyCommand).Parameter } }); }
public (CommandStatus, Event[], string, Notification[]) Process(IMessage msg, IMessageContextModel ctx, string version) { var model = ctx as SelectDueCardContextModel; if (model.Config == null) { return(new Failure("Cannot select due card! Missing box configuration."), new Event[0], "", new Notification[0]); } var events = Select_due_bin_in_specific_order(model); if (No_due_bin_selected()) { events = Fill_bin_1_and_select(model); } if (No_due_bin_selected()) { events = Select_first_bin_with_cards(model); } return(No_due_bin_selected() ? ((CommandStatus) new Failure("Not enough cards in box to select due bin."), new Event[0], "", new Notification[0]) : (new Success(), events, "", new Notification[0])); bool No_due_bin_selected() => events.Length == 0; }