Ejemplo n.º 1
0
        /// <summary>
        /// Submit the specified <see cref="EntityChangeSet"/> to the DomainService, with the results of the operation
        /// being returned on the SubmitCompleted event args.
        /// </summary>
        /// <param name="changeSet">The changeset to submit. If the changeset is empty, an <see cref="InvalidOperationException"/> will
        /// be thrown.</param>
        /// <param name="cancellationToken"><see cref="CancellationToken"/> to be used for requesting cancellation</param>
        /// <returns>The results returned by the submit request.</returns>
        /// <exception cref="InvalidOperationException">The changeset is empty.</exception>
        protected override Task <SubmitCompletedResult> SubmitAsyncCore(EntityChangeSet changeSet, CancellationToken cancellationToken)
        {
            IEnumerable <ChangeSetEntry> submitOperations = changeSet.GetChangeSetEntries();

            TContract channel = this.ChannelFactory.CreateChannel();

            return(CallServiceOperation <SubmitCompletedResult>(channel,
                                                                "SubmitChanges",
                                                                new Dictionary <string, object>()
            {
                { "changeSet", submitOperations }
            },
                                                                (state, asyncResult) =>
            {
                try
                {
                    var returnValue = (IEnumerable <ChangeSetEntry>)EndServiceOperationCall(state, asyncResult);
                    return new SubmitCompletedResult(changeSet, returnValue ?? Enumerable.Empty <ChangeSetEntry>());
                }
                catch (FaultException <DomainServiceFault> fe)
                {
                    throw WebDomainClient <TContract> .GetExceptionFromServiceFault(fe.Detail);
                }
            }, cancellationToken));
        }
 /// <summary>
 /// Invokes an operation asynchronously.
 /// </summary>
 /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
 /// <param name="cancellationToken"><see cref="CancellationToken"/> to be used for requesting cancellation</param>
 /// <returns>The results returned by the invocation.</returns>
 /// <exception cref="InvalidOperationException">The specified query does not exist.</exception>
 protected override Task <InvokeCompletedResult> InvokeAsyncCore(InvokeArgs invokeArgs, CancellationToken cancellationToken)
 {
     return(CallServiceOperation(invokeArgs.OperationName,
                                 invokeArgs.Parameters,
                                 (asyncResult) =>
     {
         IEnumerable <ValidationResult> validationErrors = null;
         object returnValue = null;
         try
         {
             returnValue = EndServiceOperationCall(this.ChannelFactory, asyncResult);
         }
         catch (FaultException <DomainServiceFault> fe)
         {
             if (fe.Detail.OperationErrors != null)
             {
                 validationErrors = fe.Detail.GetValidationErrors();
             }
             else
             {
                 throw WebDomainClient <TContract> .GetExceptionFromServiceFault(fe.Detail);
             }
         }
         return new InvokeCompletedResult(returnValue, validationErrors ?? Enumerable.Empty <ValidationResult>());
     },
                                 cancellationToken));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the results of a submit.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies a submit.</param>
        /// <returns>The results returned by the submit.</returns>
        protected sealed override SubmitCompletedResult EndSubmitCore(IAsyncResult asyncResult)
        {
            WebDomainClientAsyncResult <TContract> wcfAsyncResult = this.EndAsyncResult(asyncResult, AsyncOperationType.Submit, /* cancel */ false);
            MethodInfo      endSubmitMethod = wcfAsyncResult.EndOperationMethod;
            EntityChangeSet changeSet       = wcfAsyncResult.EntityChangeSet;

            IEnumerable <ChangeSetEntry> returnValue;

            try
            {
                try
                {
                    returnValue = (IEnumerable <ChangeSetEntry>)endSubmitMethod.Invoke(wcfAsyncResult.Channel, new object[] { wcfAsyncResult.InnerAsyncResult });
                }
                catch (TargetInvocationException tie)
                {
                    if (tie.InnerException != null)
                    {
                        throw tie.InnerException;
                    }

                    throw;
                }
                finally
                {
                    ((IChannel)wcfAsyncResult.Channel).Close();
                }
            }
            catch (FaultException <DomainServiceFault> fe)
            {
                throw WebDomainClient <TContract> .GetExceptionFromServiceFault(fe.Detail);
            }

            return(new SubmitCompletedResult(changeSet, returnValue ?? Enumerable.Empty <ChangeSetEntry>()));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method called by the framework to begin an asynchronous query operation
        /// </summary>
        /// <param name="query">The query to invoke.</param>
        /// <param name="cancellationToken"><see cref="CancellationToken"/> to be used for requesting cancellation</param>
        /// <returns>The results returned by the query.</returns>
        /// <exception cref="InvalidOperationException">The specified query does not exist.</exception>
        protected override Task <QueryCompletedResult> QueryAsyncCore(EntityQuery query, CancellationToken cancellationToken)
        {
            TContract channel = this.ChannelFactory.CreateChannel();

            // Pass the query as a message property.
            using (OperationContextScope scope = new OperationContextScope((IContextChannel)channel))
            {
                if (query.Query != null)
                {
                    OperationContext.Current.OutgoingMessageProperties.Add(WebDomainClient <object> .QueryPropertyName, query.Query);
                }
                if (query.IncludeTotalCount)
                {
                    OperationContext.Current.OutgoingMessageProperties.Add(WebDomainClient <object> .IncludeTotalCountPropertyName, true);
                }

                return(CallServiceOperation <QueryCompletedResult>(channel,
                                                                   query.QueryName,
                                                                   query.Parameters,
                                                                   (state, asyncResult) =>
                {
                    IEnumerable <ValidationResult> validationErrors = null;
                    QueryResult returnValue = null;
                    try
                    {
                        returnValue = (QueryResult)EndServiceOperationCall(state, asyncResult);
                    }
                    catch (FaultException <DomainServiceFault> fe)
                    {
                        if (fe.Detail.OperationErrors != null)
                        {
                            validationErrors = fe.Detail.GetValidationErrors();
                        }
                        else
                        {
                            throw WebDomainClient <TContract> .GetExceptionFromServiceFault(fe.Detail);
                        }
                    }

                    if (returnValue != null)
                    {
                        return new QueryCompletedResult(
                            returnValue.GetRootResults().Cast <Entity>(),
                            returnValue.GetIncludedResults().Cast <Entity>(),
                            returnValue.TotalCount,
                            Enumerable.Empty <ValidationResult>());
                    }
                    else
                    {
                        return new QueryCompletedResult(
                            Enumerable.Empty <Entity>(),
                            Enumerable.Empty <Entity>(),
                            /* totalCount */ 0,
                            validationErrors ?? Enumerable.Empty <ValidationResult>());
                    }
                }
                                                                   , cancellationToken));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the results of a query.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies a query.</param>
        /// <returns>The results returned by the query.</returns>
        protected sealed override QueryCompletedResult EndQueryCore(IAsyncResult asyncResult)
        {
            WebDomainClientAsyncResult <TContract> wcfAsyncResult = this.EndAsyncResult(asyncResult, AsyncOperationType.Query, /* cancel */ false);
            MethodInfo endQueryMethod = (MethodInfo)wcfAsyncResult.EndOperationMethod;

            IEnumerable <ValidationResult> validationErrors = null;
            QueryResult returnValue = null;

            try
            {
                try
                {
                    returnValue = (QueryResult)endQueryMethod.Invoke(wcfAsyncResult.Channel, new object[] { wcfAsyncResult.InnerAsyncResult });
                }
                catch (TargetInvocationException tie)
                {
                    if (tie.InnerException != null)
                    {
                        throw tie.InnerException;
                    }

                    throw;
                }
                finally
                {
                    ((IChannel)wcfAsyncResult.Channel).Close();
                }
            }
            catch (FaultException <DomainServiceFault> fe)
            {
                if (fe.Detail.OperationErrors != null)
                {
                    validationErrors = fe.Detail.GetValidationErrors();
                }
                else
                {
                    throw WebDomainClient <TContract> .GetExceptionFromServiceFault(fe.Detail);
                }
            }

            if (returnValue != null)
            {
                return(new QueryCompletedResult(
                           returnValue.GetRootResults().Cast <Entity>(),
                           returnValue.GetIncludedResults().Cast <Entity>(),
                           returnValue.TotalCount,
                           Enumerable.Empty <ValidationResult>()));
            }
            else
            {
                return(new QueryCompletedResult(
                           new Entity[0],
                           new Entity[0],
                           /* totalCount */ 0,
                           validationErrors ?? Enumerable.Empty <ValidationResult>()));
            }
        }
        /// <summary>
        /// Method called by the framework to begin an asynchronous query operation
        /// </summary>
        /// <param name="query">The query to invoke.</param>
        /// <param name="cancellationToken"><see cref="CancellationToken"/> to be used for requesting cancellation</param>
        /// <returns>The results returned by the query.</returns>
        /// <exception cref="InvalidOperationException">The specified query does not exist.</exception>
        protected override Task <QueryCompletedResult> QueryAsyncCore(EntityQuery query, CancellationToken cancellationToken)
        {
            return(CallServiceOperation <QueryCompletedResult>(query.QueryName,
                                                               query.Parameters,
                                                               (asyncResult) =>
            {
                IEnumerable <ValidationResult> validationErrors = null;
                QueryResult returnValue = null;
                try
                {
                    returnValue = (QueryResult)EndServiceOperationCall(this.ChannelFactory, asyncResult);
                }
                catch (FaultException <DomainServiceFault> fe)
                {
                    if (fe.Detail.OperationErrors != null)
                    {
                        validationErrors = fe.Detail.GetValidationErrors();
                    }
                    else
                    {
                        throw WebDomainClient <TContract> .GetExceptionFromServiceFault(fe.Detail);
                    }
                }

                if (returnValue != null)
                {
                    return new QueryCompletedResult(
                        returnValue.GetRootResults().Cast <Entity>(),
                        returnValue.GetIncludedResults().Cast <Entity>(),
                        returnValue.TotalCount,
                        Enumerable.Empty <ValidationResult>());
                }
                else
                {
                    return new QueryCompletedResult(
                        Enumerable.Empty <Entity>(),
                        Enumerable.Empty <Entity>(),
                        /* totalCount */ 0,
                        validationErrors ?? Enumerable.Empty <ValidationResult>());
                }
            }
                                                               , cancellationToken));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the results of an invocation.
        /// </summary>
        /// <param name="asyncResult">An asynchronous result that identifies an invocation.</param>
        /// <returns>The results returned by the invocation.</returns>
        protected sealed override InvokeCompletedResult EndInvokeCore(IAsyncResult asyncResult)
        {
            WebDomainClientAsyncResult <TContract> wcfAsyncResult = this.EndAsyncResult(asyncResult, AsyncOperationType.Invoke, /* cancel */ false);
            MethodInfo endInvokeMethod = (MethodInfo)wcfAsyncResult.EndOperationMethod;

            IEnumerable <ValidationResult> validationErrors = null;
            object returnValue = null;

            try
            {
                try
                {
                    returnValue = endInvokeMethod.Invoke(wcfAsyncResult.Channel, new object[] { wcfAsyncResult.InnerAsyncResult });
                }
                catch (TargetInvocationException tie)
                {
                    if (tie.InnerException != null)
                    {
                        throw tie.InnerException;
                    }

                    throw;
                }
                finally
                {
                    ((IChannel)wcfAsyncResult.Channel).Close();
                }
            }
            catch (FaultException <DomainServiceFault> fe)
            {
                if (fe.Detail.OperationErrors != null)
                {
                    validationErrors = fe.Detail.GetValidationErrors();
                }
                else
                {
                    throw WebDomainClient <TContract> .GetExceptionFromServiceFault(fe.Detail);
                }
            }

            return(new InvokeCompletedResult(returnValue, validationErrors ?? Enumerable.Empty <ValidationResult>()));
        }