Ejemplo n.º 1
0
        public void AddCompare(AutomationTask task, string fileAPath, string fileAHash, string fileBPath, string fileBHash, AutomationCompareMode compareMode)
        {
            AutomationCompare compare = new AutomationCompare()
            {
                CompareAFilepath = fileAPath,
                CompareAHash     = fileAHash,
                CompareBFilepath = fileBPath,
                CompareBHash     = fileBHash,
                CompareMode      = compareMode
            };

            AddCompare(task, compare);
        }
        public async Task <bool> RunTasksAsync()
        {
            ExecutionTimeStopwatch.Restart();
            RunningTask = null;
            ExitCode    = SequencerExitCode.NotRun;
            if (Package == null || AutomationSequencer == null || AutomationRunnerSettings == null)
            {
                throw new NullReferenceException();
            }

            Logging.Debug(Logfiles.AutomationRunner, "Setting up macro list before task run");
            AllMacros.Clear();
            AllMacros.AddRange(ApplicationMacros);
            foreach (AutomationMacro macro in GlobalMacros)
            {
                AllMacros.Add(AutomationMacro.Copy(macro));
            }

            //process local macros in case they were added with macros inside them
            foreach (AutomationMacro macro in SequenceMacros)
            {
                macro.Value = AutomationTask.ProcessMacro(macro.Name, macro.Value, SequenceMacros);
                AllMacros.Add(AutomationMacro.Copy(macro));
            }

            Logging.Debug(Logfiles.AutomationRunner, "Setting up working directory");
            string workingDirectory = Path.Combine(ApplicationConstants.RelhaxTempFolderPath, Package.PackageName);

            if (Directory.Exists(workingDirectory))
            {
                Logging.Debug("Directory exits, delete");
                if (!await FileUtils.DirectoryDeleteAsync(workingDirectory, true, true))
                {
                    Logging.Error(LogOptions.ClassName, "Failed to clear the working directory");
                    return(false);
                }
            }
            Directory.CreateDirectory(workingDirectory);

            bool taskReturnGood = true;

            for (int index = 0; index < AutomationTasks.Count; index++)
            {
                AutomationTask task = AutomationTasks[index];
                RunningTask = task;
                bool breakLoop = false;
                Logging.Info(Logfiles.AutomationRunner, LogOptions.MethodName, "Running task: {0}", task.ID);
                try
                {
                    await task.Execute();
                }
                catch (Exception ex)
                {
                    if (task is ICancelOperation taskThatNeedsCancel)
                    {
                        taskThatNeedsCancel.Cancel();
                    }

                    if (!(ex is OperationCanceledException))
                    {
                        Logging.Exception(ex.ToString());
                    }
                }

                switch (task.ExitCode)
                {
                case AutomationExitCode.None:
                    breakLoop      = false;
                    taskReturnGood = true;
                    ExitCode       = SequencerExitCode.NoErrors;
                    break;

                case AutomationExitCode.Cancel:
                    breakLoop      = true;
                    taskReturnGood = true;
                    ExitCode       = SequencerExitCode.Cancel;
                    break;

                case AutomationExitCode.ComparisonNoFilesToUpdate:
                    breakLoop      = true;
                    taskReturnGood = true;
                    ExitCode       = SequencerExitCode.NoErrors;
                    break;

                case AutomationExitCode.ComparisonManualFilesToUpdate:
                    breakLoop      = true;
                    taskReturnGood = true;
                    ExitCode       = SequencerExitCode.NoErrors;
                    break;

                default:
                    Logging.Error(Logfiles.AutomationRunner, LogOptions.MethodName, "The task, '{0}', failed to execute. Check the task error output above for more details. You may want to enable verbose logging.", task.ID);
                    breakLoop      = true;
                    taskReturnGood = false;
                    ExitCode       = SequencerExitCode.Errors;
                    break;
                }

                if (CancellationToken.IsCancellationRequested)
                {
                    breakLoop      = true;
                    taskReturnGood = true;
                    ExitCode       = SequencerExitCode.Cancel;
                }

                if (breakLoop)
                {
                    break;
                }
            }

            //dispose/cleanup the tasks
            AutomationTasks.Clear();
            RunningTask = null;
            Logging.Info("Sequence {0} completed in {1} ms", PackageName, ExecutionTimeStopwatch.ElapsedMilliseconds);
            Dispose();
            return(taskReturnGood);
        }
Ejemplo n.º 3
0
 public void AddCompare(AutomationTask task, AutomationCompare compare)
 {
     compare.AutomationTask = task;
     AutomationCompares.Add(compare);
 }