コード例 #1
0
ファイル: PromptDialog.cs プロジェクト: zellus/SharpVectors
        private void OnDownloadClicked(object sender, EventArgs e)
        {
            var dlg = new LoadingAdorner();

            dlg.Owner         = this;
            dlg.StartPosition = FormStartPosition.Manual;
            dlg.Location      = new Point(this.Location.X + (this.Width - dlg.Width) / 2,
                                          this.Location.Y + (this.Height - dlg.Height) / 2);
            dlg.Show(this);

            string url = _optionSettings.WebSuitePath;

            _downloadeFilePath = Path.Combine(_optionSettings.LocalSuitePath, "FullTestSuite.zip");
            if (File.Exists(_downloadeFilePath))
            {
                File.Delete(_downloadeFilePath);
            }

            //ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; //TLS 1.2
            //ServicePointManager.SecurityProtocol = (SecurityProtocolType)768; //TLS 1.1
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;

            using (WebClient client = new WebClient())
            {
                client.DownloadFileCompleted += delegate(object other, AsyncCompletedEventArgs args) {
                    bool result = !args.Cancelled;
                    if (!result)
                    {
                        return;
                    }
                    using (ZipFile zip = ZipFile.Read(_downloadeFilePath))
                    {
                        zip.ExtractAll(_optionSettings.LocalSuitePath);
                    }

                    dlg.Close();

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                };
                client.DownloadFileAsync(new Uri(url), _downloadeFilePath);
            }
        }
コード例 #2
0
ファイル: PromptDialog.cs プロジェクト: zellus/SharpVectors
        private async void OnDownloadClicked(object sender, EventArgs e)
        {
            var dlg = new LoadingAdorner();

            dlg.Owner         = this;
            dlg.StartPosition = FormStartPosition.Manual;
            dlg.Location      = new Point(this.Location.X + (this.Width - dlg.Width) / 2,
                                          this.Location.Y + (this.Height - dlg.Height) / 2);
            dlg.Show(this);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            string url = _optionSettings.WebSuitePath;

            _downloadeFilePath = Path.Combine(_optionSettings.LocalSuitePath, "FullTestSuite.zip");
            if (File.Exists(_downloadeFilePath))
            {
                File.Delete(_downloadeFilePath);
            }

            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
                    using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
                    {
                        using (Stream streamToWriteTo = File.Open(_downloadeFilePath, FileMode.Create))
                        {
                            await streamToReadFrom.CopyToAsync(streamToWriteTo);
                        }

                        ZipFile.ExtractToDirectory(_downloadeFilePath, _optionSettings.LocalSuitePath);

                        dlg.Close();

                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
            }
        }