Exemple #1
0
        public void HandleUpdateIfNeeded(LotteryNumber num)
        {
            string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            if (File.Exists(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html"))
            {
                num.lottery.html = File.ReadAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html");
                IStateDecodable decode = num.lottery.state as IStateDecodable;
                LotteryNumber   numold = decode.GetLatestNumbers(num.lottery);

                if (!numold.numbers.Equals(num.numbers))
                {
                    //no update
                }
                else
                {
                    main.NumbersList.Add(num);
                    File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", num.lottery.html);
                    main.AddToConsole("    ...Update found.");
                }
            }
            else
            {
                Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                main.NumbersList.Add(num);
                File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", num.lottery.html);
                main.AddToConsole("    ...No record.");
            }
        }
Exemple #2
0
        public LotteryNumber DecodeNumbers(Lottery l)
        {
            for (int tries = 0; tries < 3; tries++)
            {
                try
                {
                    l.LoadHtml(l.url);
                    IStateDecodable decode = l.state as IStateDecodable;
                    LotteryNumber   num    = decode.GetLatestNumbers(l);
                    return(num);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        if (ex.InnerException.Message.Contains("closed."))
                        {
                            main.AddToConsole("    ...The host closed the connection.");
                            main.AddToConsole("    ...Retrying (" + (tries + 1) + " of 3)");
                            Thread.Sleep(1000);
                            continue;
                        }
                    }
                    main.AddToConsole("Unknown exception while running " + l.lotteryName);
                    if (Debug)
                    {
                        main.AddToConsole("    ..." + ex.Message);
                        if (ex.InnerException != null)
                        {
                            main.AddToConsole("    ..." + ex.InnerException.Message);
                        }
                        main.AddToConsole("Stack trace: \n" + ex.StackTrace);
                    }
                    break;
                }
            }

            throw new NumbersUnavailableExcpetion();
        }
Exemple #3
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();
            }
        }
