private async Task <SequencerExitCode> RunSequencesAsync(List <AutomationSequence> sequencesToRun)
        {
            RunningSequence = null;
            if (sequencesToRun.Count == 0)
            {
                Logging.Error(Logfiles.AutomationRunner, LogOptions.ClassName, "No sequences specified in AutomationSequences list");
                return(SequencerExitCode.NotRun);
            }

            Logging.Info(Logfiles.AutomationRunner, LogOptions.ClassName, "Running automation sequencer");
            NumErrors = 0;

            SequencerExitCode exitCode;

            foreach (AutomationSequence sequence in sequencesToRun)
            {
                RunningSequence = sequence;
                Logging.Info(Logfiles.AutomationRunner, LogOptions.ClassName, "Preparing macro lists for sequence run: {0}", sequence.ComponentInternalName);

                //handling macros (application, global, local)
                if (!ResetApplicationMacros(sequence))
                {
                    return(SequencerExitCode.ResetApplicationMacrosFail);
                }
                if (!ParseGlobalMacros())
                {
                    return(SequencerExitCode.LoadGlobalMacrosFail);
                }
                if (!sequence.ParseSequenceMacros())
                {
                    return(SequencerExitCode.LoadLocalMacrosFail);
                }

                //handling if dumping macros and environment vars to disk
                if (AutomationRunnerSettings.DumpParsedMacrosPerSequenceRun)
                {
                    DumpApplicationMacros();
                    DumpGlobalMacros();
                }
                if (AutomationRunnerSettings.DumpShellEnvironmentVarsPerSequenceRun)
                {
                    DumpShellEnvironmentVariables();
                }

                Logging.Info(Logfiles.AutomationRunner, LogOptions.ClassName, "Running sequence: {0}", sequence.ComponentInternalName);
                await sequence.RunTasksAsync();

                exitCode = sequence.ExitCode;
                Logging.Info("----------------------- SEQUENCE RESULTS -----------------------");
                switch (exitCode)
                {
                case SequencerExitCode.Errors:
                case SequencerExitCode.NotRun:
                    Logging.Error(Logfiles.AutomationRunner, LogOptions.ClassName, "Sequence {0} result {1}. Check the log above or enable verbose logging for details.", sequence.ComponentInternalName, exitCode.ToString());
                    NumErrors++;
                    break;

                case SequencerExitCode.NoErrors:
                case SequencerExitCode.Cancel:
                    Logging.Info(Logfiles.AutomationRunner, LogOptions.ClassName, "Sequence {0} result {1}.", sequence.ComponentInternalName, exitCode.ToString());
                    break;
                }
                Logging.Info("----------------------------------------------------------------");

                if (NumErrors == 0)
                {
                    Logging.Info("Saving database before next sequence");
                    DatabaseManager.SaveDatabase(AutomationRunnerSettings.DatabaseSavePath);
                }
            }

            Logging.Info(Logfiles.AutomationRunner, LogOptions.ClassName, "Sequence run finished with {0} errors of {1} total sequences.", NumErrors, sequencesToRun.Count);
            RunningSequence = null;

            if (CancellationToken != null && CancellationToken.IsCancellationRequested)
            {
                return(SequencerExitCode.Cancel);
            }
            else if (NumErrors == 0)
            {
                return(SequencerExitCode.NoErrors);
            }
            else
            {
                return(SequencerExitCode.Errors);
            }
        }
        private bool ResetApplicationMacros(AutomationSequence sequence)
        {
            Logging.Debug(Logfiles.AutomationRunner, LogOptions.ClassName, "Resetting application macros");

            //check that required automation settings are set for being able to reset macaros
            if (string.IsNullOrEmpty(AutomationRunnerSettings.WoTClientInstallLocation))
            {
                Logging.Error("WoTClientInstallLocation is not set in settings tab!");
                return(false);
            }
            if (!File.Exists(AutomationRunnerSettings.WoTClientInstallLocation))
            {
                Logging.Error("WoTClientInstallLocation file does not exist!");
                return(false);
            }

            DatabasePackage   package           = sequence.Package;
            SelectablePackage selectablePackage = package as SelectablePackage;

            ApplicationMacros.Clear();
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "date", Value = DateTime.UtcNow.ToString("yyyy-MM-dd"), MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "category.name", Value = (selectablePackage != null) ? selectablePackage.ParentCategory.Name : "null", MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "name", Value = (selectablePackage != null) ? selectablePackage.NameFormatted : "null", MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "packageName", Value = package.PackageName, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "packageUID", Value = package.UID, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "zipfile", Value = package.ZipFile, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "level", Value = (selectablePackage != null) ? selectablePackage.Level.ToString() : "null", MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "patchGroup", Value = package.PatchGroup.ToString(), MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "installGroup", Value = package.InstallGroupWithOffset.ToString(), MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "clientVersion", Value = WoTClientVersion, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "onlineFolderVersion", Value = WoTModpackOnlineFolderVersion, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "author", Value = package.Author, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "version", Value = package.Version, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "applicationPath", Value = ApplicationConstants.ApplicationStartupPath, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "relhaxTemp", Value = ApplicationConstants.RelhaxTempFolderPath, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "workDirectory", Value = string.Format("{0}\\{1}", ApplicationConstants.RelhaxTempFolderPath, package.PackageName), MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "automationRepoRoot", Value = AutomationRepoPathEscaped, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "clientPath", Value = Path.GetDirectoryName(AutomationRunnerSettings.WoTClientInstallLocation)
            });
            return(true);
        }
Exemplo n.º 3
0
        public void ResetApplicationMacros(AutomationSequence sequence)
        {
            Logging.Debug(Logfiles.AutomationRunner, LogOptions.ClassName, "Resetting application macros");
            DatabasePackage   package           = sequence.Package;
            SelectablePackage selectablePackage = package as SelectablePackage;

            ApplicationMacros.Clear();
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "date", Value = DateTime.UtcNow.ToString("yyyy-MM-dd"), MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "category.name", Value = (selectablePackage != null)? selectablePackage.ParentCategory.Name : "null", MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "name", Value = (selectablePackage != null)? selectablePackage.NameFormatted : "null", MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "packageName", Value = package.PackageName, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "zipfile", Value = package.ZipFile, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "level", Value = (selectablePackage != null)? selectablePackage.Level.ToString() : "null", MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "patchGroup", Value = package.PatchGroup.ToString(), MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "installGroup", Value = package.InstallGroupWithOffset.ToString(), MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "clientVersion", Value = WoTClientVersion, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "onlineFolderVersion", Value = WoTModpackOnlineFolderVersion, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "author", Value = package.Author, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "version", Value = package.Version, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "applicationPath", Value = ApplicationConstants.ApplicationStartupPath, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "relhaxTemp", Value = ApplicationConstants.RelhaxTempFolderPath, MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "workDirectory", Value = string.Format("{0}\\{1}", ApplicationConstants.RelhaxTempFolderPath, package.PackageName), MacroType = MacroType.ApplicationDefined
            });
            ApplicationMacros.Add(new AutomationMacro()
            {
                Name = "automationRepoRoot", Value = AutomationXmlRepoFilebaseEscaped, MacroType = MacroType.ApplicationDefined
            });
        }