/// <summary> /// engine for searching, executed as a new thread /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LaunchSearch(object sender, DoWorkEventArgs e) { isSearching = true; if (!MainVM.RepeatSearch) { MainVM.AvailableLog = ""; MainVM.NotAvailableLog = ""; LaunchSearchInstance(sender, e); } else { while (!worker.CancellationPending) { MainVM.AvailabilityLogToSend = ""; MainVM.AppendAvailableLog("--new search--"); MainVM.AppendNotAvailableLog("--new search--"); LaunchSearchInstance(sender, e); if (MainVM.SendEmail && MainVM.AvailabilityLogToSend.Length > 0) { EmailHelper.SendEmail(MainVM.EmailLogin, EmailPassword.Password, MainVM.AvailabilityLogToSend); MainVM.AppendStatusLog("email sent"); } for (int i = 0; i < MainVM.RepeatSearchAmount && !worker.CancellationPending; i++) { MainVM.AppendStatusLog(string.Format("pausing before next search... {0} mins", MainVM.RepeatSearchAmount - i)); for (int j = 0; j < 60 && !worker.CancellationPending; j++) { System.Threading.Thread.Sleep(1000); } } } } }
private void ConductSearch(string targetDate, string pep_csrf) { string postString = string.Format("&searchDate={1}" + "&skipPricing=true" + "&searchTime={2}" + "&partySize={3}" + "&id={0}%3BentityType%3Drestaurant" + "&type=dining" + "&pep_csrf={4}", System.Web.HttpUtility.UrlEncode(MainVM.CurrentRestaurant.id), System.Web.HttpUtility.UrlEncode(targetDate), System.Web.HttpUtility.UrlEncode(MainVM.CurrentTime.id), System.Web.HttpUtility.UrlEncode(MainVM.CurrentPartySize.id), pep_csrf); MainVM.AppendStatusLog("getting results page"); string result = getCookiesFromRequest(SearchParameters.rootUrl + SearchParameters.diningSearchUrl, postString, "POST"); MainVM.AppendStatusLog(new string('-', 25)); //NOTE - the style of the link will have "selected" if it's a direct hit; we're not going // to try to get that to work right now - for now we're just going to return results //string r = ""; //r = HtmlHelper.getTagContents(result, "SearchFailMessage", "div", "id").Trim(); //if (r.Length > 0) MainVM.AppendStatusLog(r); //r = HtmlHelper.getTagContents(result, "reserveFormLabel", "label", "class").Trim(); //if (r.Length > 0) MainVM.AppendStatusLog(string.Format("Available Times: {0}", r)); List <string> b = ParseAltTimes(result); if (b.Count() > 0) { MainVM.AppendStatusLog(string.Format(/*"Alt Times found: {0}"*/ "Available Times: {0}", string.Join(", ", b))); } MainVM.AppendStatusLog(new string('-', 25)); if (result.Contains("data-hasavailability=\"\"")) { MainVM.AppendStatusLog("no times found"); MainVM.AppendNotAvailableLog(string.Format("{0}", System.Web.HttpUtility.UrlDecode(targetDate))); } else { //LaVie.MusicBox.PlayNote(LaVie.MusicBox.Notes.A4, 500); bool firstResult = true; if (b.Count > 0 /* && r.Length > 0*/) { if (firstResult) { MainVM.AppendStatusLog("***** possible success *****"); MainVM.AppendAvailableLog(string.Format("{0}", System.Web.HttpUtility.UrlDecode(targetDate))); MainVM.AppendAvailabilityLogToSend(string.Format("{0}", System.Web.HttpUtility.UrlDecode(targetDate))); firstResult = false; } //b.Add(r); foreach (string time in (from a in b.Distinct() orderby DateTime.Parse(a) ascending select a)) { MainVM.AppendAvailableLog(string.Format("- {0}", time)); MainVM.AppendAvailabilityLogToSend(string.Format("- {0}", time)); } } else { MainVM.AppendStatusLog("unable to determine availability"); MainVM.AppendNotAvailableLog(string.Format("{0}", System.Web.HttpUtility.UrlDecode(targetDate))); MainVM.AppendNotAvailableLog(string.Format("- error?")); } } }