Beispiel #1
0
        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;
                }
            }
        }
Beispiel #2
0
        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;
                }
            }
        }