示例#1
0
 public void ApplyLogToStateMachine(LogEntry entry)
 {
     foreach (var command in entry.DeepCopy().Commands)
     {
         try
         {
             lock (currentStateLock)
             {
                 CurrentState.ApplyCommand(command);
             }
         }
         catch (Exception e)
         {
             if (!_disabledLogging)
             {
                 _logger.LogDebug("Failed to apply entry with message: " + e.Message + Environment.NewLine + e.StackTrace);
             }
         }
     }
 }
示例#2
0
        public void ApplyLogsToStateMachine(IEnumerable <LogEntry> entries)
        {
            List <string> FailedLogs = new List <string>();
            var           copy       = entries.OrderBy(c => c.Index).Select(e => e.DeepCopy());

            foreach (var entry in copy)
            {
                foreach (var command in entry.Commands)
                {
                    try
                    {
                        if (!_disabledLogging)
                        {
                            _logger.LogDebug("Applying command " + Environment.NewLine + JsonConvert.SerializeObject(command, Formatting.Indented));
                        }

                        lock (currentStateLock)
                        {
                            CurrentState.ApplyCommand(command);
                        }
                        if (!_disabledLogging)
                        {
                            _logger.LogDebug("State " + Environment.NewLine + JsonConvert.SerializeObject(CurrentState, Formatting.Indented));
                        }
                    }
                    catch (Exception e)
                    {
                        if (!_disabledLogging)
                        {
                            _logger.LogDebug("Failed to apply entry with message: " + e.Message + Environment.NewLine + e.StackTrace);
                        }
                    }
                }
            }

            /*if(FailedLogs.Count() > 0)
             * {
             *  throw new Exception("Failed to apply all commands successfully, the following logs failed to apply to state" + Environment.NewLine + JsonConvert.SerializeObject(FailedLogs));
             * }*/
        }