private static FilterContentDataModel GetFilterContent(IniData iniData, string filter) { FilterContentDataModel output = new FilterContentDataModel { FilterName = filter }; var filterUrl = iniData[filter].GetKeyData("download_url").Value; using (var wc = new WebClient()) { try { output.Content = wc.DownloadString(new Uri(filterUrl)); if (wc.ResponseHeaders != null) { output.ETag = wc.ResponseHeaders["ETag"] ?? ""; output.ContentLength = wc.ResponseHeaders["content-length"] ?? ""; output.HttpStatusCode = HttpStatusCode.OK; // Can't really get this but if no exception occurs then it should be OK } } catch (Exception exception) { var test = exception.GetBaseException(); output.HttpStatusCode = ((HttpWebResponse)((WebException)test).Response).StatusCode; } } return(output); }
public static async Task <List <FilterContentDataModel> > RunGetFilterContentInParallelAsync( IProgress <ProgressReportModel> progress, IniData iniData, string poDInstallLocation, List <string> wantedFilters) { List <FilterContentDataModel> output = new List <FilterContentDataModel>(); ProgressReportModel report = new ProgressReportModel(); await Task.Run(() => { Parallel.ForEach(wantedFilters, (filter) => { FilterContentDataModel results = GetFilterContent(iniData, filter); output.Add(results); report.PercentageComplete = (output.Count * 100) / wantedFilters.Count; progress.Report(report); }); }); return(output); }