Ejemplo n.º 1
0
        private async Task CheckBoxFtpChanged()
        {
            textBoxFtpPassword.Enabled            = textBoxFtpPath.Enabled = textBoxFtpUsername.Enabled =
                buttonLoadLastCredentials.Enabled = !checkBoxFtpEnabled.Checked;
            ftpStatusIndicator.BackColor          = checkBoxFtpEnabled.Checked ? Color.Yellow : Color.Red;

            if (checkBoxFtpEnabled.Checked)
            {
                checkBoxFtpEnabled.Enabled = false;
                await Task.Run(() =>
                {
                    try
                    {
                        _ftp = new Ftp(textBoxFtpUsername.Text, textBoxFtpPassword.Text, textBoxFtpPath.Text);
                        _ftp.ConnectAndCreateDirectories();
                        Settings.Write(Settings.SettingsLastFtpPathRegister, textBoxFtpPath.Text);
                        Settings.Write(Settings.SettingsLastFtpUsernameRegister, textBoxFtpUsername.Text);
                        Settings.Write(Settings.SettingsLastFtpPasswordRegister, textBoxFtpPassword.Text);
                        RunAction(() => ftpStatusIndicator.BackColor = Color.LawnGreen);
                    }
                    catch (Exception exception)
                    {
                        RunAction(() =>
                        {
                            MessageBox.Show(
                                string.Format(Resources.TimerForm_CheckBoxFtpChanged_Couldn_t_start_FTP__0_,
                                              exception.Message), Resources.TimerForm_WriteTournamentTimer_Something_went_wrong,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                            checkBoxFtpEnabled.Checked = false;
                        });
                    }
                });

                checkBoxFtpEnabled.Enabled       = true;
                uploadSupportFilesButton.Enabled = uploadTimerNowButton.Enabled = checkBoxFtpEnabled.Checked;
            }
            else
            {
                uploadSupportFilesButton.Enabled = uploadTimerNowButton.Enabled = checkBoxFtpEnabled.Checked;
                _ftp = null;
            }
        }