public static CommandScheduled GetCommandEvent(long logIdx, byte[] data, Action executeAction) { var @event = new CommandScheduled { Command = new TestExecutableCommand(executeAction) }.Translate(new CommandScheduled(), 1L); @event.SetLogEntry(new LogEntry { Index = logIdx }, data); return(@event); }
// TODO: Should add checksum for validation when sourcing from log... http://stackoverflow.com/questions/10335203/is-there-any-very-rapid-checksum-generation-algorithm public override void Handle(CommandScheduled @event) { var logEntry = new LogEntry { Term = _node.Data.CurrentTerm, Index = _lastLogId + 1, CommandType = @event.Command.GetType().AssemblyQualifiedName, Command = @event.Command }; using (var ms = new MemoryStream()) { Serializer.SerializeWithLengthPrefix(ms, logEntry, PrefixStyle.Base128); @event.SetLogEntry(logEntry, ms.ToArray()); } _lastLogId++; }