Ejemplo n.º 1
0
        /// <summary>
        /// Invokes an operation asynchronously.
        /// </summary>
        /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
        /// <param name="callback">The callback to invoke when the invocation has been completed.</param>
        /// <param name="userState">Optional user state associated with this operation.</param>
        /// <returns>An asynchronous result that identifies this invocation.</returns>
        public IAsyncResult BeginInvoke(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
        {
            if (invokeArgs == null)
            {
                throw new ArgumentNullException("invokeArgs");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            DomainClientAsyncResult domainClientResult = DomainClientAsyncResult.CreateInvokeResult(this, invokeArgs, callback, userState);

            domainClientResult.InnerAsyncResult = this.BeginInvokeCore(
                invokeArgs,
                delegate(IAsyncResult result)
            {
                DomainClientAsyncResult clientResult = (DomainClientAsyncResult)result.AsyncState;
                clientResult.InnerAsyncResult        = result;
                clientResult.Complete();
            },
                domainClientResult);

            return(domainClientResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes an asynchronous query operation.
        /// </summary>
        /// <param name="query">The query to invoke.</param>
        /// <param name="callback">The callback to invoke when the query has been executed.</param>
        /// <param name="userState">Optional user state associated with this operation.</param>
        /// <returns>An asynchronous result that identifies this query.</returns>
        /// <remarks>
        /// Queries with side-effects may be invoked differently. For example, clients that invoke a DomainService
        /// over HTTP may use POST requests for queries with side-effects, while GET may be used otherwise.
        /// </remarks>
        public IAsyncResult BeginQuery(EntityQuery query, AsyncCallback callback, object userState)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            DomainClientAsyncResult domainClientResult = DomainClientAsyncResult.CreateQueryResult(this, callback, userState);

            domainClientResult.InnerAsyncResult = this.BeginQueryCore(
                query,
                delegate(IAsyncResult result)
            {
                DomainClientAsyncResult clientResult = (DomainClientAsyncResult)result.AsyncState;
                clientResult.InnerAsyncResult        = result;
                clientResult.Complete();
            },
                domainClientResult);

            return(domainClientResult);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Submits the specified <see cref="EntityChangeSet"/> to the DomainService asynchronously.
        /// </summary>
        /// <param name="changeSet">The <see cref="EntityChangeSet"/> to submit to the DomainService.</param>
        /// <param name="callback">The callback to invoke when the submit has been executed.</param>
        /// <param name="userState">Optional user state associated with this operation.</param>
        /// <returns>An asynchronous result that identifies this submit request.</returns>
        public IAsyncResult BeginSubmit(EntityChangeSet changeSet, AsyncCallback callback, object userState)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if (changeSet == null)
            {
                throw new ArgumentNullException("changeSet");
            }

            if (changeSet.IsEmpty)
            {
                throw new InvalidOperationException(OpenRiaServices.DomainServices.Client.Resource.DomainClient_EmptyChangeSet);
            }

            DomainClientAsyncResult domainClientResult = DomainClientAsyncResult.CreateSubmitResult(this, changeSet, callback, userState);

            // call the actual implementation asynchronously
            domainClientResult.InnerAsyncResult = this.BeginSubmitCore(
                changeSet,
                delegate(IAsyncResult result)
            {
                DomainClientAsyncResult clientResult = (DomainClientAsyncResult)result.AsyncState;
                clientResult.InnerAsyncResult        = result;
                clientResult.Complete();
            },
                domainClientResult);

            return(domainClientResult);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to cancel the invocation request specified by the <paramref name="asyncResult"/>.
        /// </summary>
        /// <param name="asyncResult">An <see cref="IAsyncResult"/> specifying what invocation operation to cancel.</param>
        /// <exception cref="ArgumentNullException"> if <paramref name="asyncResult"/> is null.</exception>
        /// <exception cref="ArgumentException"> if <paramref name="asyncResult"/> is for another operation or was not created by this <see cref="DomainClient"/> instance.</exception>
        /// <exception cref="InvalidOperationException"> if the operation associated with <paramref name="asyncResult"/> has been canceled.</exception>
        /// <exception cref="InvalidOperationException"> if the operation associated with <paramref name="asyncResult"/> has completed.</exception>
        public void CancelInvoke(IAsyncResult asyncResult)
        {
            this.VerifyCancellationSupport();

            DomainClientAsyncResult domainClientResult = this.EndAsyncResult(asyncResult, AsyncOperationType.Invoke, true /* cancel */);

            this.CancelInvokeCore(domainClientResult.InnerAsyncResult);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Transitions an <see cref="IAsyncResult"/> instance to a completed state.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies an invocation.</param>
        /// <param name="operationType">The expected operation type.</param>
        /// <param name="cancel">Boolean indicating whether or not the operation has been canceled.</param>
        /// <returns>A <see cref="DomainClientAsyncResult"/> reference.</returns>
        /// <exception cref="ArgumentNullException"> if <paramref name="asyncResult"/> is null.</exception>
        /// <exception cref="ArgumentException"> if <paramref name="asyncResult"/> is for another operation or was not created by this <see cref="DomainClient"/> instance.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/> has been canceled.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/>'s End* method has already been invoked.</exception>
        /// <exception cref="InvalidOperationException"> if <paramref name="asyncResult"/> has not completed.</exception>
        private DomainClientAsyncResult EndAsyncResult(IAsyncResult asyncResult, AsyncOperationType operationType, bool cancel)
        {
            DomainClientAsyncResult domainClientResult = asyncResult as DomainClientAsyncResult;

            if ((domainClientResult != null) && (!object.ReferenceEquals(this, domainClientResult.DomainClient) || domainClientResult.AsyncOperationType != operationType))
            {
                throw new ArgumentException(Resources.WrongAsyncResult, "asyncResult");
            }

            return(AsyncResultBase.EndAsyncOperation <DomainClientAsyncResult>(asyncResult, cancel));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the results of a submit request.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies a submit request.</param>
        /// <returns>The results returned by the submit request.</returns>
        public SubmitCompletedResult EndSubmit(IAsyncResult asyncResult)
        {
            DomainClientAsyncResult domainClientResult = this.EndAsyncResult(asyncResult, AsyncOperationType.Submit, false /* cancel */);
            SubmitCompletedResult   submitResults      = this.EndSubmitCore(domainClientResult.InnerAsyncResult);

            // correlate the operation results back to their actual client entity references
            Dictionary <int, Entity> submittedEntities = domainClientResult.EntityChangeSet.GetChangeSetEntries().ToDictionary(p => p.Id, p => p.Entity);

            foreach (ChangeSetEntry op in submitResults.Results)
            {
                op.ClientEntity = submittedEntities[op.Id];
            }

            return(submitResults);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Completes an operation invocation.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies an invocation.</param>
        /// <returns>The results returned by the invocation.</returns>
        public InvokeCompletedResult EndInvoke(IAsyncResult asyncResult)
        {
            DomainClientAsyncResult domainClientResult = this.EndAsyncResult(asyncResult, AsyncOperationType.Invoke, false /* cancel */);

            return(this.EndInvokeCore(domainClientResult.InnerAsyncResult));
        }