private async void SearchWindow_Loaded(object sender, RoutedEventArgs e) { string result = await Search.GetSearchItems(); GSCCCAPage page = new GSCCCAPage(result); page.GetSearchItems(); this.InstrumentType.ItemsSource = DataStore.Instance.InstrumentTypes; this.InstrumentType.SelectedItem = DataStore.Instance.InstrumentTypes.Find(i => i.Key.ToLower().Contains("all")); this.Counties.ItemsSource = DataStore.Instance.Counties; this.Counties.SelectedItem = DataStore.Instance.Counties.Find(i => i.Key.ToLower().Contains("all")); this.GrantorName.Focus(); }
private async Task SearchForName(string name, string partyType, DateTime?fromDate, DateTime?toDate, string instrumentType, string county) { string result = await Search.GetNamesAsync(name, partyType, fromDate, toDate, instrumentType, county, 1); GSCCCAPage page = new GSCCCAPage(result); int pageNumbers = page.GetNumberOfPageResults(); if (page.IsLoginRequired()) { Login login = new Login(); login.Owner = this; login.WindowStartupLocation = WindowStartupLocation.CenterOwner; login.ShowDialog(); await this.SearchForName(name, partyType, fromDate, toDate, instrumentType, county); } else { if (name == this.GrantorName.Text) { DataStore.Instance.GrantorResults = page.NamesSearch(); // If there are more pages, parse those too for (int i = 2; i <= pageNumbers; i++) { result = await Search.GetNamesAsync(name, partyType, fromDate, toDate, instrumentType, county, i); page = new GSCCCAPage(result); DataStore.Instance.GrantorResults.AddRange(page.NamesSearch()); } } else if (name == this.GranteeName.Text) { DataStore.Instance.GranteeResults = page.NamesSearch(); // If there are more pages, parse those too for (int i = 2; i <= pageNumbers; i++) { result = await Search.GetNamesAsync(name, partyType, fromDate, toDate, instrumentType, county, i); page = new GSCCCAPage(result); DataStore.Instance.GranteeResults.AddRange(page.NamesSearch()); } } } }
private async void Login_Click(object sender, RoutedEventArgs e) { this.Error.Text = ""; this.toggleUi(false); if (string.IsNullOrWhiteSpace(this.Username.Text) || string.IsNullOrWhiteSpace(this.Password.Password)) { this.Error.Text = "Username and password required"; this.toggleUi(true); } else { Log.Information($"Login as {this.Username.Text}"); string response = await Search.LoginAsync(this.Username.Text, this.Password.Password, this.lastLoginFailed); GSCCCAPage page = new GSCCCAPage(response); if (page.IsLoginRequired()) { Log.Information("Login failed"); // Login failed this.Error.Text = "Login failed, please try again"; this.lastLoginFailed = true; this.toggleUi(true); } else { Log.Information("Login succeeded"); if (this.SaveUserPass.IsChecked.HasValue && this.SaveUserPass.IsChecked.Value) { DataStore.Instance.Username = this.Username.Text; DataStore.Instance.Password = this.Password.Password; } this.Close(); } } }
private async void Details_Clicks(object sender, RoutedEventArgs e) { Log.Information("Searching deeds"); this.DeedsSearchProgress = await this.ShowProgressAsync("Searching Deeds", "Calculating time the search may take..."); this.DeedsSearchProgress.SetIndeterminate(); // Clear any previous searchs DataStore.Instance.DeedSearchResults.Clear(); int errors = 0; // Check our list of grantor deeds List <SelectedNameResult> grantorSearchResults = new List <SelectedNameResult>(); if (null != this.GrantorList.SelectedItems) { foreach (NameSearchResult selected in this.GrantorList.SelectedItems) { Log.Information($"Search criteria: Grantor {selected}"); DataStore.Instance.SelectedGrantors.Add(selected); // Retrieve list of deeds from selected grantor string deedListResponse = await Search.GetDeedListAsync(this.GrantorName.Text, selected.Name, this.Counties.Text, Search.PARTY_TYPE_GRANTOR, 1); GSCCCAPage page = new GSCCCAPage(deedListResponse); int pageNumbers = page.GetNumberOfPageResults(); if (page.IsLoginRequired()) { Login login = new Login(); login.Owner = this; login.WindowStartupLocation = WindowStartupLocation.CenterOwner; login.ShowDialog(); //this.GetDetails(selectedGrantors, selectedGrantees); this.Details_Clicks(sender, e); } else { // Parse first page of results grantorSearchResults.AddRange(page.DeedSearch()); // If there are more pages, parse those too for (int i = 2; i <= pageNumbers; i++) { deedListResponse = await Search.GetDeedListAsync(this.GrantorName.Text, selected.Name, this.Counties.Text, Search.PARTY_TYPE_GRANTOR, i); page = new GSCCCAPage(deedListResponse); grantorSearchResults.AddRange(page.DeedSearch()); } } } } Log.Debug($"Found {grantorSearchResults.Count} total grantor results"); // Check our list of grantee deeds List <SelectedNameResult> granteeSearchResults = new List <SelectedNameResult>(); if (null != this.GranteeList.SelectedItems) { foreach (NameSearchResult selected in this.GranteeList.SelectedItems) { Log.Information($"Search criteria: Grantor {selected}"); DataStore.Instance.SelectedGrantees.Add(selected); // Retrieve list of deeds from selected grantor string deedListResponse = await Search.GetDeedListAsync(this.GranteeName.Text, selected.Name, this.Counties.Text, Search.PARTY_TYPE_GRANTEE, 1); GSCCCAPage page = new GSCCCAPage(deedListResponse); int pageNumbers = page.GetNumberOfPageResults(); granteeSearchResults.AddRange(page.DeedSearch()); // Parse first page of results granteeSearchResults.AddRange(page.DeedSearch()); // If there are more pages, parse those too for (int i = 2; i <= pageNumbers; i++) { deedListResponse = await Search.GetDeedListAsync(this.GranteeName.Text, selected.Name, this.Counties.Text, Search.PARTY_TYPE_GRANTEE, i); page = new GSCCCAPage(deedListResponse); granteeSearchResults.AddRange(page.DeedSearch()); } } } Log.Debug($"Found {granteeSearchResults.Count} total grantee results"); // Calculate time required for seach int recordsToSearch = grantorSearchResults.Count + granteeSearchResults.Count; this.searchTime = TimeSpan.FromMilliseconds(Search.REQUEST_DELAY * recordsToSearch).Add(new TimeSpan(0, 0, 1)); this.countdownTime = this.searchTime; // Update our message display to let the user know how long it may take this.DeedsSearchProgress.SetMessage($"Search will take at least {this.searchTime.ToString(@"mm\:ss")} minutes"); this.DeedsSearchProgress.Maximum = recordsToSearch; this.DeedsSearchProgress.SetCancelable(true); this.DeedsSearchProgress.Canceled += DeedsSearchProgress_Canceled; cancelDeedsSearch = false; int recordsCompleted = 0; Timer timer = new Timer(1000); timer.Elapsed += Timer_Elapsed; timer.Start(); // Query each grantor deed foreach (SelectedNameResult deedResult in grantorSearchResults) { if (cancelDeedsSearch) { Log.Information("Deed search cancelled"); break; } string deedResponse = await Search.GetDeedAsync(deedResult.DeedUrl, Search.PARTY_TYPE_GRANTOR); //DataStore.Instance.writeToFile(deedResponse); GSCCCAPage deedPage = new GSCCCAPage(deedResponse); // Check if we're been caught and flagged as non-human or a free account if (!deedPage.IsRecaptchaPresent() && !deedPage.IsFreeAccount()) { Deed deed = deedPage.DeedResult(); // TODO Remove? DataStore.Instance.DeedSearchResults.Add(deed); DataStore.Instance.CheckHit(deed); } else { errors++; this.Notification.Text = $"Failed retrieving {errors} deeds"; this.Notification.Foreground = Brushes.Red; Log.Warning($"Failed retrieving deed at {deedResult.DeedUrl}"); } recordsCompleted++; this.DeedsSearchProgress.SetProgress(recordsCompleted); } // Query each grantee deed foreach (SelectedNameResult deedResult in granteeSearchResults) { if (cancelDeedsSearch) { Log.Information("Deed search cancelled"); break; } string deedResponse = await Search.GetDeedAsync(deedResult.DeedUrl, Search.PARTY_TYPE_GRANTEE); GSCCCAPage deedPage = new GSCCCAPage(deedResponse); // Check if we're been caught and flagged as non-human or a free account if (!deedPage.IsRecaptchaPresent() && !deedPage.IsFreeAccount()) { Deed deed = deedPage.DeedResult(); DataStore.Instance.DeedSearchResults.Add(deed); DataStore.Instance.CheckHit(deed); } else { errors++; this.Notification.Text = $"Failed retrieving {errors} deeds"; this.Notification.Foreground = Brushes.Red; Log.Warning($"Failed retrieving deed at {deedResult.DeedUrl}"); } recordsCompleted++; this.DeedsSearchProgress.SetProgress(recordsCompleted); } timer.Stop(); await this.DeedsSearchProgress.CloseAsync(); this.ResultsList.ItemsSource = DataStore.Instance.DeedResults; this.SearchesTextBlock.Text = $"Searched: {recordsToSearch}"; this.HitsTextBlock.Text = $"Hits: {DataStore.Instance.DeedResults.Count}"; this.ErrorstextBlock.Text = $"Errors: {errors}"; Log.Information($"Searched: {recordsToSearch}, Hits: {DataStore.Instance.DeedResults.Count}, Errors: {errors}"); // Move to our final tab to display results this.NavigationTab.SelectedIndex = 2; }