コード例 #1
0
 /// <summary>
 /// Executes the asynchronously.
 /// </summary>
 /// <param name="requestUri">The request URI.</param>
 /// <param name="state">The state.</param>
 /// <param name="httpMethod">The HTTP method.</param>
 /// <returns>A function delegate that returns the future result to be available through the Task.</returns>
 public Task <OperationResponse> ExecuteAsync(Uri requestUri, object state, string httpMethod)
 {
     return(Task.Factory.FromAsync <Uri, string, OperationResponse>(
                (u, m, ac, s) => _dataContext.BeginExecute(u, ac, s, m),
                (ar) => _dataContext.EndExecute(ar),
                requestUri,
                httpMethod,
                state));
 }
コード例 #2
0
        /// <summary>Loads the collection asynchronously by loading the results from the request Uri.</summary>
        /// <param name="requestUri">The request uri to download results from.</param>
        /// <remarks>This method uses the event-based async pattern.
        /// The method returns immediately without waiting for the query to complete. Then it calls the handler of the
        /// <see cref="LoadCompleted"/> event exactly once on the UI thread. The event will be raised regradless
        /// if the query succeeded or not.
        /// This class only support one asynchronous operation in flight.</remarks>
        public void LoadAsync(Uri requestUri)
        {
            Util.CheckArgumentNull(requestUri, "requestUri");

            if (!this.IsTracking)
            {
                throw new InvalidOperationException(Strings.DataServiceCollection_OperationForTrackedOnly);
            }

            if (this.ongoingAsyncOperation != null)
            {
                throw new InvalidOperationException(Strings.DataServiceCollection_MultipleLoadAsyncOperationsAtTheSameTime);
            }

            DataServiceContext context = this.observer.Context;

            requestUri = UriUtil.CreateUri(context.BaseUri, requestUri);

            this.BeginLoadAsyncOperation(
                asyncCallback => context.BeginExecute <T>(requestUri, asyncCallback, null),
                asyncResult =>
            {
                QueryOperationResponse <T> response = (QueryOperationResponse <T>)context.EndExecute <T>(asyncResult);
                this.Load(response);
                return(response);
            });
        }
コード例 #3
0
        internal static IEnumerable <TElement> EndExecute <TElement>(DataServiceContext serviceContext, IAsyncResult asyncResult)
        {
            IEnumerable <TElement> result;

            try
            {
                IEnumerable <TElement>            enumerable             = serviceContext.EndExecute <TElement>(asyncResult);
                QueryOperationResponse <TElement> queryOperationResponse = enumerable as QueryOperationResponse <TElement>;
                if (queryOperationResponse != null && queryOperationResponse.Error != null)
                {
                    throw queryOperationResponse.Error;
                }
                result = enumerable;
            }
            catch (DataServiceQueryException)
            {
                throw;
            }
            finally
            {
                if (asyncResult is IDisposable)
                {
                    (asyncResult as IDisposable).Dispose();
                }
            }

            return(result);
        }
コード例 #4
0
            public void QueryFailureUsingContextExecuteAsync()
            {
                Uri baseUri    = ctx.BaseUri;
                Uri requestUri = new Uri(baseUri.OriginalString + "/Customers('VAR1')");

                try
                {
                    var q = ctx.EndExecute <northwindClient.Customers>(
                        ctx.BeginExecute <northwindClient.Customers>(requestUri, null, null));
                }
                catch (DataServiceQueryException ex)
                {
                    QueryOperationResponse response = ex.Response;
                    Utils.IsErrorResponse(response, HttpStatusCode.NotFound, false);
                    Assert.IsTrue(response.Query.RequestUri.Equals(requestUri), "expecting the same request uri");
                }
            }
