/// <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)); }
/// <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); }); }
void dispatchTimer_Tick(object sender, EventArgs e) { DataServiceContext AstoriaTestService = null; AstoriaTestService = GetServiceContext(); AstoriaTestService.BeginExecute <Message>(MessagesUri, PollForTestWorkMessages, AstoriaTestService); }
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"); } }
public static Task <OperationResponse> ExecuteAsync(this DataServiceContext self, Uri uri, string httpMethod, params OperationParameter[] operationParameters) { IAsyncResult asyncResult = self.BeginExecute(uri, null, null, httpMethod, operationParameters); return(Task <OperationResponse> .Factory.FromAsync( asyncResult, self.EndExecute)); }
public static Task <IEnumerable <TElement> > ExecuteAsync <TElement>(this DataServiceContext self, Uri uri, string httpMethod, bool singleResult, params OperationParameter[] operationParameters) { IAsyncResult asyncResult = self.BeginExecute <TElement>(uri, null, null, httpMethod, singleResult, operationParameters); return(Task <IEnumerable <TElement> > .Factory.FromAsync( asyncResult, self.EndExecute <TElement>)); }
/// <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; })); }
/// <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); }
/// <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); }
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); }
public IAsyncResult BeginExecute(AsyncCallback callback, object state) { return(Context.BeginExecute <T>(this.RequestUri, callback, state, XmlConstants.HttpMethodPost, false, Parameters)); }
/// <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); }
private void TestMQConnection() { DataServiceContext testDataContext = GetServiceContext(); testDataContext.BeginExecute <TestSL.Message>(new Uri("Messages", UriKind.RelativeOrAbsolute), MQCOnnectionCallback, testDataContext); }