public static DataEntryAPI.EntryImporterWebRequest ToJson(List <LotteryNumber> list) { DataEntryAPI.EntryImporterWebRequest request = new DataEntryAPI.EntryImporterWebRequest(); List <DataEntryAPI.EntryImporterWebRequest.EntryImporterDrawData> dataList = new List <DataEntryAPI.EntryImporterWebRequest.EntryImporterDrawData>(); List <LotteryNumber> InvalidNumbers = new List <LotteryNumber>(); if (DataEntryAPI.Auth.isProduction) { request.data_key = DataEntryAPI.Auth.AuthToken_Prod; } else { request.data_key = DataEntryAPI.Auth.AutoToken_Test; } foreach (LotteryNumber n in list) { DataEntryAPI.EntryImporterWebRequest.EntryImporterDrawData data = new DataEntryAPI.EntryImporterWebRequest.EntryImporterDrawData(); if (n.lottery.Submit == FullAutoAction.SubmitFull) { if (n.ADI == AfterDecodeInformation.Invalid) { InvalidNumbers.Add(n); } if (n.ADI != AfterDecodeInformation.Valid) { continue; } data.draw_date = n.date.ToShortDateString(); data.picks = n.numbers; data.multiplier = n.multiplier; data.lottery_id = n.lottery.lottery_id; data.specials = n.specials; foreach (string p in data.picks) { p.Trim(); } dataList.Add(data); } } if (InvalidNumbers.Count > 0) { Console.WriteLine("Autoclave validation checks failed on the following lotteries:"); foreach (LotteryNumber n in InvalidNumbers) { string nn = ""; for (int i = 0; i < n.numbers.Length; i++) { nn += n.numbers[i]; if (i < n.numbers.Length - 1) { nn += ", "; } } string sn = ""; if (n.specials != null) { sn += " ["; for (int i = 0; i < n.specials.Length; i++) { sn += n.specials[i]; if (i < n.specials.Length - 1) { sn += ", "; } } sn += "]"; } string mn = ""; if (!String.IsNullOrWhiteSpace(n.multiplier)) { mn = " <" + n.multiplier + ">"; } Console.WriteLine(" [" + n.lottery.lotteryName + "] -> {" + nn + sn + mn + "}"); Logging.AddToLog(new string[] { "Validation failed.", " [" + n.lottery.lotteryName + "] -> {" + nn + sn + mn + "}", " UL: " + n.lottery.UnitLength + ", NC: " + n.lottery.NumbersCount, " SUL: " + n.lottery.SpecialUnitLength + ", SNC: " + n.lottery.SpecialsCount, " hasMultiplier: " + n.lottery.hasMultiplier.ToString(), " This is a FullAutoAction." + n.lottery.Submit.ToString() + " lottery." }); } } request.draw_data = dataList.ToArray(); return(request); }
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(); }