Пример #1
0
        /// <summary>
        /// Executes the Ps1 script with DryDun switch,
        /// Parses the output to acquire primary and legacy Urls,
        /// Tests the primary Url to see if it is available,
        /// Reports the results to the data service provided.
        /// </summary>
        internal static async Task ExecuteDryRunCheckAndReportUrlAccessAsync(ILogger log, string monitorName, string additionalCmdArgs,
                                                                             CancellationToken cancellationToken = default)
        {
            string scriptName      = "dotnet-install.ps1";
            string commandLineArgs = $"-DryRun {additionalCmdArgs}";

            using IDataService dataService = new DataServiceFactory().GetDataService();

            // Execute the script;
            ScriptExecutionResult results = await HelperMethods.ExecuteInstallScriptPs1Async(commandLineArgs).ConfigureAwait(false);

            log.LogInformation($"Ouput stream: {results.Output}");

            if (!string.IsNullOrWhiteSpace(results.Error))
            {
                log.LogError($"Error stream: {results.Error}");
                await dataService.ReportScriptExecutionAsync(monitorName, scriptName, commandLineArgs, results.Error, cancellationToken)
                .ConfigureAwait(false);

                return;
            }

            // Parse the output
            ScriptDryRunResult dryRunResults = ParseDryRunOutput(results.Output);

            if (string.IsNullOrWhiteSpace(dryRunResults.PrimaryUrl))
            {
                log.LogError($"Primary Url was not found for channel {additionalCmdArgs}");
                await dataService.ReportScriptExecutionAsync(monitorName, scriptName, commandLineArgs,
                                                             "Failed to parse primary url from the following DryRun execution output: " + results.Output
                                                             , cancellationToken).ConfigureAwait(false);

                return;
            }

            // Validate URL accessibility
            await HelperMethods.CheckAndReportUrlAccessAsync(log, monitorName, dryRunResults.PrimaryUrl, dataService);
        }