public override IScriptCommand Execute(IParameterDic pm) { switch (Mode) { case RunMode.Parallel: case RunMode.Queue: ScriptRunner.RunScript(pm, ScriptCommands); break; case RunMode.Sequence: foreach (var cmd in ScriptCommands) { ScriptRunner.RunScript(pm, cmd); if (pm.Error() != null) { return(ResultCommand.Error(pm.Error())); } } break; default: return(ResultCommand.Error(new NotSupportedException(Mode.ToString()))); } if (pm.Error() != null) { return(ResultCommand.Error(pm.Error())); } else { return(NextCommand); } }
public async Task RunAsync(Queue <IScriptCommand> cmds, IParameterDic initialParameters) { IParameterDic pd = initialParameters; pd.ScriptRunner(this); while (cmds.Any()) { try { var current = cmds.Dequeue(); if (current.CanExecute(pd)) { //pd.CommandHistory.Add(current.CommandKey); //logger.Info("Running " + current.CommandKey); try { var retCmd = await current.ExecuteAsync(pd) .ConfigureAwait(current.RequireCaptureContext()); if (retCmd != null) { if (pd.Error() != null) { logger.Error("Error when running script", pd.Error()); return; } cmds.Enqueue(retCmd); } } catch (Exception ex) { throw ex; } } else { throw new Exception(String.Format("Cannot execute {0}", current)); } } catch (Exception ex) { pd.Error(ex); logger.Error("Error when running script", ex); var progress = pd.Progress <Defines.TransferProgress>(); if (progress != null) { progress.Report(Defines.TransferProgress.Error(ex)); } throw ex; } } }
public override IScriptCommand Execute(IParameterDic pm) { ScriptRunner.RunScript(pm, ScriptCommands); if (pm.Error() != null) { return(ResultCommand.Error(pm.Error())); } else { return(_nextCommand); } }
public override async Task <IScriptCommand> ExecuteAsync(IParameterDic pm) { await ScriptRunner.RunScriptAsync(pm, ScriptCommands); if (pm.Error() != null) { return(ResultCommand.Error(pm.Error())); } else { return(_nextCommand); } }
public override bool CanExecute(IParameterDic pm) { IParameterDic pm2 = pm.Clone(); ScriptRunner.RunScriptAsync(pm2, ConditionCommand); return(pm2.IsHandled() && pm2.Error() == null); }
public void Run(Queue <IScriptCommand> cmds, IParameterDic initialParameters) { IParameterDic pd = initialParameters; pd.ScriptRunner(this); while (cmds.Any()) { try { var current = cmds.Dequeue(); //logger.Info("Running " + current.CommandKey); if (current.CanExecute(pd)) { //(pd.Progress<IScriptCommand>() as IProgress<IScriptCommand>).Report() //pd.CommandHistory.Add(current.CommandKey); var retCmd = current.Execute(pd); if (retCmd != null) { if (pd.Error() != null) { throw pd.Error(); } cmds.Enqueue(retCmd); } } else if (!(current is NullScriptCommand)) { throw new Exception(String.Format("Cannot execute {0}", current)); } } catch (Exception ex) { pd.Error(ex); logger.Error("Error when running script", ex); var progress = pd.Progress <Defines.TransferProgress>(); if (progress != null) { progress.Report(Defines.TransferProgress.Error(ex)); } throw ex; } } }
public override async Task <IScriptCommand> ExecuteAsync(IParameterDic pm) { IEnumerable e = pm.Get <IEnumerable>(ItemsKey); if (e == null) { return(ResultCommand.Error(new ArgumentException(ItemsKey))); } IProgress <TransferProgress> progress = NullProgress <TransferProgress> .Instance; if (IsProgressEnabled) { List <object> list; e = list = e.Cast <object>().ToList(); progress = pm.Progress <TransferProgress>(); progress.Report(TransferProgress.IncrementTotalEntries(list.Count)); } uint counter = 0; pm.Set <bool>(BreakKey, false); foreach (var item in e) { if (pm.Get <bool>(BreakKey)) { break; } counter++; pm.Set(CurrentItemKey, item); await ScriptRunner.RunScriptAsync(pm, NextCommand); progress.Report(TransferProgress.IncrementProcessedEntries()); if (pm.Error() != null) { pm.Set <Object>(CurrentItemKey, null); return(ResultCommand.Error(pm.Error())); } } logger.Info(String.Format("Looped {0} items", counter)); pm.Set <Object>(CurrentItemKey, null); return(ThenCommand); }
private bool runCommand(IScriptCommand command, IParameterDic pm = null) { pm = pm ?? new ParameterDic(); while (command != null && !(command is ResultCommand)) { command = command.Execute(pm); } return((command == null) && (pm.Error() == null)); }
public override async Task <IScriptCommand> ExecuteAsync(IParameterDic pm) { if (CanExecute(pm)) { return(NextCommand); } else { return(ResultCommand.Error(pm.Error() ?? new ArgumentException("pm"))); } }
public override async Task <IScriptCommand> ExecuteAsync(IParameterDic pm) { switch (Mode) { case RunMode.Parallel: await Task.WhenAll(ScriptCommands.Select(cmd => ScriptRunner.RunScriptAsync(pm.Clone(), cmd))); break; case RunMode.Queue: await ScriptRunner.RunScriptAsync(pm, ScriptCommands) .ConfigureAwait(this.ContinueOnCaptureContext); break; case RunMode.Sequence: foreach (var cmd in ScriptCommands) { await ScriptRunner.RunScriptAsync(pm, cmd) .ConfigureAwait(this.ContinueOnCaptureContext); if (pm.Error() != null) { return(ResultCommand.Error(pm.Error())); } } break; default: return(ResultCommand.Error(new NotSupportedException(Mode.ToString()))); } if (pm.Error() != null) { return(ResultCommand.Error(pm.Error())); } else { return(NextCommand); } }
public override IScriptCommand Execute(IParameterDic pm) { if (_exception == null) { if (MarkHandled) { pm.IsHandled(true); } //logger.Debug("OK"); } else { logger.Error(_exception.Message, _exception); pm.Error(_exception); } return(NextCommand); }
public override IScriptCommand Execute(IParameterDic pm) { List <IScriptCommand> outputCommands = new List <IScriptCommand>(); foreach (var s in _source) { var command = _commandFunc(s); var outputCommand = command.Execute(pm); if (pm.Error() != null) { return(outputCommand); } if (outputCommand != ResultCommand.NoError && outputCommand != ResultCommand.OK) { outputCommands.Add(outputCommand); } } return(new RunInSequenceScriptCommand(outputCommands.ToArray(), _nextCommand)); }
public override async Task <IScriptCommand> ExecuteAsync(IParameterDic pm) { List <IScriptCommand> outputCommands = new List <IScriptCommand>(); foreach (var s in _source) { var outputCommand = await _commandFunc(s).ExecuteAsync(pm); if (pm.Error() != null) { return(outputCommand); } if (outputCommand != ResultCommand.NoError && outputCommand != ResultCommand.OK) { outputCommands.Add(outputCommand); } } return(outputCommands.Count() == 0 ? _nextCommand : new RunInSequenceScriptCommand(outputCommands.ToArray(), _nextCommand)); }