public ConnectAsync ( string name, string host, string password ) : Task |
||
name | string | |
host | string | |
password | string | |
return | Task |
public async Task<bool> ConnectAsync(string name, string host, string password)
{
bool result = false;
ServerConnection connection = null;
if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(host) && !string.IsNullOrWhiteSpace(password))
{
connection = new ServerConnection(host, name);
Task<bool> connectionTask = connection.ConnectAsync(password);
SetStatusLabel(string.Format("Attempting to connect to: {0}@{1}", name, host));
toolStripProgressBar1.ProgressBar.Style = ProgressBarStyle.Marquee;
result = await connectionTask;
}
if (result)
{
_connection = connection;
_connection.UploadProgress += (sender, e) => UpdateProgress(e);
_connection.UploadStart += (sender, e) => SetStatusLabel("Uploading file " + e.FilePath + "...");
SetStatusLabel("Loading Databases from server...");
await RefreshDatabases();
SetStatusLabel();
SetTitle(string.Format("{0}@{1}", _connection.UserName, _connection.Host));
toolStripProgressBar1.ProgressBar.Style = ProgressBarStyle.Continuous;
submitToolStripMenuItem.Enabled = true;
}
else
{
submitToolStripMenuItem.Enabled = false;
toolStripProgressBar1.ProgressBar.Style = ProgressBarStyle.Continuous;
SetStatusLabel(string.Format("Unable to Connected To: {0}@{1}", name, host));
}
return result;
}
private async void button1_Click(object sender, EventArgs e) { button1.Enabled = false; bool storeAsDefault = checkBox1.Checked; string host = textBox1.Text; string userName = textBox2.Text; string password = ServerConnection.EncryptString(ServerConnection.ToSecureString(textBox3.Text)); if (storeAsDefault) { Properties.Settings.Default.UserName = userName; Properties.Settings.Default.Host = host; Properties.Settings.Default.Password = password; Properties.Settings.Default.Save(); } bool result = await CoondornatorParentForm.ConnectAsync(userName, host, password); if (!result) { button1.Enabled = true; } else { Close(); } }