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 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); }