Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
 internal virtual void Redo(ref Model model)
 {
     PrepareStub(model);
     ExecuteStub(model);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Perform read operations before the write lock is obtained.
 /// </summary>
 /// <param name="model"></param>
 internal abstract void PrepareStub(Model model);
Ejemplo n.º 6
0
 internal abstract object ExecuteStub(Model model);
Ejemplo n.º 7
0
 public RoyalFoodTaster(EngineConfiguration config, Model model)
     : base(config, model)
 {
     _formatter = config.CreateFormatter(FormatterUsage.Snapshot);
     _foodTaster = _formatter.Clone(Model);
 }
Ejemplo n.º 8
0
 public OptimisticKernel(EngineConfiguration config, Model model)
     : base(config, model)
 {
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 public ImmutabilityKernel(EngineConfiguration config, Model model)
     : base(config, model)
 {
 }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
0
 internal override void PrepareStub(Model model)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
 internal override object ExecuteStub(Model model)
 {
     throw new NotImplementedException();
 }