Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        public static void Default_1_GetWebProxy()
        {
            var webProxyFactory = WebProxyFactory.GetInstance();

            Assert.NotNull(webProxyFactory);
            var webProxy = webProxyFactory.GetWebProxy();

            Assert.NotNull(webProxy);
        }
Ejemplo n.º 3
0
        public void Default_2_GetWebProxyStatus()
        {
            var webProxyFactory = WebProxyFactory.GetInstance();

            Assert.NotNull(webProxyFactory);
            var webProxy = webProxyFactory.GetWebProxy();

            Assert.NotNull(webProxy);
            var webProxyStatus = webProxyFactory.GetWebProxyStatus(webProxy);

            Assert.True(webProxyStatus != WebProxyFactory.WebProxyStatus.Unknown);
            _output.WriteLine("WebProxyStatus: " + webProxyStatus);
        }
        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));
            }
        }
Ejemplo n.º 5
0
        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);
        }