Exemplo n.º 1
0
        private void TestConnection_Click(object sender, EventArgs e)
        {
            if (ValidateForm())
            {
                bool retry = true;
                while (retry)
                {
                    retry = false;

                    Cursor c = this.Cursor;
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;
                        SaveSettings();

                        bool existingBackup = false;

                        Dictionary<string, string> options = new Dictionary<string, string>();
                        string hostname = GetConfiguration(m_options, options);
                        using (XervBackup.Library.Modules.Builtin.HttpOptions httpconf = new XervBackup.Library.Modules.Builtin.HttpOptions())
                        {
                            httpconf.Configure(options);
                            using(FTP f = new FTP(hostname, options))
                                foreach (Interface.IFileEntry n in f.List())
                                    if (n.Name.StartsWith("XervBackup-"))
                                    {
                                        existingBackup = true;
                                        break;
                                    }
                        }

                        bool isUiAdd = string.IsNullOrEmpty(m_uiAction) || string.Equals(m_uiAction, "add", StringComparison.InvariantCultureIgnoreCase);
                        if (existingBackup && isUiAdd)
                        {
                            if (MessageBox.Show(this, string.Format(Interface.CommonStrings.ExistingBackupDetectedQuestion), Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3) != DialogResult.Yes)
                                return;
                        }
                        else
                        {
                            MessageBox.Show(this, Interface.CommonStrings.ConnectionSuccess, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        m_hasTested = true;
                    }
                    catch (Interface.FolderMissingException)
                    {
                        switch (MessageBox.Show(this, Strings.FTPUI.CreateMissingFolderQuestion, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                        {
                            case DialogResult.Yes:
                                CreateFolderButton.PerformClick();
                                TestConnection.PerformClick();
                                return;
                            default:
                                return;
                        }
                    }
                    catch (Utility.SslCertificateValidator.InvalidCertificateException cex)
                    {
                        if (string.IsNullOrEmpty(cex.Certificate))
                            MessageBox.Show(this, string.Format(Interface.CommonStrings.ConnectionFailure, cex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        else
                        {
                            if (MessageBox.Show(this, string.Format(Strings.FTPUI.ApproveCertificateHashQuestion, cex.SslError), Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                            {
                                retry = true;
                                AcceptSpecifiedHash.Checked = true;
                                SpecifiedHash.Text = cex.Certificate;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, string.Format(Interface.CommonStrings.ConnectionFailure, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        this.Cursor = c;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void CreateFolderButton_Click(object sender, EventArgs e)
        {
            if (ValidateForm())
            {
                bool retry = true;
                while (retry)
                {
                    retry = false;
                    Cursor c = this.Cursor;
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;
                        SaveSettings();

                        Dictionary<string, string> options = new Dictionary<string, string>();
                        string hostname = GetConfiguration(m_options, options);
                        using (XervBackup.Library.Modules.Builtin.HttpOptions httpconf = new XervBackup.Library.Modules.Builtin.HttpOptions())
                        {
                            httpconf.Configure(options);
                            FTP f = new FTP(hostname, options);
                            f.CreateFolder();
                        }

                        MessageBox.Show(this, Interface.CommonStrings.FolderCreated, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }
                    catch (Utility.SslCertificateValidator.InvalidCertificateException cex)
                    {
                        if (string.IsNullOrEmpty(cex.Certificate))
                            MessageBox.Show(this, string.Format(Interface.CommonStrings.ConnectionFailure, cex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        else
                        {
                            if (MessageBox.Show(this, string.Format(Strings.FTPUI.ApproveCertificateHashQuestion, cex.SslError), Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                            {
                                retry = true;
                                AcceptSpecifiedHash.Checked = true;
                                SpecifiedHash.Text = cex.Certificate;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, string.Format(Interface.CommonStrings.ConnectionFailure, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        this.Cursor = c;
                    }
                }
            }
        }