private void Button_Click(object sender, RoutedEventArgs e) { if (this.ConnectButton.Content.ToString() == "Disconnect") { this.ConnectButton.IsEnabled = false; System.Threading.Tasks.Task.Run(() => disconnectingTask()); return; } if (string.IsNullOrEmpty(this.ApiKey.Text) || string.IsNullOrEmpty(this.ApiSecret.Password)) { MessageBox.Show("Please enter valid ApiKey and ApiSecret to continue", "Error", MessageBoxButton.OK, MessageBoxImage.Information); return; } this.ConnectButton.IsEnabled = false; confBtn.IsEnabled = false; ErrorStatus.STATUS = "Connecting..."; BittrexBridge bridge = new BittrexBridge(this.ApiKey.Text.Replace(" ", String.Empty), this.ApiSecret.Password.Replace(" ", String.Empty)); this.ApiSecret.Password = string.Empty; this.ApiKey.IsEnabled = false; this.ApiSecret.IsEnabled = false; Manager = new OrderManager(bridge, ErrorStatus, (int)Properties.Settings.Default["age"], (int)Properties.Settings.Default["frecuency"]); GUIupdater = new Task(new Action(UpdateGUI)); GUIupdater.Start(); this.ConnectButton.Content = "Disconnect"; this.ConnectButton.IsEnabled = true; }
private async void AddButton_Click(object sender, EventArgs e) { UserStatusLabel.Visible = false; if (String.IsNullOrWhiteSpace(UserBox.Text) || String.IsNullOrWhiteSpace(ApiBox.Text) || String.IsNullOrWhiteSpace(SecretBox.Text) || String.IsNullOrWhiteSpace(PassBox1.Text) || String.IsNullOrWhiteSpace(PassBox2.Text)) { UserStatusLabel.Text = "Error: empty paramether"; UserStatusLabel.ForeColor = Color.Red; UserStatusLabel.Visible = true; return; } if (!(PassBox1.Text == PassBox2.Text)) { PassBox1.Text = String.Empty; PassBox2.Text = String.Empty; UserStatusLabel.Text = "Error: Passwords don't match"; UserStatusLabel.ForeColor = Color.Red; UserStatusLabel.Visible = true; return; } if (PassBox1.Text.Length < 6) { UserStatusLabel.Text = "Error: Password must be at least 6 char long"; UserStatusLabel.ForeColor = Color.Red; UserStatusLabel.Visible = true; return; } if (!System.Text.RegularExpressions.Regex.IsMatch(UserBox.Text, @"^[a-zA-Z0-9_]+$")) { UserStatusLabel.Text = "Error: Only {a-z,0-9,_} allowed in username"; UserStatusLabel.ForeColor = Color.Red; UserStatusLabel.Visible = true; return; } if (ApiBox.Text.Length != 32) { UserStatusLabel.Text = "Error: Invalid ApiKey"; UserStatusLabel.ForeColor = Color.Red; UserStatusLabel.Visible = true; return; } if (SecretBox.Text.Length != 32) { UserStatusLabel.Text = "Error: Invalid ApiSecret"; UserStatusLabel.ForeColor = Color.Red; UserStatusLabel.Visible = true; return; } DisableAll(); UserStatusLabel.Text = "Testing credentials..."; UserStatusLabel.ForeColor = Color.Green; UserStatusLabel.Visible = true; bool response = await BittrexBridge.testConnection(ApiBox.Text, SecretBox.Text); if (!response) { UserStatusLabel.Text = "Error: Invalid Key and Secret Combination"; UserStatusLabel.ForeColor = Color.Red; UserStatusLabel.Visible = true; AddButton.Enabled = Deletebtn.Enabled = true; EnableAll(); return; } UserStatusLabel.Visible = false; try { _manager.AddNewUser(UserBox.Text, ApiBox.Text, SecretBox.Text, PassBox1.Text); } catch (Exception ex) { MessageBox.Show(this, ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); EnableAll(); return; } EmptyStuff(); }
private void Button_Click(object sender, EventArgs e) { if (this.ConnectButton.Text.ToString() == "Disconnect") { this.ConnectButton.Enabled = false; System.Threading.Tasks.Task.Run(() => disconnectingTask(ErrorStatus)); return; } if (!ProfileMngr.UserNames.Any()) { MessageBox.Show(this, "Please create at least one user to continue", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (UsersComboBox.SelectedIndex < 0) { MessageBox.Show(this, "Please select a user to continue", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } UsersComboBox.Enabled = false; this.ConnectButton.Enabled = false; confBtn.Enabled = false; ProfManagerButton.Enabled = false; DialogResult result = passWindow.ShowDialog(); if (result == DialogResult.Cancel || String.IsNullOrWhiteSpace(passWindow.password)) { this.ConnectButton.Enabled = true; confBtn.Enabled = true; ProfManagerButton.Enabled = true; UsersComboBox.Enabled = true; passWindow.password = String.Empty; return; } Tuple <string, string> UserData; try { var CurrentUser = ProfileMngr.GetUserData((string)UsersComboBox.SelectedItem, passWindow.password, out UserData); } catch (InvalidPasswordException) { MessageBox.Show(this, "Invalid or Incorrect password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.ConnectButton.Enabled = true; UsersComboBox.Enabled = Enabled; ProfManagerButton.Enabled = Enabled; passWindow.password = string.Empty; confBtn.Enabled = true; return; } catch (NoPasswordException) { MessageBox.Show(this, "Error in user data, please recreate it", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.ConnectButton.Enabled = true; UsersComboBox.Enabled = Enabled; ProfManagerButton.Enabled = Enabled; passWindow.password = string.Empty; confBtn.Enabled = true; return; } passWindow.password = string.Empty; ErrorStatus.STATUS = "Connecting..."; try { BittrexBridge bridge = new BittrexBridge(UserData.Item1, UserData.Item2); Manager = new OrderManager(bridge, ErrorStatus, (int)Properties.Settings.Default["age"], (int)Properties.Settings.Default["frecuency"]); } catch (Exception ex) { MessageBox.Show(this, ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } GUIupdater = new Task(() => UpdateGUI(ErrorStatus)); GUIupdater.Start(); this.ConnectButton.Text = "Disconnect"; this.ConnectButton.Enabled = true; }