Example #1
0
        public static void InputLoop()
        {
            while (true)
            {
                string   command = Console.ReadLine().ToLower();
                string[] splits  = command.Split(' ');

                if (splits[0] == "action")
                {
                    if (splits.Length >= 2)
                    {
                        if (splits[1] == "slave")
                        {
                            Action = ProgramAction.Action_PopSlave;
                        }
                        else if (splits[1] == "mix")
                        {
                            Action = ProgramAction.Action_PopSlaveThenApply;
                        }
                        else if (splits[1] == "full")
                        {
                            Action = ProgramAction.Action_Full;
                        }
                    }

                    AddToConsole("ProgramAction is " + Action.ToString());
                }
                else if (splits[0] == "start")
                {
                    RenderTimer = 10000;
                    if (splits.Length >= 2)
                    {
                        try
                        {
                            RenderTimer = Convert.ToInt16(splits[1]) * 1000;
                        }
                        catch
                        {
                            AddToConsole("Incorrect format.");
                            continue;
                        }
                    }
                    Logging.StartEmailLogLoop(5 * 60 * 1000);
                    Status = ProgramStatus.Program_Idle;
                    AddToConsole("AUTOCLAVE Started");
                    Cycle();
                }
                else if (command == "slave")
                {
                    if (Slave != null)
                    {
                        Slave.Close();
                    }

                    Status = ProgramStatus.Program_Idle;

                    Slave          = new SequentialSlave();
                    Slave.Sequence = NumbersList;
                    SystemSounds.Exclamation.Play();

                    Slave.ShowDialog();

                    NumbersList.Clear();
                }
                else
                {
                    AddToConsole("\'" + command + "\' not recognized.");
                }
            }
        }
Example #2
0
        private static async void CycleEndedAsync()
        {
            Status = ProgramStatus.Program_Idle;

            if ((Action == ProgramAction.Action_PopSlave) && NumbersList.Count > 0)
            {
                Status = ProgramStatus.Program_Applying;

                AddToConsole("");
                AddToConsole("Autoclave detected " + NumbersList.Count + " updates.");
                foreach (LotteryNumber n in NumbersList)
                {
                    AddToConsole("    [" + n.lottery.lotteryName + "]");
                }
                AddToConsole("");

                List <LotteryNumber> validatedList = new List <LotteryNumber>();
                foreach (LotteryNumber n in NumbersList)
                {
                    validatedList.Add(Autoclave.Validation.CheckValidation(n));
                }

                Slave          = new SequentialSlave();
                Slave.Sequence = validatedList;
                SystemSounds.Exclamation.Play();

                Slave.ShowDialog();

                NumbersList.Clear();

                Status = ProgramStatus.Program_Waiting;
            }
            else if (Action == ProgramAction.Action_Full || Action == ProgramAction.Action_PopSlaveThenApply)
            {
                AddToConsole("");
                AddToConsole("Autoclave detected " + NumbersList.Count + " updates.");
                foreach (LotteryNumber n in NumbersList)
                {
                    AddToConsole("    [" + n.lottery.lotteryName + "]");
                }
                AddToConsole("");

                if (NumbersList.Count > 0)
                {
                    List <string> updates = new List <string>();
                    updates.Add("Autoclave detected " + NumbersList.Count + " updates.");

                    foreach (LotteryNumber n in NumbersList)
                    {
                        updates.Add("    [" + n.lottery.lotteryName + "]");
                    }

                    Logging.AddToLog(updates.ToArray());
                }

                if (NumbersList.Count <= 0)
                {
                    Status = ProgramStatus.Program_Waiting;
                    return;
                }

                List <LotteryNumber> validatedList = new List <LotteryNumber>();
                foreach (LotteryNumber n in NumbersList)
                {
                    validatedList.Add(Autoclave.Validation.CheckValidation(n));
                }

                if (Action == ProgramAction.Action_PopSlaveThenApply)
                {
                    Slave          = new SequentialSlave();
                    Slave.Sequence = validatedList;
                    SystemSounds.Exclamation.Play();

                    Slave.ShowDialog();
                }

                TextUtils.DashBox("Deploying updates to LH.com...");
                Console.WriteLine();
                Console.WriteLine();
                AddToConsole("Creating JSON object...");

                DataEntryAPI.EntryImporterWebRequest request = NumbersListToConcreteJson.ToJson(validatedList);
                AddToConsole("Complete.");
                if (request.draw_data.Length <= 0)
                {
                    Logging.AddToLog(new string[]
                    {
                        "All updates detected were FullAutoAction.DoNothing. No updates will be deployed."
                    });
                    AddToConsole(" --- All updates are FullAutoAction.DoNothing. No updates will be deployed.");
                    AddToConsole("");
                    Status = ProgramStatus.Program_Waiting;
                    return;
                }
                else
                {
                    AddToConsole("Submitting data to LHAPI...");
                    try
                    {
                        DataEntryAPI.EntryImporterWebResponse response = await DataEntryAPI.Entry.EntryImporter(request);

                        Logging.AddToLog(new string[]
                        {
                            "Submitting data to LHAPI...",
                            "    " + response.response.StatusCode + " [" + (int)response.response.StatusCode + "]",
                            "    Submitted json payload: ",
                            "    " + request.rawJsonPayload
                        });
                        AddToConsole("Complete.");
                        Status = ProgramStatus.Program_Waiting;
                    }
                    catch
                    {
                        Logging.AddToLog(new string[]
                        {
                            "There was an error when submitting data to LHAPI. The payload may not have been submitted."
                        });
                        AddToConsole("Complete.");
                        Status = ProgramStatus.Program_Waiting;
                    }
                }
            }
            else
            {
                Status = ProgramStatus.Program_Waiting;
            }
            NumbersList.Clear();
            Logging.CloseEntry();
        }