コード例 #5
0
ファイル: Page.xaml.cs プロジェクト: zhonli/odata.net
        private void PollForTestWorkMessages(IAsyncResult asyncResult)
        {
            Message response = null;
            Message message  = null;

            try
            {
                DataServiceContext    asynchConnector = asyncResult.AsyncState as DataServiceContext;
                IEnumerable <Message> messages        = asynchConnector.EndExecute <Message>(asyncResult);
                message = messages.FirstOrDefault <Message>();

                SignalUI("PollingStatus", "Started");

                if (null != message && !processedMessages.Any <string>(pm => pm == message.MessageID.ToString()))
                {
                    processedMessages.Add(message.MessageID.ToString());

                    #region ClaimTest
                    //If the test is not claimed , then claim it .
                    //if (message.TestClientID.Length == 0)
                    //{
                    //    ClaimTest(message);
                    //}
                    //if (message.TestClientID.Length > 0 && message.TestClientID == ClientID)
                    //{
                    #endregion

                    SignalUI("MQConnectionStatus", "Pass");
                    response           = new Message();
                    response.WhoSentMe = "SL";
                    response.Method    = message.Method;
                    RemoteClient.Dispatch(message, response);
                    //}
                }
            }
            catch (Exception exception)
            {
                SignalUI("TestStatus", "Failed : " + exception.StackTrace.ToString());

                Message Response = new Message();
                Response.Method    = message.Method;
                Response.WhoSentMe = "SL";
                PushResponseToQueue(message, Response);

                //DataServiceContext dsc = GetServiceContext();
                //Message response2 = new Message();
                //response.ReturnValue = exception.ToString();
                //response.WhoSentMe = "SL";
                //response.Method = message.Method;
                //dsc.AddObject("Messages", response2);

                //dsc.BeginSaveChanges(PostTestWorkRespose, dsc);
            }
            finally
            {
            }
        }
コード例 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TResult"></typeparam>
 /// <param name="context"></param>
 /// <param name="requestUri"></param>
 /// <returns></returns>
 public static async Task <IEnumerable <TResult> > ExecuteAsync <TResult>(this DataServiceContext context, Uri requestUri)
 {
     return
         (await Task.Factory.FromAsync <IEnumerable <TResult> >(context.BeginExecute <TResult>(requestUri, null, null),
                                                                executeAsyncResult =>
     {
         List <TResult> executeResult = context.EndExecute <TResult>(executeAsyncResult).ToList();
         return executeResult;
     }));
 }
コード例 #7
0
        /// <summary>
        /// Asynchronously requests the next page of data in the results.
        /// </summary>
        /// <typeparam name="TResult">Entity type of the result of the execution.</typeparam>
        /// <param name="context">The <see cref="T:System.Data.Services.Client.DataServiceContext"/> instance on which this extension method is enabled. </param>
        /// <param name="requestUri">The URI of the query or operation that returns type <typeparam name="TResult"/>.</param>
        /// <param name="queryContinuationToken">A <see cref="T:System.Data.Services.Client.DataServiceQueryContinuation`1"/> token that is used to request the next page of data.</param>
        /// <returns>A <see cref="T:System.Threading.Tasks.Task`1"/> that, when completed, returns the results of the execution.</returns>
        public static async Task <IEnumerable <TResult> > ExecuteAsync <TResult>(this DataServiceContext context, DataServiceQueryContinuation <TResult> queryContinuationToken)
        {
            var queryTask = Task.Factory.FromAsync <IEnumerable <TResult> >(context.BeginExecute <TResult>(queryContinuationToken, null, null),
                                                                            (queryAsyncResult) =>
            {
                var results = context.EndExecute <TResult>(queryAsyncResult);
                return(results);
            });

            return(await queryTask);
        }
コード例 #8
0
        /// <summary>
        /// Asychronously executes a specific request URI.
        /// </summary>
        /// <typeparam name="TResult">Entity type of the result of the execution.</typeparam>
        /// <param name="context">The <see cref="T:System.Data.Services.Client.DataServiceContext"/> instance on which this extension method is enabled. </param>
        /// <param name="requestUri">The URI of the query or operation that returns type <typeparam name="TResult"/>.</param>
        /// <param name="operationParameters">An array of <see cref="T:System.Data.Services.Client.OperationParameter"/> objects that are parameters in the request URI.</param>
        /// <returns>A <see cref="T:System.Threading.Tasks.Task`1"/> that, when completed, returns the results of the execution.</returns>
        public static async Task <IEnumerable <TResult> > ExecuteAsync <TResult>(this DataServiceContext context, Uri requestUri,
                                                                                 params System.Data.Services.Client.OperationParameter[] operationParameters)
        {
            var queryTask = Task.Factory.FromAsync <IEnumerable <TResult> >(context.BeginExecute <TResult>(requestUri, null, null),
                                                                            (queryAsyncResult) =>
            {
                var results = context.EndExecute <TResult>(queryAsyncResult);
                return(results);
            });

            return(await queryTask);
        }
