private async void BtnQuery_Click(object sender, EventArgs e) { this.queryCancelled = false; if (!this.InputsAreValid()) { return; } this.saveSessionHistoryToolStripMenuItem.Visible = true; this.showingOfflineSession = false; QueryBundle bundle = new QueryBundle() { Sandbox = this.tbSandbox.Text.Trim(), Scid = this.tbScid.Text.Trim(), TemplateName = this.tbTemplateName.Text.Trim(), QueryKey = this.tbQueryKey.Text.Trim(), QueryKeyIndex = this.cmbQueryType.SelectedIndex, QueryFrom = this.dateTimePicker1.Value, QueryTo = this.dateTimePicker2.Value, }; await this.SearchForHistoricalDocumentsAsync(bundle, true); }
private async Task SearchForHistoricalDocumentsAsync(QueryBundle queryBundle, bool addToStack) { this.tbSandbox.Text = queryBundle.Sandbox; this.tbScid.Text = queryBundle.Scid; this.tbTemplateName.Text = queryBundle.TemplateName; this.tbQueryKey.Text = queryBundle.QueryKey; this.cmbQueryType.SelectedIndex = queryBundle.QueryKeyIndex; this.dateTimePicker1.Value = queryBundle.QueryFrom; this.dateTimePicker2.Value = queryBundle.QueryTo; string eToken = await ToolAuthentication.GetDevTokenSilentlyAsync(this.tbScid.Text, this.tbSandbox.Text); this.lblExplanation.Text = "Searching for MPSD historical documents..."; Tuple <HttpStatusCode, string> response = null; string continuationToken = null; do { response = await this.QueryForHistoricalSessionDocuments(eToken, queryBundle, continuationToken); if (response.Item1 == HttpStatusCode.OK) { continuationToken = response.Item2; } else { continuationToken = null; } }while (continuationToken != null); this.downloadPanel.Hide(); if (response.Item1 != HttpStatusCode.OK) { if (response.Item1 == HttpStatusCode.Unauthorized) { MessageBox.Show("Your auth token has expired. Re-try the query to get a new token", "Expired Token"); } else if (response.Item1 == HttpStatusCode.InternalServerError) { MessageBox.Show("The server is busy. Please try again", QueryFailure); } else { MessageBox.Show(response.Item2, QueryFailure); } } else { if (this.listView1.Items.Count == 0) { this.btnPriorQuery.Visible = this.queryStack.Count > 0; // show the back button following un unsuccesful query (if there was a prior successul one) MessageBox.Show("No results found. Try expanding the query time window (if possible)\nor use different search criteria.", "Query Results"); } else { if (addToStack) { this.queryStack.Push(queryBundle); // succesful query, so remember it this.btnPriorQuery.Visible = this.queryStack.Count > 1; } else { this.btnPriorQuery.Visible = this.queryStack.Count > 0; } } } }
private async void BtnPriorQuery_Click(object sender, EventArgs e) { QueryBundle priorQuery = this.queryStack.Pop(); await this.SearchForHistoricalDocumentsAsync(priorQuery, false); }
private async Task <Tuple <HttpStatusCode, string> > QueryForHistoricalSessionDocuments(string eToken, QueryBundle queryBundle, string continuationToken) { if (continuationToken == null) { this.InitViews(); this.listView1.Items.Clear(); } Tuple <System.Net.HttpStatusCode, string> response = null; switch (this.cmbQueryType.SelectedIndex) { case (int)QueryBy.SessionName: { response = await SessionHistory.QuerySessionHistoryBranches( queryBundle.Scid, queryBundle.TemplateName, queryBundle.QueryKey, eToken); } break; case (int)QueryBy.GamerTag: { response = await SessionHistory.QuerySessionHistoryByGamertagAsync( queryBundle.Scid, queryBundle.TemplateName, queryBundle.QueryKey, queryBundle.QueryStartDate, queryBundle.QueryEndDate, continuationToken, eToken); } break; case (int)QueryBy.GamerXuid: { response = await SessionHistory.QuerySessionHistoryByXuidAsync( queryBundle.Scid, queryBundle.TemplateName, long.Parse(queryBundle.QueryKey), queryBundle.QueryStartDate, queryBundle.QueryEndDate, continuationToken, eToken); } break; case (int)QueryBy.CorrelationId: { response = await SessionHistory.QuerySessionHistoryByCorrelationIdAsync( queryBundle.Scid, queryBundle.TemplateName, this.tbQueryKey.Text, eToken); } break; } if (response.Item1 != HttpStatusCode.OK) { return(response); } SessionHistoryQueryResponse queryResponse = new SessionHistoryQueryResponse(response.Item2); foreach (var item in queryResponse.Results) { string[] arr = new string[QueryResultColumnCount] { item.SessionName, item.Branch, item.Changes.ToString(), this.displayDateTimesAsUTCToolStripMenuItem.Checked ? item.LastModified.ToString() : item.LastModified.ToLocalTime().ToString(), item.IsExpired.ToString(), item.ActivityId }; ListViewItem lvi = new ListViewItem(arr); this.listView1.Items.Add(lvi); } this.lblDocCount.Text = string.Format("{0} session{1}", this.listView1.Items.Count, (this.listView1.Items.Count != 1) ? "s" : string.Empty); this.lblDocCount.Text += " [" + SaveInstructions + "]"; if (this.queryCancelled) { return(new Tuple <HttpStatusCode, string>(HttpStatusCode.OK, null)); // ignore continuation token if user cancelled the query } else { return(new Tuple <HttpStatusCode, string>(HttpStatusCode.OK, queryResponse.ContinuationToken)); } }