Esempio n. 1
0
        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            if (usernameBox.Text == "" && chatbotsBox.SelectedIndex != -1 && chatbotsBox.SelectedValue.ToString() != "")
            {
                username = chatbotsBox.SelectedValue.ToString();
                if (File.Exists(username + "/login.json") && passwordBox.Password == "" && sentryFileTextBox.Text == "" &&
                    logFileTextBox.Text == "" && displaynameBox.Text == "" && consoleLLBox.SelectedItem.ToString() == "System.Windows.Controls.ListBoxItem: Verbose" &&
                    fileLLBox.SelectedItem.ToString() == "System.Windows.Controls.ListBoxItem: Verbose")
                {
                    var _data = Bot.ReadData(username);
                    logFile     = _data.logFile;
                    sentryFile  = _data.sentryFile;
                    username    = _data.username;
                    password    = _data.password;
                    displayName = _data.displayName;
                    cll         = _data.cll;
                    fll         = _data.fll;

                    if (sharedSecretBox.Text != "")
                    {
                        Bot.sharedSecret = sharedSecretBox.Text;
                    }

                    Log = Log.CreateInstance(logFile, username, (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), cll, true),
                                             (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), fll, true));

                    Log.Instance.Silly("Successfully read login data from file");
                    Close();
                    Bot.Start(username, password, cll, fll, logFile, displayName, sentryFile);
                }
            }
            else if (usernameBox.Text != "")
            {
                username = usernameBox.Text;
                if (File.Exists(username + "/login.json") && passwordBox.Password == "" && sentryFileTextBox.Text == "" &&
                    logFileTextBox.Text == "" && displaynameBox.Text == "" && consoleLLBox.SelectedItem.ToString() == "System.Windows.Controls.ListBoxItem: Verbose" &&
                    fileLLBox.SelectedItem.ToString() == "System.Windows.Controls.ListBoxItem: Verbose")
                {
                    var _data = Bot.ReadData(username);
                    logFile     = _data.logFile;
                    sentryFile  = _data.sentryFile;
                    username    = _data.username;
                    password    = _data.password;
                    displayName = _data.displayName;
                    cll         = _data.cll;
                    fll         = _data.fll;

                    if (sharedSecretBox.Text != "")
                    {
                        Bot.sharedSecret = sharedSecretBox.Text;
                    }

                    Log = Log.CreateInstance(logFile, username, (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), cll, true),
                                             (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), fll, true));

                    Log.Instance.Silly("Successfully read login data from file");
                    Close();
                    Bot.Start(username, password, cll, fll, logFile, displayName, sentryFile);
                }
                else
                {
                    if (passwordBox.Password != "")
                    {
                        object cll = ((ListBoxItem)consoleLLBox.SelectedValue).Content;
                        object fll = ((ListBoxItem)fileLLBox.SelectedValue).Content;

                        Log = Log.CreateInstance((logFileTextBox.Text == "" ? usernameBox.Text + ".log" : logFileTextBox.Text), usernameBox.Text,
                                                 (cll == null ? (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), "Verbose", true) :
                                                  (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), cll.ToString(), true)),
                                                 (fll == null ? (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), "Verbose", true) :
                                                  (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), fll.ToString(), true)));

                        Log.Instance.Silly("Console started successfully!");
                        if (displaynameBox.Text != "")
                        {
                            Close();
                            if (sharedSecretBox.Text != "")
                            {
                                Bot.sharedSecret = sharedSecretBox.Text;
                            }
                            Bot.Start(usernameBox.Text, passwordBox.Password, (cll == null ? "Verbose" :
                                                                               cll.ToString()), (fll == null ? "Verbose" :
                                                                                                 fll.ToString()), (logFile == null ? usernameBox.Text + ".log" : logFile),
                                      displaynameBox.Text, (sentryFile == null ? usernameBox.Text + ".sentry" : sentryFile));
                        }
                        else
                        {
                            MessageBox.Show("Missing Display Name!", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Missing password.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                        return;
                    }
                }
            }
            else
            {
                MessageBox.Show("Missing username.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                return;
            }
        }