public void Apply(LogEntry entry, Command cmd) { var betCmd = cmd as BetOnPonyCommand; if (betCmd != null) { var odd = OddsReference.AvailableOdds.FirstOrDefault(o => o.OddId == betCmd.OddId); if (odd != null) { this.Bets.Add(new Bet() { Odd = odd, UserId = betCmd.UserId, AmountOfMoney = betCmd.AmountOfMoney }); cmd.CommandResult = new { Result = "Success" }; } else { // TODO: figure out what to do if the odd is invalid } } var getCmd = cmd as GetAllBetsCommand; if (getCmd != null) { cmd.CommandResult = this.Bets; } this.LastAppliedIndex = cmd.AssignedIndex; }
public void Apply(LogEntry entry, Command cmd) { if (LastAppliedIndex >= entry.Index) throw new InvalidOperationException("Already applied " + entry.Index); LastAppliedIndex = entry.Index; var dicCommand = cmd as DictionaryCommand; if (dicCommand != null) dicCommand.Apply(Data); }
public void Apply(LogEntry entry, Command cmd) { var batch = cmd as OperationBatchCommand; if (batch != null) { Apply(batch.Batch, cmd.AssignedIndex); return; } var get = cmd as GetCommand; if (get != null) { cmd.CommandResult = Read(get.Key); } // have to apply even get command so we'll keep track of the last applied index Apply(Enumerable.Empty<KeyValueOperation>(), cmd.AssignedIndex); }
internal virtual void OnEntriesAppended(LogEntry[] logEntries) { var handler = EntriesAppended; if (handler != null) { try { handler(logEntries); } catch (Exception e) { _log.Error("Error on raising EntriesAppended event", e); } } }
protected void CommitEntries(LogEntry[] entries, long lastIndex) { var oldCommitIndex = Engine.CommitIndex + 1; Engine.ApplyCommits(oldCommitIndex, lastIndex); Engine.OnEntriesAppended(entries); }
public EntriesContent(LogEntry[] entries) { _entries = entries; }