Exemple #4
0
        public void HandleUpdateIfNeeded(LotteryNumber num, int recursivecalls = 0)
        {
            try
            {
                string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                if (File.Exists(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html"))
                {
                    //save the new html
                    string writeHTML = num.lottery.html;
                    num.lottery.html = File.ReadAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html");
                    if (String.IsNullOrWhiteSpace(num.lottery.html))
                    {
                        main.AddToConsole("    ...Record blank. Deleting...");
                        File.Delete(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html");
                        Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                        main.NumbersList.Add(num);
                        File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", writeHTML);
                        main.AddToConsole("    ...Record re-made. This will cause a slave update.");
                    }
                    IStateDecodable decode = num.lottery.state as IStateDecodable;
                    LotteryNumber   numold = decode.GetLatestNumbers(num.lottery);

                    bool numsMatch = false;
                    for (int i = 0; i < num.numbers.Length; i++)
                    {
                        if (numold.numbers.Length != num.numbers.Length)
                        {
                            numsMatch = false;
                            break;
                        }
                        if (numold.numbers[i].Equals(num.numbers[i]))
                        {
                            numsMatch = true;
                            break;
                        }
                    }

                    if (!numsMatch || num.date != numold.date) //sense update
                    {
                        main.NumbersList.Add(num);
                        File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", writeHTML);
                        main.AddToConsole("    ...Update found.");
                    }
                }
                else
                {
                    Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                    main.NumbersList.Add(num);
                    File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", num.lottery.html);
                    main.AddToConsole("    ...No record.");
                }
            }
            catch (NumbersUnavailableExcpetion)
            {
                main.AddToConsole("    ...Currently unavailabele/pending.");
            }
            catch (Exception ex)
            {
                main.AddToConsole("Exception while running " + num.lottery.lotteryName);
                if (Debug)
                {
                    main.AddToConsole("    ..." + ex.Message);
                    if (ex.InnerException != null)
                    {
                        main.AddToConsole("    ..." + ex.InnerException.Message);
                    }
                    main.AddToConsole("Stack trace: \n" + ex.StackTrace);
                }
            }
        }
Exemple #5
0
        public void Tick(object source, ElapsedEventArgs e)
        {
            if (!Running)
            {
                ticker.Stop();
                return;
            }

            main.AddToConsole("Cycles Render starting...");

            main.NumbersList.Clear();

            Thread t = new Thread(new ThreadStart(() =>
            {
                int run = 0;
                int iS  = 0;
                foreach (State state in States.AllStates)
                {
                    state.main = main;
                    int iL     = 0;
                    foreach (Lottery lottery in state.lotteries)
                    {
                        if (!Running)
                        {
                            return;
                        }

                        main.UpdateProgressBar2(iL, state.lotteries.Count);
                        main.UpdateProgressBar1(iS, States.AllStates.Count);
                        main.UpdateStatusText("Cycles Render (" + run + " / " + States.AllStates.Sum(x => x.lotteries.Count) + ")");
                        main.AddToConsole("Rendering " + lottery.url + "...");


                        if (lottery.Action == LotteryDecodeAction.Decode)
                        {
                            lottery.LoadHtml(lottery.url);
                            IStateDecodable decode = state as IStateDecodable;
                            LotteryNumber num      = decode.GetLatestNumbers(lottery);
                            HandleUpdateIfNeeded(num);
                        }
                        else if (lottery.Action == LotteryDecodeAction.DateTrigger)
                        {
                            lottery.LoadHtml(lottery.url);
                            IStateDecodable decode = state as IStateDecodable;
                            DateTime date          = decode.GetLatestDate(lottery);
                            HandleDateTrigger(date, lottery);
                        }
                        iL++;
                        run++;

                        main.UpdateProgressBar2(iL, state.lotteries.Count);
                        main.UpdateProgressBar1(iS, States.AllStates.Count);
                        main.UpdateStatusText("Cycles Render (" + run + " / " + States.AllStates.Sum(x => x.lotteries.Count) + ")");
                        //main.AddToConsole(num.lottery.lotteryNameUI + " finished.");
                    }
                    iS++;
                }

                ticker.Start();

                if (main.InvokeRequired)
                {
                    main.BeginInvoke((MethodInvoker) delegate() { main.CyclesRenderFinished(); });
                }
                else
                {
                    main.CyclesRenderFinished();
                }
            }));

            try
            {
                ticker.Stop();
                t.Start();
            }
            catch
            {
                main.AddToConsole("There was an error running cycles render.");
            }
        }
Exemple #6
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();
            }
        }
Exemple #7
0
        public static LotteryNumber CheckValidation(LotteryNumber number)
        {
            bool valid = true;

            if (number.lottery.Action == LotteryDecodeAction.Skip)
            {
                number.ADI = AfterDecodeInformation.NotDrawnOrUnavailable;
                return(number);
            }

            if (number.numbers != null)
            {
                if (number.numbers.Length != number.lottery.NumbersCount)
                {
                    number.ADI = AfterDecodeInformation.Invalid;
                    valid      = false;
                }
                if (number.numbers.Length > 0 && number.lottery.UnitLength > 0)
                {
                    if (number.numbers[0].Length > number.lottery.UnitLength)
                    {
                        number.ADI = AfterDecodeInformation.Invalid;
                        valid      = false;
                    }
                }
                else if (number.numbers.Length == 0 && number.lottery.UnitLength > 0)
                {
                    number.ADI = AfterDecodeInformation.Invalid;
                    valid      = false;
                }
            }
            if (number.specials != null)
            {
                if (number.specials.Length != number.lottery.SpecialsCount)
                {
                    number.ADI = AfterDecodeInformation.Invalid;
                    valid      = false;
                }
                if (number.specials.Length > 0 && number.lottery.SpecialUnitLength > 0)
                {
                    if (number.specials[0].Length > number.lottery.SpecialUnitLength)
                    {
                        number.ADI = AfterDecodeInformation.Invalid;
                        valid      = false;
                    }
                }
                else if (number.specials.Length == 0 && number.lottery.SpecialUnitLength > 0)
                {
                    number.ADI = AfterDecodeInformation.Invalid;
                    valid      = false;
                }
            }
            if ((String.IsNullOrWhiteSpace(number.multiplier) && number.lottery.hasMultiplier))
            {
                number.ADI = AfterDecodeInformation.Invalid;
                valid      = false;
            }

            if (valid)
            {
                number.ADI = AfterDecodeInformation.Valid;

                string path         = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                string specificpath = path + "\\Autoclave\\Log\\NumberSave.log";

                int totalNumbers = 0;
                int readNumbers  = 0;

                if (number.lottery.SpecialsCount > 0 || number.lottery.NumbersCount > 0)
                {
                    if (Directory.Exists(path + "\\Autoclave\\Log\\"))
                    {
                        if (File.Exists(specificpath))
                        {
                            try
                            {
                                readNumbers = Convert.ToInt32(File.ReadAllText(specificpath));
                            }
                            catch
                            {
                                readNumbers = 0;
                            }
                        }
                    }

                    totalNumbers = readNumbers + number.lottery.NumbersCount + number.lottery.SpecialsCount;

                    File.WriteAllText(specificpath, totalNumbers.ToString());
                }
            }
            return(number);
        }