コード例 #1
0
ファイル: asyncservice.cs プロジェクト: hemrika/SharePresence
 /// <summary>
 ///  worker method for the query case
 /// </summary>
 /// <param name="data"></param>
 /// <param name="asyncOp"></param>
 /// <param name="completionMethodDelegate"></param>
 /// <returns></returns>
 private void AsyncQueryWorker(AsyncQueryData data, AsyncOperation asyncOp, SendOrPostCallback completionMethodDelegate)
 {
     try
     {
         long contentLength;
         using (var responseStream = Query(data.UriToUse, data.Modified, null, out contentLength))
         {
             HandleResponseStream(data, responseStream, contentLength);
         }
     }
     catch (Exception e)
     {
         data.Exception = e;
     }
     completionMethodDelegate(data);
 }
コード例 #2
0
ファイル: asyncservice.cs プロジェクト: hemrika/SharePresence
        /// <summary>
        /// the basic interface as an async version. This call will return directly
        /// and you need to rely on the events fired to figure out what happened.
        /// </summary>
        /// <param name="queryUri">the Uri to Query</param>
        /// <param name="ifModifiedSince">The ifmodifiedsince date, use DateTime.MinValue if you want everything</param>
        /// <param name="doParse">if true, returns a feed, else a stream</param>
        /// <param name="userData">The userData token. this must be unique if you make several async requests at once</param>
        /// <returns>nothing</returns>
        private void QueryAsync(Uri queryUri, DateTime ifModifiedSince, bool doParse, Object userData)
        {
            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(userData);
            AsyncQueryData data    = new AsyncQueryData(queryUri, ifModifiedSince, doParse, asyncOp, userData, this.ProgressReportDelegate);

            AddUserDataToDictionary(userData, asyncOp);

            // Start the asynchronous operation.
            WorkerQueryEventHandler workerDelegate = new WorkerQueryEventHandler(AsyncQueryWorker);

            workerDelegate.BeginInvoke(
                data,
                asyncOp,
                this.CompletionMethodDelegate,
                null,
                null);
        }
コード例 #3
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 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);
        }