public Command(CommandExecutor executor, string name) { if (executor == null) throw new ArgumentNullException("executor"); if (name == null) throw new ArgumentNullException("name"); this.executor = executor; Name = name; logDeExecucao = new LogEvent { Message = name }; }
public void CasoGrande() { var logEventPai = new LogEvent { Status = StatusLog.Success }; logEventPai.AdicionaFilho(new LogEvent { Status = StatusLog.Success, Events = new List<LogEvent> { new LogEvent { Status = StatusLog.Warning }, new LogEvent { Status = StatusLog.Success } } }); logEventPai.AdicionaFilho(new LogEvent { Status = StatusLog.Success, Events = new List<LogEvent> { new LogEvent { Status = StatusLog.Error } } }); logEventPai.AdicionaFilho(new LogEvent { Status = StatusLog.Success, Events = new List<LogEvent> { new LogEvent { Status = StatusLog.Success } } }); Assert.AreEqual(StatusLog.Warning, logEventPai.Events[0].Status, "Primeiro filho deve ser Warning"); Assert.AreEqual(StatusLog.Error, logEventPai.Events[1].Status, "Segundo filho deve ser Error"); Assert.AreEqual(StatusLog.Success, logEventPai.Events[2].Status, "Terceiro filho deve ser Success"); Assert.AreEqual(StatusLog.Success, logEventPai.Events[2].Events[0].Status, "Filho do terceiro filho deve ser Success"); Assert.AreEqual(StatusLog.Error, logEventPai.Status, "Pai deve ser Error"); }
public void LogSemFilhosDeveTerOProprioStatus() { var logEvent = new LogEvent { Status = StatusLog.Success }; Assert.AreEqual(StatusLog.Success, logEvent.Status); }
public void LogComFilhosComStatusErroOPaiTambemDeveSerErro() { //prescedência: Erro, Warning, Sucesso var logWarning = new LogEvent {Status = StatusLog.Warning}; var logError = new LogEvent {Status = StatusLog.Error}; var logEventPai = new LogEvent { Status = StatusLog.Success }; logEventPai.AdicionaFilho(logError); logEventPai.AdicionaFilho(logWarning); Assert.AreEqual(StatusLog.Error, logEventPai.Status); }
public void FilhoComWarningPaiDeveSerWarning() { var logEventPai = new LogEvent { Status = StatusLog.Success }; logEventPai.AdicionaFilho(new LogEvent { Status = StatusLog.Warning }); Assert.AreEqual(StatusLog.Warning, logEventPai.Status, "Pai deve ser Warning"); }
public void FilhoComErrorPaiDeveSerError() { var logEventPai = new LogEvent { Status = StatusLog.Success }; logEventPai.AdicionaFilho(new LogEvent { Status = StatusLog.Error }); Assert.AreEqual(StatusLog.Error, logEventPai.Status, "Pai deve ser Error"); }
private LogEvent PreencheDatas(LogEvent logEvent) { logEvent.DataFim = DateTime.Now; logEvent.DataInicio = Events.Count > 0 ? Events[Events.Count - 1].DataFim : DataInicio; return logEvent; }
public void AtualizaStatus(LogEvent log) { if (!ConsolidaErros) return; switch (log.Status) { case StatusLog.Warning: case StatusLog.Error: Status = StatusLog.Warning; break; } }
public void AdicionaFilho(LogEvent log) { AtualizaStatus(log); if (Events == null) { Events = new List<LogEvent>(); } Events.Add(PreencheDatas(log)); }
/// <summary> /// Resets the command list /// </summary> protected void Reset() { Commands = new ICommand[0]; Log = new LogEvent{Message = Name}; }
public virtual bool Execute(Context context) { // Verify our parameters if (context == null) { throw new ArgumentNullException(); } if (Logger.IsDebugEnabled) { Logger.Debug(String.Format("{0} command(s) in chain.", Commands.Length)); } Frozen = true; bool saveResult = false; SaveException = null; Log = new LogEvent {Message = Name, DataInicio = DateTime.Now}; var stopWatch = new Stopwatch(); for (var i = 0; i < Commands.Length; i++) { if (StopExecution) { Logger.Debug("Stopping command..."); StopExecution = false; break; } var command = Commands[i]; if (Logger.IsInfoEnabled) { Logger.Info(String.Format("{0}. Starting \"{1}\" execution.", i, command.Name)); } try { stopWatch.Start(); saveResult = command.Execute(context); if (saveResult) { break; } } catch (Exception e) { Log.Status = StatusLog.Error; Log.Message = command.Name + ": " + e.Message; Logger.Error(String.Format("Exception during \"{0}\" execution.", command.Name), e); SaveException = e; if (PauseOnException) { throw; // break; } } finally { stopWatch.Stop(); Log.AdicionaFilho(command.GetLog()); if (Logger.IsInfoEnabled) { Logger.Info(String.Format("Finishing \"{0}\" execution in {1} seg.", command.Name, stopWatch.ElapsedMilliseconds / 1000.00)); } } } Log.DataFim = DateTime.Now; return (saveResult); }