コード例 #1
0
        /// <summary>
        /// used by the run fuction to run the tests
        /// </summary>
        /// <param name="runner"></param>
        /// <param name="resultsFile"></param>
        private void RunTests(IAssetRunner runner, string resultsFile)
        {
            try
            {
                if (_ciRun)
                {
                    _xmlBuilder         = new JunitXmlBuilder();
                    _xmlBuilder.XmlName = resultsFile;
                }

                TestSuiteRunResults results = runner.Run();

                if (results == null)
                {
                    Environment.Exit((int)Launcher.ExitCodeEnum.Failed);
                }

                _xmlBuilder.CreateXmlFromRunResults(results);

                //if there is an error
                if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error))
                {
                    Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
                }

                //this is the total run summary
                ConsoleWriter.ActiveTestRun = null;
                string runStatus   = (Launcher.ExitCode == ExitCodeEnum.Passed || Launcher.ExitCode == ExitCodeEnum.Unstable) ? "Job succeeded" : "Job failed";
                int    numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed);
                int    numSuccess  = results.TestRuns.Count(t => t.TestState == TestState.Passed);
                int    numErrors   = results.TestRuns.Count(t => t.TestState == TestState.Error);
                ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator);
                ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors));

                if (!runner.RunWasCancelled)
                {
                    results.TestRuns.ForEach(tr => ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath));

                    ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator);
                    if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0)
                    {
                        ConsoleWriter.WriteLine("Job Errors summary:");
                        ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line));
                    }
                }

                //ConsoleWriter.WriteLine("Returning " + runStatus + ".");
            }
            finally
            {
                try
                {
                    runner.Dispose();
                }
                catch (Exception ex)
                {
                    ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message));
                };
            }
        }
コード例 #2
0
 private static void ExitApplication(string message, ExitCodeEnum exitCode)
 {
     Console.WriteLine(message);
     Console.Write("Press any key to close this window...");
     Console.ReadKey(true);
     Environment.Exit((int)exitCode);
 }
コード例 #3
0
 /// <summary>
 /// Sets the reason for exiting
 /// </summary>
 /// <param name="Reason">The Enum value of the reason to set</param>
 /// <returns>
 /// Returns true if a new reason has be set; Otherwise false.
 /// </returns>
 /// <remarks>
 /// Will only set <paramref name="Reason"/> if the current <see cref="WriterBase.ExitReason"/> is not set.
 /// </remarks>
 protected bool SetExitReason(ExitCodeEnum Reason)
 {
     if (this.ExitReason == ExitCodeEnum.NotSet || this.ExitReason == ExitCodeEnum.NoError)
     {
         this.ExitReason = Reason;
         return(true);
     }
     return(false);
 }
