/// <summary> /// Queries a database for information, composing the query with information provided in the /// specified query structure. This query uses a single request and as such cannot be used /// with large data sets. /// </summary> /// <param name="databaseId"> /// The unique identifier of the EMS database to query. /// </param> /// <param name="query"> /// The information used to construct a query for which results are returned. /// </param> /// <param name="callback"> /// A callback to execute for each row of data received. /// </param> /// <param name="emsSystem"> /// The unique identifier of the system containing the EMS data. /// </param> public virtual Task SimpleQueryAsync(string databaseId, DatabaseQuery query, RowCallback callback, int emsSystem = NoEmsServerSpecified) { int ems = GetEmsSystemForMethodCall(emsSystem); return(CallApiTask(api => api.QueryDatabase(ems, databaseId, query.Raw)).ContinueWith(task => { // Callback for each row. DbQueryResult queryResult = task.Result; var result = new DatabaseQueryResult(queryResult.Header); result.CallbackRows(query, queryResult.Rows, callback); })); }
/// <summary> /// Queries the database for information, composing the query with information provided in the /// specified query structure. This method is a convenience wrapper around the async-query routes /// to handle pagination, and it also executes a callback function for each row of data. /// </summary> /// <param name="databaseId"> /// The unique identifier of the EMS database to query. /// </param> /// <param name="query"> /// The information used to construct a query for which results are returned. /// </param> /// <param name="callback"> /// A callback to execute for each row of data received. /// </param> /// <param name="rowsPerCall"> /// The number of rows to read for each API call. /// </param> /// <param name="emsSystem"> /// The unique identifier of the system containing the EMS data. /// </param> public virtual async Task QueryAsync(string databaseId, DatabaseQuery query, RowCallback callback, int rowsPerCall = 20000, int emsSystem = NoEmsServerSpecified) { AsyncQueryInfo info = await StartQueryAsync(databaseId, query, emsSystem); var result = new DatabaseQueryResult(info.Header); int startingRow = 0; bool moreToRead = true; while (moreToRead) { AsyncQueryData data = await ReadQueryAsync(databaseId, info.Id, startingRow, startingRow + rowsPerCall - 1, emsSystem); result.CallbackRows(query, data.Rows, callback); startingRow = startingRow + rowsPerCall; moreToRead = data.HasMoreRows; } await StopQueryAsync(databaseId, info.Id, emsSystem); }