Esempio n. 1
0
        /// <summary>
        /// Handles the Click event of the btnCreate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnCreate_Click(object sender, EventArgs e)
        {
            // Confirm
            const string confirmMsg = "Are you sure you with to modify this server with the new values?";

            if (MessageBox.Show(confirmMsg, "Modify server?", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            try
            {
                var type         = (FileUploaderType)cmbType.SelectedItem;
                var host         = txtHost.Text;
                var user         = txtUser.Text;
                var pass         = txtPassword.Text;
                var downloadType = (DownloadSourceType)cmbDownloadType.SelectedItem;
                var downloadHost = txtDownloadHost.Text;

                if (string.IsNullOrEmpty(host))
                {
                    MessageBox.Show("Please enter a valid host.", "Invalid value", MessageBoxButtons.OK);
                    txtHost.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(downloadHost))
                {
                    MessageBox.Show("Please enter a valid download host.", "Invalid value", MessageBoxButtons.OK);
                    txtDownloadHost.Focus();
                    return;
                }

                if (!Enum.IsDefined(typeof(FileUploaderType), type))
                {
                    const string errmsg =
                        "Invalid FileUploaderType type ({0}) supplied - not a known enum value. Please select a valid type.";
                    cmbType.SelectedIndex = 0;
                    throw new InvalidEnumArgumentException(string.Format(errmsg, type));
                }

                if (!Enum.IsDefined(typeof(DownloadSourceType), downloadType))
                {
                    const string errmsg =
                        "Invalid DownloadSourceType type ({0}) supplied - not a known enum value. Please select a valid type.";
                    cmbDownloadType.SelectedIndex = 0;
                    throw new InvalidEnumArgumentException(string.Format(errmsg, downloadType));
                }

                // Update
                _server.ChangeInfo(host, user, pass, type, downloadType, downloadHost);
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to modify the server. Reason: {0}";
                MessageBox.Show(string.Format(errmsg, ex));
                return;
            }

            MessageBox.Show("Server successfully modified!", "Success!", MessageBoxButtons.OK);
            Close();
        }