Пример #1
0
        public void tb_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string command = CommandLine.Text;
                CommandLine.Text = "";
                AddToConsole("> " + command);

                string[] args = command.Split(new char[] { ' ' });

                Thread t = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        switch (args[0])
                        {
                        case "date":

                            if (args.Length <= 1)
                            {
                                AddToConsole("Unable to find lottery \' \'");
                                return;
                            }

                            foreach (Lottery l in States.AllStates.SelectMany(x => x.lotteries))
                            {
                                if (l.lotteryName == args[1])
                                {
                                    DateTime date = autoclave.DecodeDate(l);

                                    AddToConsole(date.ToLongDateString());

                                    return;
                                }
                            }

                            foreach (IStateDecodable s in States.AllStates)
                            {
                                if (args[1] == s.stateName)
                                {
                                    foreach (Lottery l in (s as State).lotteries)
                                    {
                                        try
                                        {
                                            DateTime date = autoclave.DecodeDate(l);

                                            AddToConsole(l.lotteryName + ": " + date.ToLongDateString());

                                            continue;
                                        }
                                        catch (Exception ex)
                                        {
                                            if (ex.InnerException != null)
                                            {
                                                if (ex.InnerException.Message.Contains("closed."))
                                                {
                                                    AddToConsole("    ...The host closed the connection.");
                                                    continue;
                                                }
                                            }
                                            AddToConsole("An error occurred when running " + l.lotteryName);
                                        }
                                    }

                                    return;
                                }
                            }

                            AddToConsole("Unable to find lottery \'" + args[1] + "\'");

                            break;

                        case "numbers":

                            if (args.Length <= 1)
                            {
                                AddToConsole("Unable to find lottery \' \'");
                                return;
                            }

                            foreach (Lottery l in States.AllStates.SelectMany(x => x.lotteries))
                            {
                                if (args.Length <= 1)
                                {
                                    AddToConsole("Unable to find lottery \' \'");
                                    return;
                                }

                                if (l.lotteryName == args[1])
                                {
                                    if (l.Action == LotteryDecodeAction.Decode)
                                    {
                                        LotteryNumber num = autoclave.DecodeNumbers(l);

                                        AddToConsole(num.ToString(LotteryNumberStringTypes.NumbersSpecialsMultipliers));
                                    }
                                    else if (l.Action == LotteryDecodeAction.DateTrigger)
                                    {
                                        AddToConsole("Date Trigger Only");
                                    }
                                    return;
                                }
                            }

                            foreach (IStateDecodable s in States.AllStates)
                            {
                                if (args[1] == s.stateName)
                                {
                                    foreach (Lottery l in (s as State).lotteries)
                                    {
                                        try
                                        {
                                            if (l.Action == LotteryDecodeAction.Decode)
                                            {
                                                LotteryNumber num = autoclave.DecodeNumbers(l);

                                                AddToConsole(l.lotteryName + ": " + num.ToString(LotteryNumberStringTypes.NumbersSpecialsMultipliers));
                                            }
                                            else if (l.Action == LotteryDecodeAction.DateTrigger)
                                            {
                                                AddToConsole("Date Trigger Only");
                                            }

                                            continue;
                                        }
                                        catch (Exception ex)
                                        {
                                            if (ex.InnerException != null)
                                            {
                                                if (ex.InnerException.Message.Contains("closed."))
                                                {
                                                    AddToConsole("    ...The host closed the connection.");
                                                    continue;
                                                }
                                            }
                                            AddToConsole("Exception while running " + l.lotteryName);
                                            continue;
                                        }
                                    }

                                    return;
                                }
                            }

                            AddToConsole("Unable to find lottery \'" + args[1] + "\'");

                            break;

                        case "autoclave":

                            if (args.Length <= 1)
                            {
                                AddToConsole(">>autoclave usage:");
                                AddToConsole(">>autoclave cycle");
                                AddToConsole(">>autoclave init");
                                AddToConsole(">>autoclave debug");
                                return;
                            }

                            if (args[1] == "cycle")
                            {
                                if (autoclave != null)
                                {
                                    if (autoclave.ticker != null)
                                    {
                                        autoclave.Cycle(true);
                                        return;
                                    }
                                    else
                                    {
                                        AddToConsole("Autoclave is not initialized. Please run autoclave init.");
                                        return;
                                    }
                                }
                                else
                                {
                                    AddToConsole("Autoclave is not initialized. Please run autoclave init.");
                                    return;
                                }
                            }
                            else if (args[1] == "init")
                            {
                                autoclave.RunningUpdated();
                                return;
                            }

                            if (args[1] == "debug")
                            {
                                if (args.Length == 3)
                                {
                                    if (args[2].ToLower() == "true")
                                    {
                                        autoclave.Debug = true;
                                        AddToConsole("Debug messages enabled.");
                                    }
                                    else if (args[2].ToLower() == "false")
                                    {
                                        autoclave.Debug = false;
                                        AddToConsole("Debug messages disabled.");
                                    }
                                    else
                                    {
                                        AddToConsole(">>debug usage:");
                                        AddToConsole(">>autoclave debug true/false"); AddToConsole(">>debug usage:");
                                        AddToConsole(">>autoclave debug true/false");
                                    }
                                }
                                else
                                {
                                    AddToConsole(">>debug usage:");
                                    AddToConsole(">>autoclave debug true/false");
                                }
                            }

                            break;

                        case "write":

                            if (args.Length >= 2)
                            {
                                Thread writeThread = new Thread(new ThreadStart(() =>
                                {
                                    using (WebClient client = new WebClient())     // WebClient class inherits IDisposable
                                    {
                                        try
                                        {
                                            if (args.Length >= 3)
                                            {
                                                if (command.Contains("-emulate"))
                                                {
                                                    client.Headers.Add("Upgrade-Insecure-Requests", "1");
                                                    client.Headers.Add("Accept", "*/*");
                                                    client.Headers.Add("Accept-Encoding", "gzip, deflate, sdch, br");
                                                    client.Headers.Add("Accept-Language", "en-US,en;q=0.8");
                                                }
                                            }
                                            client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36");
                                            AddToConsole("Downloading " + args[1]);
                                            string text = client.DownloadString(args[1]);
                                            File.WriteAllText(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Autoclave\\Save\\write.html", text);
                                            AddToConsole("Finished download.");
                                        }
                                        catch (WebException ex)
                                        {
                                            if (ex.Message.Contains("find"))
                                            {
                                                AddToConsole("Invalid URI.");
                                                return;
                                            }

                                            AddToConsole("WebException " + ex.Status.ToString());
                                            return;
                                        }
                                    }
                                }));

                                writeThread.Start();
                            }

                            break;

                        case "version":

                            AddToConsole(version);

                            break;

                        default:

                            AddToConsole("Invalid command \'" + args[0] + "\'");

                            break;
                        }
                    }
                    catch
                    {
                        AddToConsole("A fatal error occurred when running " + command);
                    }
                }));

                t.Start();
            }
        }
