public ICollection <Protein> GetProteins(IProgress <ProgressInfo> progress) { var requestUri = new Uri(_preferences.Get <string>(Preference.ProjectDownloadUrl)); var webOperation = WebOperation.Create(requestUri); if (progress != null) { webOperation.ProgressChanged += (sender, e) => { int progressPercentage = Convert.ToInt32(e.Length / (double)e.TotalLength * 100); string message = $"Downloading {e.Length} of {e.TotalLength} bytes..."; progress.Report(new ProgressInfo(progressPercentage, message)); }; } webOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); webOperation.WebRequest.Proxy = WebProxyFactory.Create(_preferences); using (var stream = new MemoryStream()) { webOperation.Download(stream); stream.Position = 0; var serializer = new ProjectSummaryJsonDeserializer(); return(serializer.Deserialize(stream)); } }
public ApplicationUpdate GetApplicationUpdate(Uri requestUri) { using (var stream = new MemoryStream()) { var webOperation = WebOperation.Create(requestUri); webOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); webOperation.WebRequest.Proxy = WebProxyFactory.Create(Preferences); webOperation.Download(stream); stream.Position = 0; var serializer = new ApplicationUpdateSerializer(); return(serializer.Deserialize(stream)); } }
private bool PerformDownload() { var selectedUpdateFile = Model.SelectedUpdateFile; var uri = new Uri(selectedUpdateFile.HttpAddress); var path = Model.SelectedUpdateFileLocalFilePath; _webOperation = WebOperation.Create(uri); _webOperation.WebRequest.Proxy = WebProxyFactory.Create(Preferences); // execute the download _webOperation.Download(path); if (_webOperation.Result != WebOperationResult.Completed) { return(false); } // verify, throws exception on error selectedUpdateFile.Verify(path); return(true); }