CreateInstance() public static method

public static CreateInstance ( string logFile, string botName, LogLevel consoleLogLevel, LogLevel fileLogLevel ) : Log
logFile string
botName string
consoleLogLevel LogLevel
fileLogLevel LogLevel
return Log
Beispiel #1
0
        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            if (activeTriggers.Items.Count > 0)
            {
                foreach (ListBoxItem trigger in activeTriggers.Items)
                {
                    triggers.Add((BaseTrigger)Enum.Parse(typeof(BaseTrigger), trigger.Content.ToString()));
                }
            }

            if (File.Exists("login.json") && usernameBox.Text == "" && passwordBox.Password == "" && sentryFileTextBox.Text == "" &&
                logFileTextBox.Text == "" && displaynameBox.Text == "" && consoleLLBox.SelectedValue == null && fileLLBox.SelectedValue == null)
            {
                var _data = Bot.ReadData();
                logFile      = _data.logFile;
                sentryFile   = _data.sentryFile;
                autoJoinFile = _data.autoJoinFile;
                username     = _data.username;
                password     = _data.password;
                displayName  = _data.displayName;
                cll          = _data.cll;
                fll          = _data.fll;

                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");
                Bot.Start(username, password, cll, fll, logFile, displayName, sentryFile, triggers);
                Close();
            }
            else
            {
                if (usernameBox.Text != "" && 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), "Silly", true) :
                                              (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), cll.ToString(), true)),
                                             (fll == null ? (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), "Silly", true) :
                                              (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), fll.ToString(), true)));

                    Log.Instance.Silly("Console started successfully!");
                    if (passwordBox.Password != "" && displaynameBox.Text != "")
                    {
                        Bot.Start(usernameBox.Text, passwordBox.Password, (cll == null ? "Silly" :
                                                                           cll.ToString()), (fll == null ? "Silly" :
                                                                                             fll.ToString()), (logFile == null ? usernameBox.Text + ".log" : logFile),
                                  displaynameBox.Text, (sentryFile == null ? usernameBox.Text + ".sentry" : sentryFile), triggers);
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Missing either username or password.");
                }
            }
        }
        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;
            }
        }