protected override Snapshot WriteSnapshotImpl(Model model) { var bytes = _formatter.ToByteArray(model); var snapshot = new Snapshot(DateTime.Now, model.Revision); _state.Snapshots.Add(snapshot, bytes); return snapshot; }
protected override Snapshot WriteSnapshotImpl(Model model) { var fileSnapshot = new FileSnapshot(DateTime.Now, model.Revision); var fileName = Path.Combine(_config.Location.OfSnapshots, fileSnapshot.Name); using (Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { _formatter.Serialize(stream, model); } return fileSnapshot; }
/// <summary> /// Apply the command to the food taster. If it succeeds, apply to the real model. /// </summary> /// <param name="command"></param> /// <returns></returns> public override object ExecuteCommand(Command command) { try { command.PrepareStub(_foodTaster); command.ExecuteStub(_foodTaster); //outofmemory,commandaborted, unhandled user } catch (CommandAbortedException) { throw; } catch (OutOfMemoryException) { throw; } catch (Exception ex) { _foodTaster = _formatter.Clone(Model); //reset throw new CommandAbortedException("Royal taster died of food poisoning, see inner exception for details", ex); } return base.ExecuteCommand(command); }
internal virtual void Redo(ref Model model) { PrepareStub(model); ExecuteStub(model); }
/// <summary> /// Perform read operations before the write lock is obtained. /// </summary> /// <param name="model"></param> internal abstract void PrepareStub(Model model);
internal abstract object ExecuteStub(Model model);
public RoyalFoodTaster(EngineConfiguration config, Model model) : base(config, model) { _formatter = config.CreateFormatter(FormatterUsage.Snapshot); _foodTaster = _formatter.Clone(Model); }
public OptimisticKernel(EngineConfiguration config, Model model) : base(config, model) { }
protected override Snapshot WriteSnapshotImpl(Model model, ulong lastAppliedEntryId) { var fileSnapshot = new FileSnapshot(DateTime.Now, lastAppliedEntryId); var fileName = Path.Combine(_config.Location.OfSnapshots, fileSnapshot.Name); using (Stream stream = GetWriteStream(fileName, append:false)) { _snapshotFormatter.Serialize(stream, model); } return fileSnapshot; }
public ImmutabilityKernel(EngineConfiguration config, Model model) : base(config, model) { }
private void UnpackTuple(object tuple, out Model model, out object result) { var type = tuple.GetType(); model = (Model)type.GetProperty("Item1").GetGetMethod().Invoke(tuple, null); result = type.GetProperty("Item2").GetGetMethod().Invoke(tuple, null); }
internal override void PrepareStub(Model model) { throw new NotImplementedException(); }
internal override object ExecuteStub(Model model) { throw new NotImplementedException(); }