コード例 #9
0
        public static void ExecuteUri(this DataServiceContext context, IAsyncContinuation continuation, bool async, Uri requestUri, HttpVerb verb, OperationParameter[] inputParameters, Action <OperationResponse> onCompletion)
        {
            ExceptionUtilities.CheckArgumentNotNull(context, "context");
            ExceptionUtilities.CheckArgumentNotNull(continuation, "continuation");
            ExceptionUtilities.CheckArgumentNotNull(onCompletion, "onCompletion");

            string method = Enum.GetName(typeof(HttpVerb), verb).ToUpperInvariant();

            AsyncHelpers.InvokeSyncOrAsyncMethodCall <OperationResponse>(
                continuation,
                async,
                () => context.Execute(requestUri, method, inputParameters),
                c => context.BeginExecute(requestUri, c, null, method, inputParameters),
                r => context.EndExecute(r),
                onCompletion);
        }
コード例 #10
0
ファイル: Page.xaml.cs プロジェクト: zhonli/odata.net
 public void MQCOnnectionCallback(IAsyncResult asynchResult)
 {
     try
     {
         DataServiceContext testDataContext = asynchResult.AsyncState as DataServiceContext;
         var messages = testDataContext.EndExecute <TestSL.Message>(asynchResult);
         if (messages.Count <TestSL.Message>() >= 0)
         {
             SignalUI("MQConnectionStatus", "Pass");
         }
     }
     catch (Exception exception)
     {
         SignalUI("MQConnectionStatus", "Fail with " + exception.Message);
     }
 }
コード例 #11
0
 public IEnumerable <T> EndExecute(IAsyncResult asyncResult)
 {
     Util.CheckArgumentNull(asyncResult, "asyncResult");
     return(Context.EndExecute <T>(asyncResult));
 }
コード例 #12
0
 /// <summary>Called to complete the <see cref="Microsoft.OData.Client.DataServiceActionQuery.BeginExecute(System.AsyncCallback,System.Object)" />.</summary>
 /// <returns>The result of the operation.</returns>
 /// <param name="asyncResult">An <see cref="System.IAsyncResult" /> that represents the status of the asynchronous operation.</param>
 /// <remarks>This method should be used in combination with the BeginExecute overload which
 /// expects the request uri to end with an action that returns void.</remarks>
 public OperationResponse EndExecute(IAsyncResult asyncResult)
 {
     return(Context.EndExecute(asyncResult));
 }
コード例 #13
0
 /// <summary>
 /// Extension method to perform sync/async version of DataServiceContext.Execute dynamically
 /// </summary>
 /// <typeparam name="TElement">The element type of the expression results</typeparam>
 /// <param name="context">The context to call execute on</param>
 /// <param name="continuation">The asynchronous continuation</param>
 /// <param name="async">A value indicating whether or not to use async API</param>
 /// <param name="requestUri">The uri to make a request to</param>
 /// <param name="onCompletion">A callback for when the call completes</param>
 public static void Execute <TElement>(this DataServiceContext context, IAsyncContinuation continuation, bool async, Uri requestUri, Action <IEnumerable <TElement> > onCompletion)
 {
     ExceptionUtilities.CheckArgumentNotNull(context, "context");
     AsyncHelpers.InvokeSyncOrAsyncMethodCall <IEnumerable <TElement> >(continuation, async, () => context.Execute <TElement>(requestUri), c => context.BeginExecute <TElement>(requestUri, c, null), r => context.EndExecute <TElement>(r), onCompletion);
 }
コード例 #14
0
 public T EndGetValue(IAsyncResult asyncResult)
 {
     Util.CheckArgumentNull(asyncResult, "asyncResult");
     return(context.EndExecute <T>(asyncResult).Single());
 }