コード例 #1
0
        /// <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="emsSystem">
        /// The unique identifier of the system containing the EMS data.
        /// </param>
        public virtual Task <DatabaseQueryResult> SimpleQueryAsync(string databaseId, DatabaseQuery query, int emsSystem = NoEmsServerSpecified)
        {
            int ems = GetEmsSystemForMethodCall(emsSystem);

            return(CallApiTask(api => api.QueryDatabase(ems, databaseId, query.Raw)).ContinueWith(task =>
            {
                // Convert to our result format.
                DbQueryResult queryResult = task.Result;
                var result = new DatabaseQueryResult(queryResult.Header);
                result.AddRows(query, queryResult.Rows);
                return result;
            }));
        }
コード例 #2
0
        /// <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 converts the results into a more accessible structure.
        /// </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="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 <DatabaseQueryResult> QueryAsync(string databaseId, DatabaseQuery query, 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.AddRows(query, data.Rows);
                startingRow = startingRow + rowsPerCall;
                moreToRead  = data.HasMoreRows;
            }

            await StopQueryAsync(databaseId, info.Id, emsSystem);

            return(result);
        }