public void Dispose()
 {
     ApplicationMacros.Clear();
     GlobalMacros.Clear();
     AutomationSequences.Clear();
     ((IDisposable)WebClient).Dispose();
 }
Пример #2
0
        public async Task <bool> LoadAutomationSequencesAsync(List <DatabasePackage> packagesToRun)
        {
            if (RootDocument == null)
            {
                throw new NullReferenceException();
            }
            if (packagesToRun == null)
            {
                throw new NullReferenceException();
            }
            if (packagesToRun.Count == 0)
            {
                throw new BadMemeException("packagesToRun must have at least one package to run automation on");
            }

            Logging.AutomationRunner(LogOptions.MethodName, "Checking root document for to build urls to download automation sequences", LogLevel.Info);
            foreach (DatabasePackage package in packagesToRun)
            {
                Logging.AutomationRunner(LogOptions.MethodName, "Parsing path for automation of package {0}", LogLevel.Info, package.PackageName);
                //sample xpath: /root.xml/AutomationSequence[@UID='123456789ABCD']
                XmlElement result = XmlUtils.GetXmlNodeFromXPath(RootDocument, string.Format("/root.xml/AutomationSequence[@UID='{0}']", package.UID)) as XmlElement;
                if (result == null)
                {
                    Logging.Error(Logfiles.AutomationRunner, "Package not found in automation database");
                    return(false);
                }

                if (result.Attributes["packageName"].Value != package.PackageName)
                {
                    Logging.Warning(Logfiles.AutomationRunner, "The packageName property is out of date. From database: {0}. From Package: {1}", result.Attributes["packageName"].Value, package.PackageName);
                }

                string pathToFileFromRepoRoot = result.Attributes["path"].Value;
                if (string.IsNullOrEmpty(pathToFileFromRepoRoot))
                {
                    Logging.Error(Logfiles.AutomationRunner, "Package path attribute not found from xml node");
                    return(false);
                }
                if (pathToFileFromRepoRoot[0] == '/')
                {
                    Logging.Warning(Logfiles.AutomationRunner, "Package path attribute starts with slash, please update entry to remove it!");
                    pathToFileFromRepoRoot = pathToFileFromRepoRoot.Substring(1);
                }
                AutomationSequences.Add(new AutomationSequence()
                {
                    AutomationSequencer = this, Package = package, SequenceDownloadUrl = AutomationXmlRepoFilebaseEscaped + pathToFileFromRepoRoot
                });
                Logging.Debug(Logfiles.AutomationRunner, "Added automation sequence URL: {0}", AutomationSequences.Last().SequenceDownloadUrl);
            }

            Logging.Info(Logfiles.AutomationRunner, LogOptions.MethodName, "Parsing each automationSequence xml document from its download URL");
            foreach (AutomationSequence automationSequence in AutomationSequences)
            {
                Logging.Info(Logfiles.AutomationRunner, "Load automation sequence xml for package {0}", automationSequence.Package.PackageName);
                await automationSequence.LoadAutomationXmlAsync();
            }

            return(true);
        }
        public bool ParseRootDocumentAsync()
        {
            if (RootDocument == null)
            {
                throw new NullReferenceException();
            }
            if (AutomationRunnerSettings == null)
            {
                throw new NullReferenceException();
            }

            Logging.AutomationRunner(LogOptions.MethodName, "Checking root document for to build automation sequences", LogLevel.Info);

            XmlNodeList sequencesXml = XmlUtils.GetXmlNodesFromXPath(RootDocument, "//root.xml/AutomationSequence");

            if (sequencesXml == null || sequencesXml.Count == 0)
            {
                return(false);
            }
            AutomationSequences.Clear();

            foreach (XmlElement result in sequencesXml)
            {
                string sequencePackageName = result.Attributes["packageName"].Value;
                string sequenceUID         = result.Attributes["UID"].Value;
                string sequenceUrlPath     = result.Attributes["path"].Value;
                string sequenceLoadString;

                if (AutomationRunnerSettings.UseLocalRunnerDatabase)
                {
                    sequenceUrlPath    = sequenceUrlPath.Replace('/', Path.DirectorySeparatorChar);
                    sequenceLoadString = Path.Combine(AutomationRepoPathEscaped, sequenceUrlPath);
                }
                else
                {
                    sequenceLoadString = AutomationRepoPathEscaped + sequenceUrlPath;
                }

                AutomationSequences.Add(new AutomationSequence(DatabasePackages, ApplicationMacros, GlobalMacros, AutomationRunnerSettings, DatabaseManager, CancellationToken)
                {
                    AutomationSequencer = this,
                    Package             = null,
                    PackageName         = sequencePackageName,
                    PackageUID          = sequenceUID,
                    SequenceDownloadUrl = sequenceLoadString
                });
            }

            return(true);
        }
        private void CleanWorkingDirectories(IProgress <RelhaxProgress> reporter, RelhaxProgress progress, CancellationToken token)
        {
            if (AutomationSequences == null || AutomationSequences.Count == 0)
            {
                return;
            }

            //get the list of files
            List <string> FilesToDelete         = new List <string>();
            List <string> FoldersToGetFilesFrom = AutomationSequences.Select(sequence => sequence.PackageName).ToList();

            foreach (string folder in FoldersToGetFilesFrom)
            {
                string folderPath = Path.Combine(ApplicationConstants.RelhaxTempFolderPath, folder);
                if (Directory.Exists(folderPath))
                {
                    FilesToDelete.AddRange(FileUtils.FileSearch(folderPath, SearchOption.AllDirectories, false, true));
                }

                if (token != null && token.IsCancellationRequested)
                {
                    return;
                }
            }

            if (progress != null)
            {
                progress.ChildTotal   = FilesToDelete.Count;
                progress.ChildCurrent = progress.ParrentCurrent = 0;
                reporter?.Report(progress);
            }


            foreach (string file in FilesToDelete)
            {
                progress.ChildCurrent++;
                progress.ChildCurrentProgress = string.Format("Deleting file {0} of {1}", progress.ChildCurrent, progress.ChildTotal);
                reporter.Report(progress);

                FileUtils.FileDelete(file);
                if (token != null && token.IsCancellationRequested)
                {
                    return;
                }

                if (progress != null)
                {
                    progress.ChildCurrent         = progress.ChildTotal;
                    progress.ChildCurrentProgress = string.Format("Finishing up");
                    reporter?.Report(progress);
                }
            }


            foreach (string folder in FoldersToGetFilesFrom)
            {
                string folderPath = Path.Combine(ApplicationConstants.RelhaxTempFolderPath, folder);
                if (Directory.Exists(folderPath))
                {
                    FileUtils.DirectoryDelete(folderPath, true, true);
                }

                if (token != null && token.IsCancellationRequested)
                {
                    return;
                }
            }
        }