コード例 #4
0
        /// <summary>
        /// used by the run fuction to run the tests
        /// </summary>
        /// <param name="runner"></param>
        /// <param name="resultsFile"></param>
        private void RunTests(IAssetRunner runner, string resultsFile)
        {
            try
            {
                if (_ciRun)
                {
                    _xmlBuilder         = new JunitXmlBuilder();
                    _xmlBuilder.XmlName = resultsFile;
                }

                TestSuiteRunResults results = runner.Run();

                if (results == null)
                {
                    Environment.Exit((int)Launcher.ExitCodeEnum.Failed);
                }

                _xmlBuilder.CreateXmlFromRunResults(results);

                //if there is an error
                if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error))
                {
                    Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
                }

                int numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed);
                int numSuccess  = results.TestRuns.Count(t => t.TestState == TestState.Passed);
                int numErrors   = results.TestRuns.Count(t => t.TestState == TestState.Error);

                //TODO: Temporery fix to remove since jenkins doesnt retrive resutls from jobs that marked as failed and unstable marks jobs with only failed tests
                if ((numErrors <= 0) && (numFailures > 0))
                {
                    Launcher.ExitCode = Launcher.ExitCodeEnum.Unstable;
                }

                foreach (var testRun in results.TestRuns)
                {
                    if (testRun.FatalErrors > 0 && !testRun.TestPath.Equals(""))
                    {
                        Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
                        break;
                    }
                }

                //this is the total run summary
                ConsoleWriter.ActiveTestRun = null;
                string runStatus = "";
                switch (Launcher.ExitCode)
                {
                case ExitCodeEnum.Passed:
                    runStatus = "Job succeeded";
                    break;

                case ExitCodeEnum.Unstable:
                    runStatus = "Job unstable (Passed with failed tests)";
                    break;

                case ExitCodeEnum.Aborted:
                    runStatus = "Job failed due to being Aborted";
                    break;

                case ExitCodeEnum.Failed:
                    runStatus = "Job failed";
                    break;

                default:
                    runStatus = "Error: Job status is Undefined";
                    break;
                }

                ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator);
                ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors));

                if (!runner.RunWasCancelled)
                {
                    results.TestRuns.ForEach(tr => ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath));

                    ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator);
                    if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0)
                    {
                        ConsoleWriter.WriteLine("Job Errors summary:");
                        ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line));
                    }
                }

                //ConsoleWriter.WriteLine("Returning " + runStatus + ".");
            }
            finally
            {
                try
                {
                    runner.Dispose();
                }
                catch (Exception ex)
                {
                    ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message));
                };
            }
        }
コード例 #5
0
        private void RunTests(IAssetRunner runner, string resultsFile, TestSuiteRunResults results)
        {
            try
            {
                if (_ciRun)
                {
                    _xmlBuilder         = new JunitXmlBuilder();
                    _xmlBuilder.XmlName = resultsFile;
                }

                if (results == null)
                {
                    Environment.Exit((int)Launcher.ExitCodeEnum.Failed);
                }

                _xmlBuilder.CreateXmlFromRunResults(results);

                if (results.TestRuns.Count == 0)
                {
                    Console.WriteLine("No tests were run");
                    Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
                    Environment.Exit((int)Launcher.ExitCode);
                }

                //if there is an error
                if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error))
                {
                    Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
                }

                int numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed);
                int numSuccess  = results.TestRuns.Count(t => t.TestState == TestState.Passed);
                int numErrors   = results.TestRuns.Count(t => t.TestState == TestState.Error);
                int numWarnings = results.TestRuns.Count(t => t.TestState == TestState.Warning);

                if ((numErrors <= 0) && (numFailures > 0))
                {
                    Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
                }

                if ((numErrors <= 0) && (numFailures > 0) && (numSuccess > 0))
                {
                    Launcher.ExitCode = Launcher.ExitCodeEnum.Unstable;
                }

                foreach (var testRun in results.TestRuns)
                {
                    if (testRun.FatalErrors > 0 && !testRun.TestPath.Equals(""))
                    {
                        Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
                        break;
                    }
                }

                //this is the total run summary
                ConsoleWriter.ActiveTestRun = null;
                string runStatus = "";

                switch (Launcher.ExitCode)
                {
                case ExitCodeEnum.Passed:
                    runStatus = "Job succeeded";
                    break;

                case ExitCodeEnum.Unstable:
                    runStatus = "Job unstable (Passed with failed tests)";
                    break;

                case ExitCodeEnum.Aborted:
                    runStatus = "Job failed due to being Aborted";
                    break;

                case ExitCodeEnum.Failed:
                    runStatus = "Job failed";
                    break;

                default:
                    runStatus = "Error: Job status is Undefined";
                    break;
                }

                ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator);
                ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors, numWarnings));

                int testIndex = 1;
                if (!runner.RunWasCancelled)
                {
                    results.TestRuns.ForEach(tr => { ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath + "[" + testIndex + "]"); testIndex++; });

                    ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator);

                    if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0)
                    {
                        ConsoleWriter.WriteLine("Job Errors summary:");
                        ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line));
                    }

                    string onCheckFailedTests = (_ciParams.ContainsKey("onCheckFailedTest") ? _ciParams["onCheckFailedTest"] : "");

                    _rerunFailedTests = !string.IsNullOrEmpty(onCheckFailedTests) && Convert.ToBoolean(onCheckFailedTests.ToLower());

                    if (!_rerunFailedTests)
                    {
                        Environment.Exit((int)Launcher.ExitCode);
                    }
                }
            }
            finally
            {
                try
                {
                    runner.Dispose();
                }
                catch (Exception ex)
                {
                    ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message));
                };
            }
        }
