private void butLogin_Click(object sender, EventArgs e) { var but = (Button)sender; but.Enabled = false; Task.Run(() => { ScrapeClient tempClient = null; if (ScrapeClient.TryCreateInstance(txtUsername.Text, txtPassword.Text, ref tempClient)) { but.Invoke(new Action(() => { this.client = tempClient; this.Close(); })); } else { but.Invoke(new Action(() => { but.Enabled = true; MessageBox.Show("Login failed."); txtPassword.Text = ""; })); } }); }
/// <summary> /// Creates and attempts to log in a new ScrapeClient with the given credentials. /// </summary> /// <param name="username">The username to log in with.</param> /// <param name="password">The password to log in with.</param> /// <returns>Returns null if login fails.</returns> public static ScrapeClient CreateInstance(string username, string password) { var client = new ScrapeClient(username, password); if(!client.Login()) { return null; } return client; }
/// <summary> /// Creates and attempts to log in a new ScrapeClient with the given credentials. /// </summary> /// <param name="username">The username to log in with.</param> /// <param name="password">The password to log in with.</param> /// <returns>Returns null if login fails.</returns> public static ScrapeClient CreateInstance(string username, string password) { var client = new ScrapeClient(username, password); if (!client.Login()) { return(null); } return(client); }
/// <summary> /// Creates and attempts to log in a new ScrapeClient with the given credentials. /// </summary> /// <param name="username">The username to log in with.</param> /// <param name="password">The password to log in with.</param> /// <param name="client">The output ScrapeClient. Will not be set if failed.</param> /// <returns>Returns true if login successful, false if failed.</returns> public static bool TryCreateInstance(string username, string password, ref ScrapeClient client) { var newClient = CreateInstance(username, password); if(newClient == null) { return false; } else { client = newClient; return true; } }
/// <summary> /// Creates and attempts to log in a new ScrapeClient with the given credentials. /// </summary> /// <param name="username">The username to log in with.</param> /// <param name="password">The password to log in with.</param> /// <param name="client">The output ScrapeClient. Will not be set if failed.</param> /// <returns>Returns true if login successful, false if failed.</returns> public static bool TryCreateInstance(string username, string password, ref ScrapeClient client) { var newClient = CreateInstance(username, password); if (newClient == null) { return(false); } else { client = newClient; return(true); } }
private void DoLogin() { var login = new Login(); DialogResult res = login.ShowDialog(this); this.client = login.Client; }