/// <summary> /// extract session information into a form easier to deal with. /// Note: The startdates are particularly useful since this allows the user to /// specify a date start or range that he is interested in and the application can retrieve /// just the bills that are of interest without the user having to know much about how texas /// defines a session. /// </summary> /// <param name="results"></param> /// <param name="names"></param> /// <param name="ids"></param> /// <param name="startdates"></param> /// <returns></returns> private static bool ExtractSessionNames(GraphQL.Common.Response.GraphQLResponse results, out List <string> names, out List <string> ids, out List <DateTime> startdates) { names = null; ids = null; startdates = null; try { int n = results.Data.jurisdiction.legislativeSessions.edges.Count; names = new List <string>(n); ids = new List <string>(n); startdates = new List <DateTime>(n); for (int i = 0; i < n; i++) { string NameI = results.Data.jurisdiction.legislativeSessions.edges[i].node.name.ToString(); string IdentifierI = results.Data.jurisdiction.legislativeSessions.edges[i].node.identifier.ToString(); string startDateStringI = results.Data.jurisdiction.legislativeSessions.edges[i].node.startDate.ToString(); DateTime startDateI; bool OkDate = DateTime.TryParse(startDateStringI, out startDateI); if (NameI != null && IdentifierI != null && OkDate) { names.Add(NameI); ids.Add(IdentifierI); startdates.Add(startDateI); } } return(true); } catch (System.Exception) { } return(false); }
private void SetSessionsListBox(ListBox l, GraphQL.Common.Response.GraphQLResponse resp) { // [0].node.identifier.ToString(); Newtonsoft.Json.Linq.JArray arr = resp.Data.jurisdiction.legislativeSessions.edges; List <string> noms = new List <string>(arr.Count); DataTable dt = new DataTable("hmmmm"); dt.Columns.Add("name"); dt.Columns.Add("index"); dt.Columns.Add("id"); int index = 0; foreach (var each in arr) { Newtonsoft.Json.Linq.JToken tok = each["node"]; DataRow dr = dt.NewRow(); string Id = each["node"]["identifier"].ToString(); dr["id"] = Id; dr["name"] = "[" + Id + "]" + each["node"]["name"].ToString(); dr["index"] = index; index++; dt.Rows.Add(dr); } DataView dv = new DataView(dt); dv.Sort = "name DESC"; l.DataSource = dv; l.DisplayMember = "name"; }
/// <summary> /// get all the bills by subject /// </summary> /// <param name="state"></param> /// <param name="session"></param> /// <param name="subject"></param> /// <param name="cursor"></param> /// <param name="f">method to call for each bill</param> /// <returns></returns> public async Task <Newtonsoft.Json.Linq.JArray> GetBillsBySubjectAllAsync(string state, string session, string subject, string cursor, ExtraActionPerQuery1 f) { string Cursor = ""; // GraphQL.Common.Response.GraphQLResponse resultsAll = null; Newtonsoft.Json.Linq.JArray summaryAll = null; while (true) { // // get a set of bills up to the limit (usually 100) GraphQL.Common.Response.GraphQLResponse results = await GetBillsBySubjectAsync(state, session, subject, Cursor); Newtonsoft.Json.Linq.JArray summaryOne = results.Data.search_1.edges; int Count = GetCount(summaryOne); if (Count <= 0) { // // no more bills available // break; } // // bills available, so append into a summary of all bills in memory // AppendResults(ref summaryAll, summaryOne, Count); // // do any client specified extra work // (like displaying results in a gui without having to wait for all the bills to // be read from Openstates. if (f != null) { f(summaryOne); } // // get the cursor of the last bill just read // Cursor = GetNextCursor(summaryOne, Count); // // no more bills available // if (!IsCursorOK(Cursor)) { break; } } return(summaryAll); }
/// <summary> /// Run the GraphQL Query /// </summary> /// <returns></returns> async public Task <JObject> Call() { GraphQLHttpRequest request = new GraphQLHttpRequest() { Query = this.Query, OperationName = this.OperationName, Variables = this.Variables }; GraphQLHttpResponse response = await this._client.SendQueryAsync(request); if (response.Errors != null) { throw new GraphQLException(response.Errors); } JObject data = (JObject)response.Data; return(data); }