Ejemplo n.º 1
0
        public static 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."))
                        {
                            AddToConsole("    ...The host closed the connection.");
                            AddToConsole("    ...Retrying (" + (tries + 1) + " of 3)");
                            Thread.Sleep(1000);
                            continue;
                        }
                    }
                    AddToConsole("Unknown exception while running " + l.lotteryName);
                    AddToConsole("    ..." + ex.Message);
                    if (ex.InnerException != null)
                    {
                        AddToConsole("    ..." + ex.InnerException.Message);
                    }
                    AddToConsole("Stack trace: \n" + ex.StackTrace);
                }
            }

            throw new NumbersUnavailableExcpetion();
        }
Ejemplo n.º 2
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.");
            }
        }
Ejemplo n.º 3
0
        public static 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))
                    {
                        AddToConsole("    ...Record blank. Deleting...");
                        File.Delete(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html");
                        Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                        NumbersList.Add(num);
                        File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", writeHTML);
                        AddToConsole("    ...Record re-made. This will cause a slave update.");

                        Logging.AddToLog(new string[]
                        {
                            "There was a problem opening the record. The record will be remade. This will cause an update.",
                            "    [" + num.lottery.lotteryName + "]"
                        });
                    }

                    LotteryNumber numold;

                    try
                    {
                        IStateDecodable decode = num.lottery.state as IStateDecodable;
                        numold = decode.GetLatestNumbers(num.lottery);
                    }
                    catch
                    {
                        AddToConsole("    ...There was an error reading the record. The record will be remade. This will cause an update.");
                        Logging.AddToLog(new string[]
                        {
                            "There was an error reading the record. The record will be remade. This will cause an update.",
                            "    [" + num.lottery.lotteryName + "]"
                        });

                        File.Delete(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html");
                        Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                        NumbersList.Add(num);
                        File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", writeHTML);

                        return;
                    }
                    bool numsMatch = true;
                    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
                    {
                        NumbersList.Add(num);
                        File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", writeHTML);
                        AddToConsole("    ...Update found.");
                    }
                }
                else
                {
                    Directory.CreateDirectory(path + "\\Autoclave\\Save\\");
                    NumbersList.Add(num);
                    File.WriteAllText(path + "\\Autoclave\\Save\\" + num.lottery.lotteryName + ".html", num.lottery.html);
                    AddToConsole("    ...No record.");
                }
            }
            catch (NumbersUnavailableExcpetion)
            {
                AddToConsole("    ...Currently unavailabele/pending.");
            }
            catch (Exception ex)
            {
                AddToConsole("Exception while running " + num.lottery.lotteryName);

                AddToConsole("    ..." + ex.Message);
                if (ex.InnerException != null)
                {
                    AddToConsole("    ..." + ex.InnerException.Message);
                }
                AddToConsole("Stack trace: \n" + ex.StackTrace);

                Logging.AddToLog(new string[]
                {
                    "There was an exception while handling updates. Could the website have updated?",
                    "    [" + num.lottery.lotteryName + "]",
                    "    Stack trace: ",
                    "    " + ex.StackTrace
                });
            }
        }
Ejemplo 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.");
            }
        }
Ejemplo 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();
            }
        }