コード例 #6
0
 /// <summary>
 /// Terminates application with specified exit code.
 /// </summary>
 /// <param name="exitCode">The exit code.</param>
 private static void Exit(ExitCodeEnum exitCode = ExitCodeEnum.Success)
 {
     ConsoleHelper.RestoreDefaultColor();
     Environment.Exit((int)exitCode);
 }
コード例 #7
0
        /// <summary>
        /// The entry point.
        /// </summary>
        /// <param name="parameters"></param>
        private static void RunMain(CommandLineArguments parameters)
        {
            InitialRun(parameters);

            if (!parameters.DoNotClone)
            {
                CheckFreeSpace(parameters.Repo, parameters.Out);
            }

            string clonedRepoPath = Path.Combine(parameters.Out, ".git");

            if (!parameters.DoNotClone)
            {
                clonedRepoPath = CloneRepository(parameters.Repo, parameters.Out);
            }

            string enClonedRepoPath = null;

            if (!String.IsNullOrEmpty(parameters.EnOut))
            {
                enClonedRepoPath = Path.Combine(parameters.EnOut, ".git");
                if (!String.IsNullOrEmpty(parameters.EnRepo))
                {
                    enClonedRepoPath = CloneRepository(parameters.EnRepo, parameters.EnOut);
                }
            }

            if (!RepoHelper.TryToCheckClonedRepo(parameters.Out, parameters.Json, out string pathToDocFxJson))
            {
                Logger.LogError($"{Error}: File {pathToDocFxJson} does not exist");
                Exit(ExitCodeEnum.InvalidRepo);
            }

            string pathToEnDocFxJson = null;

            if (enClonedRepoPath != null && !RepoHelper.TryToCheckClonedRepo(parameters.EnOut, parameters.Json, out pathToEnDocFxJson))
            {
                Logger.LogError($"{Error}: File {pathToEnDocFxJson} does not exist in en-US repository");
                Exit(ExitCodeEnum.InvalidRepo);
            }

            string repoLocalRoot     = Path.GetDirectoryName(pathToDocFxJson);
            string repoEnUsLocalRoot = Path.GetDirectoryName(pathToEnDocFxJson);

            if (!DocFxJsonHelper.IsDocFxJsonCorrect(pathToDocFxJson))
            {
                Logger.LogError(DocFxJsonIncorrect);
                Exit(ExitCodeEnum.InvalidRepo);
            }

            FilesCollector filesCollector = new FilesCollector(Logger);

            Logger.LogInfo("Collecting files, it may take awhile...");
            string[] files = filesCollector.FindAllFiles(repoLocalRoot, "*.md|*.yml", (fname, count) =>
            {
                Console.SetCursorPosition(0, Console.CursorTop);
                Console.CursorVisible = false;
                string file           = Path.GetFileName(fname);
                if (file != null && file.Length > 30)
                {
                    file = file.Substring(file.Length - 30, 30);
                }
                Console.Write($@"Found {count} files: {file}");
            });
            Console.SetCursorPosition(0, Console.CursorTop);
            Console.Write(new char[80]);
            Console.SetCursorPosition(0, Console.CursorTop);
            Logger.LogInfo($"Found {files.Length} files.");

            Console.WriteLine(@"Normalizing files...");
            foreach (string f in files)
            {
                string content = File.ReadAllText(f);
                content = Regex.Replace(content, "ms.contentlocale:.*", "ms.contentlocale: " + parameters.Lng);
                File.WriteAllText(f, content);
            }

            string externalText = parameters.ExternalText;

            if (!String.IsNullOrEmpty(externalText))
            {
                externalText = " " + externalText;
            }

            if (!parameters.ReplaceUrl.EndsWith("/"))
            {
                parameters.ReplaceUrl = $"{parameters.ReplaceUrl}/";
            }

            string baseEnUsUrl  = parameters.ReplaceUrl;
            string baseWoExtUrl = null;

            if (Uri.TryCreate(parameters.ReplaceUrl, UriKind.Absolute, out var uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))
            {
                baseWoExtUrl = $"{uriResult.Scheme}://{uriResult.Host}";
            }

            foreach (string f in files)
            {
                string            content    = File.ReadAllText(f);
                StringBuilder     newContent = new StringBuilder();
                LinkProcessorBase proc       = new ConceptualLinkProcessor(Logger, repoLocalRoot, parameters.ReplaceUrl, baseEnUsUrl, baseWoExtUrl, externalText, repoLocalRoot != null ? f.Replace(repoLocalRoot, "").TrimStart('\\') : "", repoEnUsLocalRoot, content, newContent);
                bool hasModified             = proc.ProcessContentLinks();
                if (hasModified)
                {
                    File.WriteAllText(f, newContent.ToString());
                }

                AppendTextLog(LogType.NotExistingFiles, proc.GetLogContent(LogType.NotExistingFiles));
                AppendTextLog(LogType.NormalFiles, proc.GetLogContent(LogType.NormalFiles));
                AppendTextLog(LogType.CopiedFiles, proc.GetLogContent(LogType.CopiedFiles));
                AppendTextLog(LogType.ReplacedLinks, proc.GetLogContent(LogType.ReplacedLinks));
                AppendTextLog(LogType.ReplacedEnUsLinks, proc.GetLogContent(LogType.ReplacedEnUsLinks));
                AppendRemovedFiles(proc.GetFilesToRemove());
                AppendIgnoredFiles(proc.GetFilesToIgnore());

                if (proc.GetCopiedFiles().Length > 0)
                {
                    ProcessCopiedFiles(repoLocalRoot, parameters.ReplaceUrl, baseEnUsUrl, baseWoExtUrl, externalText, repoEnUsLocalRoot, proc.GetCopiedFiles());
                }
            }

            LogFiles logFiles = new LogFiles(parameters.LogsDir);

            StringBuilder sb = new StringBuilder();

            foreach (string file in LRemovedFiles)
            {
                if (!LIgnoredFiles.Contains(file))
                {
                    sb.AppendLine(file);
                    string path = Path.Combine(repoLocalRoot, file);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            }
            WriteLog(sb.ToString(), logFiles.RemovedFilesLog, "The files which have been removed");

            StringBuilder sbIgnored = new StringBuilder();

            foreach (string file in LIgnoredFiles)
            {
                sbIgnored.AppendLine(file);
            }

            WriteLog(SbNormalFiles.ToString(), logFiles.NormalFilesLog, "The normal files");
            WriteLog(SbNotExistingFiles.ToString(), logFiles.NotExistentFilesLog, "Not Existing Link;Source File");
            WriteLog(SbCopiedFiles.ToString(), logFiles.CopiedFilesLog, "The files which have been copied from en-US repository");
            WriteLog(SbReplacedLinks.ToString(), logFiles.ReplacedLinksLog, "Source file,Link,Title,New Link,New Title");
            WriteLog(SbReplacedEnUsLinks.ToString(), logFiles.ReplacedLanguageLinksLog, "Source file,Link,Title,New Link,New Title");
            //WriteLog(sbIgnored.ToString(), "logs\\ignored files.txt", "The ignored files");

            string tempDocFxZipFile = SaveToTempFile(Properties.Resources.docfx, DocFxZip);
            string tempDocFxDir     = ExtractZip(tempDocFxZipFile, DocFxZip);

            CopyCustomPlugin(pathToDocFxJson);
            string pathToTemplateZip = SaveToTempFile(Properties.Resources.mstemplate, MsTemplateZip);
            string templateTempDir   = ExtractZip(pathToTemplateZip, MsTemplateZip);

            UtilityHelper.CopyDirectory(templateTempDir, Path.GetDirectoryName(pathToDocFxJson));

            if (String.IsNullOrEmpty(parameters.Lng))
            {
                parameters.Lng = "en-us";
            }
            Logger.LogInfo($"Setting language {parameters.Lng} for template...", false);
            SetLanguage(parameters.Lng, Path.GetDirectoryName(pathToDocFxJson));
            Logger.LogInfo(Completed);
            DocFxJsonHelper.ModifyDocfxJson(pathToDocFxJson, CustomPluginName, parameters.Rtl);

            string       docfxexe      = Path.Combine(tempDocFxDir, DocFxExe);
            int          exitCodeDocFx = RunDocFx(docfxexe, pathToDocFxJson);
            ExitCodeEnum exitCode      = ExitCodeEnum.Success;

            if (exitCodeDocFx != 0)
            {
                exitCode = ExitCodeEnum.DocFxError;
                Logger.LogError($"{Error}: exit code {exitCode}");
            }

            DocFxJsonHelper.RevertDocfxJson(pathToDocFxJson, CustomPluginName);
            RepoHelper.CleanRepo(parameters.RemoveGitFolder ? clonedRepoPath : null, pathToDocFxJson);
            string docfxDir = Path.GetDirectoryName(pathToDocFxJson);

            RemoveTemp(new[]
            {
                tempDocFxDir, tempDocFxZipFile, pathToTemplateZip, templateTempDir,
                (docfxDir != null ? Path.Combine(docfxDir, CustomPluginName) : null)
            });

            string consoleOutput = Logger.GetLogContent();

            File.WriteAllText(logFiles.ConsoleLog, consoleOutput);
            Exit(exitCode);
        }
コード例 #8
0
        /// <summary>
        /// used by the run fuction to run the tests
        /// </summary>
        /// <param name="runner"></param>
        /// <param name="resultsFile"></param>
        private void RunTests(IAssetRunner runner, string resultsFile)
        {
            try
            {
                if (_ciRun)
                {
                    _xmlBuilder = new JunitXmlBuilder();
                    _xmlBuilder.XmlName = resultsFile;
                }

                TestSuiteRunResults results = runner.Run();

                if (results == null)
                    Environment.Exit((int)Launcher.ExitCodeEnum.Failed);

                _xmlBuilder.CreateXmlFromRunResults(results);

                //if there is an error
                if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error))
                {
                    Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
                }

                //this is the total run summary
                ConsoleWriter.ActiveTestRun = null;
                string runStatus = (Launcher.ExitCode == ExitCodeEnum.Passed || Launcher.ExitCode == ExitCodeEnum.Unstable) ? "Job succeeded" : "Job failed";
                int numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed);
                int numSuccess = results.TestRuns.Count(t => t.TestState == TestState.Passed);
                int numErrors = results.TestRuns.Count(t => t.TestState == TestState.Error);
                ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator);
                ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors));

                if (!runner.RunWasCancelled)
                {
                    results.TestRuns.ForEach(tr => ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath));
                    
                    ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator);
                    if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0)
                    {
                        ConsoleWriter.WriteLine("Job Errors summary:");
                        ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line));
                    }
                }

                //ConsoleWriter.WriteLine("Returning " + runStatus + ".");
            }
            finally
            {
                try
                {
                    runner.Dispose();
                }
                catch (Exception ex)
                {
                    ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message));
                };
            }

        }