Exemplo n.º 1
0
        public DateTime DecodeDate(Lottery l, bool skipLoad)
        {
            for (int tries = 0; tries < 3; tries++)
            {
                try
                {
                    if (!skipLoad)
                    {
                        l.LoadHtml(l.url);
                    }

                    IStateDecodable decode = l.state as IStateDecodable;
                    DateTime        date   = decode.GetLatestDate(l);
                    return(date);
                }
                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();
        }
Exemplo n.º 2
0
        public void HandleDateTrigger(DateTime date, Lottery lot)
        {
            string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            if (File.Exists(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html"))
            {
                lot.html = File.ReadAllText(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html");
                IStateDecodable decode  = lot.state as IStateDecodable;
                DateTime        dateold = decode.GetLatestDate(lot);

                if (date.Equals(dateold))
                {
                    //no update
                }
                else
                {
                    main.NumbersList.Add(new LotteryNumber
                    {
                        date    = date,
                        lottery = lot,
                        numbers = new string[] { "Date Trigger Only" },
                    });
                    File.WriteAllText(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html", lot.html);
                    main.AddToConsole("    ...Update found.");
                }
            }
            else
            {
                Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                main.NumbersList.Add(new LotteryNumber
                {
                    date    = date,
                    lottery = lot,
                    numbers = new string[] { "Date Trigger Only" },
                });
                File.WriteAllText(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html", lot.html);
                main.AddToConsole("    ...No record.");
            }
        }
Exemplo n.º 3
0
        public static void HandleDateTrigger(DateTime date, Lottery lot)
        {
            try
            {
                string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                if (File.Exists(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html"))
                {
                    string writeHTML = lot.html;
                    lot.html = File.ReadAllText(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html");
                    if (String.IsNullOrWhiteSpace(lot.html))
                    {
                        AddToConsole("    ...Record blank. Deleting...");
                        File.Delete(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html");
                        Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                        NumbersList.Add(new LotteryNumber
                        {
                            date    = date,
                            lottery = lot,
                            numbers = new string[] { "Date Trigger Only" },
                        });
                        File.WriteAllText(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html", writeHTML);
                        AddToConsole("    ...Record re-made. This will cause a slave update.");
                    }
                    IStateDecodable decode  = lot.state as IStateDecodable;
                    DateTime        dateold = decode.GetLatestDate(lot);

                    if (date != dateold) //sense update
                    {
                        NumbersList.Add(new LotteryNumber
                        {
                            date    = date,
                            lottery = lot,
                            numbers = new string[] { "Date Trigger Only" },
                        });
                        File.WriteAllText(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html", writeHTML);
                        AddToConsole("    ...Update found.");
                    }
                }
                else
                {
                    Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                    NumbersList.Add(new LotteryNumber
                    {
                        date    = date,
                        lottery = lot,
                        numbers = new string[] { "Date Trigger Only" },
                    });
                    File.WriteAllText(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html", lot.html);
                    AddToConsole("    ...No record.");
                }
            }
            catch (NumbersUnavailableExcpetion)
            {
                AddToConsole("    ...Currently unavailabele/pending.");
            }
            catch (Exception ex)
            {
                AddToConsole("Exception while running " + lot.lotteryName);
                AddToConsole("    ..." + ex.Message);
                if (ex.InnerException != null)
                {
                    AddToConsole("    ..." + ex.InnerException.Message);
                }
                AddToConsole("Stack trace: \n" + ex.StackTrace);
            }
        }
Exemplo n.º 4
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.");
            }
        }
Exemplo n.º 5
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();
            }
        }