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(); }
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."); } }
public 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)) { main.AddToConsole(" ...Record blank. Deleting..."); File.Delete(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html"); 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", writeHTML); main.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 { main.NumbersList.Add(new LotteryNumber { date = date, lottery = lot, numbers = new string[] { "Date Trigger Only" }, }); File.WriteAllText(path + "\\Autoclave\\Save\\" + lot.lotteryName + ".html", writeHTML); 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."); } } catch (NumbersUnavailableExcpetion) { main.AddToConsole(" ...Currently unavailabele/pending."); } catch (Exception ex) { main.AddToConsole("Exception while running " + lot.lotteryName); if (Debug) { main.AddToConsole(" ..." + ex.Message); if (ex.InnerException != null) { main.AddToConsole(" ..." + ex.InnerException.Message); } main.AddToConsole("Stack trace: \n" + ex.StackTrace); } } }