示例#1
0
        private async void MainForm_Load(object sender, EventArgs e)
        {
            if (!CertificatesProcess.CheckCaCertificate())
            {
                Cursor = Cursors.WaitCursor;
                DisableAll();
                var statusLabel = new ToolStripStatusLabel("Adding server certificate to Windows Certificate Store");
                statusBar.Items.Add(statusLabel);
                try
                {
                    var certificatesStore = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
                    certificatesStore.Open(OpenFlags.ReadWrite);
                    var     tempCertificate = Path.GetTempFileName();
                    Dropbox cloud           = new Dropbox();
                    await cloud.DownloadFileAsync(tempCertificate, "cert.crt");

                    certificatesStore.Add(new X509Certificate2(tempCertificate));
                    certificatesStore.Close();
                    File.Delete(tempCertificate);
                }
                catch
                {
                }
                EnableIdentity();
                if (_connected)
                {
                    EnableGroups();
                }
                statusBar.Items.Remove(statusLabel);
                Cursor = Cursors.Arrow;
            }
        }
示例#2
0
        private async void downloadFilesButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            var statusLabel = new ToolStripStatusLabel("Downloading files");

            statusBar.Items.Add(statusLabel);
            var folderBroswerDialog = new FolderBrowserDialog();

            if (folderBroswerDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var selectedFiles = filesListBox.SelectedItems;
                    foreach (CloudFile file in selectedFiles)
                    {
                        var outputPath = string.Format("{0}\\{1}", folderBroswerDialog.SelectedPath, file.Name);
                        if (!encryptCheckBox.Checked)
                        {
                            statusLabel.Text = string.Format("Downloading {0}", file.Name);
                            await _cloud.DownloadFileAsync(outputPath, _currentUser, file.Name);
                        }
                        else
                        {
                            var tempFile = Path.GetTempFileName();
                            statusLabel.Text = string.Format("Downloading {0}", file.Name);
                            await _cloud.DownloadFileAsync(tempFile, _currentUser, file.Name);

                            statusLabel.Text = string.Format("Decrypting {0}", file.Name);
                            await Decrypt.FileWithPrivateKey(tempFile, outputPath, _certificate);
                        }
                    }
                }
                catch (CloudException cloud)
                {
                    MessageBox.Show(cloud.Message, "Cloud problem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception)
                {
                    MessageBox.Show("Unexcepted error occured. Click OK to contiune", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }

            EnableAll();
            statusBar.Items.Remove(statusLabel);
            Cursor = Cursors.Arrow;
        }