/// <summary>
        /// Parses the output of the script when executed in DryRun mode and finds out Primary and Legacy urls.
        /// </summary>
        /// <param name="output">Output of the script execution in DryRun mode</param>
        /// <returns>Object containing primary and legacy runs</returns>
        public static ScriptDryRunResult ParseDryRunOutput(string?output)
        {
            string primaryUrlIdentifier = "Primary named payload URL: ";
            string legacyUrlIdentifier  = "Legacy named payload URL: ";

            ScriptDryRunResult result = new ScriptDryRunResult();

            using StringStream stringStream = new StringStream(output);
            using StreamReader streamReader = new StreamReader(stringStream);

            string?line;

            while ((line = streamReader.ReadLine()) != null)
            {
                // Does this line contain the primary url?
                int primaryIdIndex = line.IndexOf(primaryUrlIdentifier);
                if (primaryIdIndex != -1)
                {
                    result.PrimaryUrl = line.Substring(primaryIdIndex + primaryUrlIdentifier.Length);
                }
                else
                {
                    // Does this line contain the legacy url?
                    int legacyIdIndex = line.IndexOf(legacyUrlIdentifier);
                    if (legacyIdIndex != -1)
                    {
                        result.LegacyUrl = line.Substring(legacyIdIndex + legacyUrlIdentifier.Length);
                    }
                }
            }

            return(result);
        }
        /// <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 commandLineArgs = $"-DryRun {additionalCmdArgs}";

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

            // Execute the script;
            ScriptExecutionResult results = await InstallScriptRunner.ExecuteInstallScriptAsync(commandLineArgs).ConfigureAwait(false);

            string scriptName = results.ScriptName;

            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 = InstallScriptRunner.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);
        }