private void RecoverSystem(System.Type systemType, CommandLogReader reader, ExceptionDuringRecoveryHandler handler) { _system = reader.ReadLastSnapshot(); if (null == _system) { _system = System.Activator.CreateInstance(systemType); } RecoverCommands(reader, handler); }
private void RecoverCommands(CommandLogReader reader, ExceptionDuringRecoveryHandler handler) { ShareCurrentObject(); try { Clock.Pause(); try { foreach (ContextRecoveryCommand contextRecoveryCommand in reader) { Clock.Recover(contextRecoveryCommand.DateTime); ICommand command = contextRecoveryCommand.Command; try { command.Execute(_system); } catch (System.Exception x) { // commands are allowed to throw exceptions // it is up to the client to decide what to // do with them OnExceptionDuringRecovery(handler, command, x); } } } finally { Clock.Resume(); } } finally { UnshareCurrentObject(); } }
/// <summary> /// See <see cref="PrevalenceActivator.CreateEngine(System.Type, string)"/> /// </summary> /// <param name="systemType"></param> /// <param name="prevalenceBase"></param> /// <param name="formatter"></param> /// <param name="handler"></param> internal PrevalenceEngine(System.Type systemType, string prevalenceBase, BinaryFormatter formatter, ExceptionDuringRecoveryHandler handler) { _clock = new AlarmClock(); CommandLogReader reader = new CommandLogReader(CheckPrevalenceBase(prevalenceBase), formatter); RecoverSystem(systemType, reader, handler); _commandLog = reader.ToWriter(); _lock = new ReaderWriterLock(); _decorators = GetCommandDecorators(systemType); _paused = false; }