public async Task <CacheProgramResults> ExecuteAsync(string username, string password, CancellationToken cancellationToken) { var sb = new StringBuilder(); sb.Append($"--userName {username} "); sb.Append($"--userPassword {password} "); sb.Append($"--resultsFilePath {ResultsFilePath.EncloseQuotes()} "); sb.Append($"--cacheStorageType {Convert.ToInt32(CacheStorageType, CultureInfo.InvariantCulture)} "); string arguments = sb.ToString(); var processUtils = new ProcessUtils(); try { var processRunResults = await processUtils.RunProcessAsync(ExecutablePath, arguments, cancellationToken).ConfigureAwait(false); return(CacheProgramResults.CreateFromResultsFile(ResultsFilePath, processRunResults)); } catch (ProcessRunException ex) { return(CacheProgramResults.CreateWithFailedExecution(ex)); } }
private void ValidateResultsFilePathForMapping(PluginProfileErrorCollection errors, bool checkFileExists = true) { if (string.IsNullOrEmpty(ResultsFilePath) || string.IsNullOrEmpty(ResultsFilePath.Trim())) { errors.Add(new PluginProfileError { FieldName = "ResultsFilePath", Message = "Test result XML file path should be specified" }); } else { try { ResultsFilePath = ResultsFilePath.Trim(); var request = WebRequest.Create(new Uri(ResultsFilePath)); if (request is FileWebRequest) { var path = request.RequestUri.LocalPath; var fileInfo = new FileInfo(path); if (checkFileExists && !fileInfo.Exists) { errors.Add(new PluginProfileError { FieldName = "ResultsFilePath", Message = string.Format("File \"{0}\" does not exist", path) }); } } else if (request is HttpWebRequest) { if (checkFileExists) { request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); var response = (HttpWebResponse)request.GetResponse(); response.Close(); } } else if (request is FtpWebRequest) { if (checkFileExists) { var ftpWebRequest = (FtpWebRequest)request; ftpWebRequest.UsePassive = PassiveMode; request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); var response = (FtpWebResponse)request.GetResponse(); response.Close(); } } else { errors.Add(new PluginProfileError { FieldName = "ResultsFilePath", Message = string.Format("Unsupported resource \"{0}\"", request.RequestUri) }); } } catch (Exception ex) { errors.Add(new PluginProfileError { FieldName = "ResultsFilePath", Message = ex.Message }); } } }