Пример #2
0
        public void tb_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string command = CommandLine.Text;
                CommandLine.Text = "";
                AddToConsole("> " + command);

                string[] args = command.Split(new char[] { ' ' });

                Thread t = new Thread(new ThreadStart(() =>
                {
                    switch (args[0])
                    {
                    case "date":

                        foreach (Lottery l in States.AllStates.SelectMany(x => x.lotteries))
                        {
                            if (args.Length <= 1)
                            {
                                AddToConsole("Unable to find lottery \' \'");
                                return;
                            }

                            if (l.lotteryName == args[1])
                            {
                                l.LoadHtml(l.url);
                                IStateDecodable decode = l.state as IStateDecodable;
                                DateTime date          = decode.GetLatestDate(l);

                                AddToConsole(date.ToLongDateString());

                                return;
                            }
                        }

                        AddToConsole("Unable to find lottery \'" + args[1] + "\'");

                        break;

                    case "numbers":

                        foreach (Lottery l in States.AllStates.SelectMany(x => x.lotteries))
                        {
                            if (args.Length <= 1)
                            {
                                AddToConsole("Unable to find lottery \' \'");
                                return;
                            }

                            if (l.lotteryName == args[1])
                            {
                                if (l.Action == LotteryDecodeAction.Decode)
                                {
                                    l.LoadHtml(l.url);
                                    IStateDecodable decode = l.state as IStateDecodable;
                                    LotteryNumber num      = decode.GetLatestNumbers(l);

                                    AddToConsole(num.ToString(LotteryNumberStringTypes.Numbers));
                                }
                                else if (l.Action == LotteryDecodeAction.DateTrigger)
                                {
                                    AddToConsole("Date Trigger Only");
                                }
                                return;
                            }
                        }

                        AddToConsole("Unable to find lottery \'" + args[1] + "\'");

                        break;

                    default:

                        AddToConsole("Invalid command \'" + args[0] + "\'");

                        break;
                    }
                }));

                t.Start();
            }
        }