/// <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));
 }
Example #2
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);
        }
        /// <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 that will be passed through on the <see cref="InvokeCompletedResult"/>.</param>
        /// <returns>An asynchronous result that identifies this invocation.</returns>
        /// <exception cref="InvalidOperationException">The specified query does not exist.</exception>
        protected sealed override IAsyncResult BeginInvokeCore(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
        {
            MethodInfo beginInvokeMethod = WebDomainClient <TContract> .ResolveBeginMethod(invokeArgs.OperationName);

            MethodInfo endInvokeMethod = WebDomainClient <TContract> .ResolveEndMethod(invokeArgs.OperationName);

            // Pass operation parameters.
            ParameterInfo[] parameterInfos  = beginInvokeMethod.GetParameters();
            object[]        realParameters  = new object[parameterInfos.Length];
            int             parametersCount = (invokeArgs.Parameters == null) ? 0 : invokeArgs.Parameters.Count;

            for (int i = 0; i < parametersCount; i++)
            {
                realParameters[i] = invokeArgs.Parameters[parameterInfos[i].Name];
            }

            TContract channel = this.ChannelFactory.CreateChannel();
            WebDomainClientAsyncResult <TContract> wcfAsyncResult = WebDomainClientAsyncResult <TContract> .CreateInvokeResult(this, channel, endInvokeMethod, invokeArgs, callback, userState);

            // Pass async operation related parameters.
            realParameters[parameterInfos.Length - 2] = new AsyncCallback(delegate(IAsyncResult asyncResponseResult)
            {
                wcfAsyncResult.InnerAsyncResult = asyncResponseResult;
                wcfAsyncResult.Complete();
            });
            realParameters[parameterInfos.Length - 1] = userState;

            IAsyncResult asyncResult;

            try
            {
                asyncResult = (IAsyncResult)beginInvokeMethod.Invoke(channel, realParameters);
            }
            catch (TargetInvocationException tie)
            {
                if (tie.InnerException != null)
                {
                    throw tie.InnerException;
                }

                throw;
            }

            if (!asyncResult.CompletedSynchronously)
            {
                wcfAsyncResult.InnerAsyncResult = asyncResult;
            }
            return(wcfAsyncResult);
        }
Example #4
0
        /// <summary>
        /// Initializes a new <see cref="DomainClientAsyncResult"/> instance used for Invoke operations.
        /// </summary>
        /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
        /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
        /// <param name="callback">The <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        protected DomainClientAsyncResult(DomainClient domainClient, InvokeArgs invokeArgs, AsyncCallback callback, object asyncState)
            : base(callback, asyncState)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }
            if (invokeArgs == null)
            {
                throw new ArgumentNullException("invokeArgs");
            }

            this._asyncOperationType = AsyncOperationType.Invoke;
            this._domainClient       = domainClient;
            this._invokeArgs         = invokeArgs;
        }
Example #5
0
 /// <summary>
 /// Creates a new <see cref="DomainClientAsyncResult"/> used for Invoke operations.
 /// </summary>
 /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
 /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
 /// <param name="callback">The <see cref="AsyncCallback"/> to invoke upon completion.</param>
 /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
 /// <returns>A <see cref="DomainClientAsyncResult"/> used for Invoke operations</returns>
 public static DomainClientAsyncResult CreateInvokeResult(DomainClient domainClient, InvokeArgs invokeArgs, AsyncCallback callback, object asyncState)
 {
     return(new DomainClientAsyncResult(domainClient, invokeArgs, callback, asyncState));
 }
        /// <summary>
        /// Initializes a new <see cref="DomainClientAsyncResult"/> instance used for Invoke operations.
        /// </summary>
        /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
        /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
        /// <param name="callback">The <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        protected DomainClientAsyncResult(DomainClient domainClient, InvokeArgs invokeArgs, AsyncCallback callback, object asyncState)
            : base(callback, asyncState)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }
            if (invokeArgs == null)
            {
                throw new ArgumentNullException("invokeArgs");
            }

            this._asyncOperationType = AsyncOperationType.Invoke;
            this._domainClient = domainClient;
            this._invokeArgs = invokeArgs;
        }
        /// <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;
        }
 /// <summary>
 /// Method called by the framework to begin an Invoke operation asynchronously. Overrides
 /// should not call the base method.
 /// </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>
 protected virtual IAsyncResult BeginInvokeCore(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
 {
     throw new NotSupportedException();
 }
Example #9
0
 /// <summary>
 /// Invokes an operation asynchronously.
 /// </summary>
 /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
 /// <param name="cancellationToken"><see cref="CancellationToken"/> which may be used to request cancellation</param>
 /// <returns>The results returned by the invocation.</returns>
 public Task <InvokeCompletedResult> InvokeAsync(InvokeArgs invokeArgs, CancellationToken cancellationToken) => InvokeAsyncCore(invokeArgs, cancellationToken);
 protected override IAsyncResult BeginInvokeCore(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
 {
     return null;
 }
 /// <summary>
 /// Creates a new <see cref="WebDomainClientAsyncResult&lt;TContract&gt;"/> used for Invoke operations.
 /// </summary>
 /// <param name="domainClient">The <see cref="WebDomainClient&lt;TContract&gt;"/> associated with this result.</param>
 /// <param name="channel">The channel used to communicate with the server.</param>
 /// <param name="endOperationMethod">The method that completes an asynchronous operation.</param>
 /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
 /// <param name="callback">The <see cref="AsyncCallback"/> to invoke upon completion.</param>
 /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
 /// <returns>A <see cref="WebDomainClientAsyncResult&lt;TContract&gt;"/> used for Invoke operations</returns>
 public static WebDomainClientAsyncResult <TContract> CreateInvokeResult(WebDomainClient <TContract> domainClient, TContract channel, MethodInfo endOperationMethod, InvokeArgs invokeArgs, AsyncCallback callback, object asyncState)
 {
     return(new WebDomainClientAsyncResult <TContract>(domainClient, channel, endOperationMethod, invokeArgs, callback, asyncState));
 }
        /// <summary>
        /// Initializes a new <see cref="WebDomainClientAsyncResult&lt;TContract&gt;"/> instance used for Invoke operations.
        /// </summary>
        /// <param name="domainClient">The <see cref="WebDomainClient&lt;TContract&gt;"/> associated with this result.</param>
        /// <param name="channel">The channel used to communicate with the server.</param>
        /// <param name="endOperationMethod">The method that completes an asynchronous operation.</param>
        /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
        /// <param name="callback">Optional <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        /// <exception cref="ArgumentNullException">if <paramref name="endOperationMethod"/> is null.</exception>
        private WebDomainClientAsyncResult(WebDomainClient <TContract> domainClient, TContract channel, MethodInfo endOperationMethod, InvokeArgs invokeArgs, AsyncCallback callback, object asyncState)
            : base(domainClient, invokeArgs, callback, asyncState)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

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

            this._endOperationMethod = endOperationMethod;
            this._channel            = channel;
        }
Example #13
0
 /// <summary>
 /// Method called by the framework to begin an Invoke operation asynchronously. Overrides
 /// should not call the base method.
 /// </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>
 protected virtual IAsyncResult BeginInvokeCore(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
 {
     throw new NotSupportedException();
 }
 /// <summary>
 /// Creates a new <see cref="DomainClientAsyncResult"/> used for Invoke operations.
 /// </summary>
 /// <param name="domainClient">The associated <see cref="DomainClient"/>.</param>
 /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
 /// <param name="callback">The <see cref="AsyncCallback"/> to invoke upon completion.</param>
 /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
 /// <returns>A <see cref="DomainClientAsyncResult"/> used for Invoke operations</returns>
 public static DomainClientAsyncResult CreateInvokeResult(DomainClient domainClient, InvokeArgs invokeArgs, AsyncCallback callback, object asyncState)
 {
     return new DomainClientAsyncResult(domainClient, invokeArgs, callback, asyncState);
 }
        protected override IAsyncResult BeginInvokeCore(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
        {
            MockAsyncResult ar = new MockAsyncResult(null, userState, new object[] { invokeArgs.OperationName, invokeArgs.ReturnType, invokeArgs.Parameters, userState });

            // do the invoke and get the return value
            if (invokeArgs.OperationName == "Echo")
            {
                ar.ReturnValue = "Echo: " + (string)invokeArgs.Parameters.Values.First();
            }

            callback.Invoke(ar);

            return ar;
        }
        public void TestMockClientReturnsNull()
        {
            NullReturningMockDomainClient dc = new NullReturningMockDomainClient();

            AsyncCallback ignored = delegate { };

            InvokeArgs invokeArgs = new InvokeArgs("M", typeof(void), null, true /*hasSideEffects*/);
            DomainClientAsyncResult result = (DomainClientAsyncResult)dc.BeginInvoke(invokeArgs, ignored, null);

            EnqueueConditional(() => result != null);

            EnqueueCallback(delegate
            {
                Assert.IsNull(result.InnerAsyncResult);

                ExceptionHelper.ExpectArgumentNullException(
                () => dc.EndInvoke(result.InnerAsyncResult),
                "asyncResult");

                result = null;
                result = (DomainClientAsyncResult)dc.BeginQuery(new EntityQuery<Entity>(dc, "GetIgnored", null, true, false), ignored, null);
            });

            EnqueueConditional(() => result != null);

            EnqueueCallback(delegate
            {
                Assert.IsNull(result.InnerAsyncResult);

                ExceptionHelper.ExpectArgumentNullException(
                    () => dc.EndQuery(result.InnerAsyncResult),
                    "asyncResult");

                List<Entity> list = new List<Entity>();
                list.Add(new Product());
                ReadOnlyCollection<Entity> simpleCollection = new ReadOnlyCollection<Entity>(list);
                ReadOnlyCollection<Entity> emptyCollection = new ReadOnlyCollection<Entity>(new List<Entity>());
                EntityChangeSet emptyChangeSet = new EntityChangeSet(simpleCollection, emptyCollection, emptyCollection);
                result = null;
                result = (DomainClientAsyncResult)dc.BeginSubmit(emptyChangeSet, ignored, null);
            });

            EnqueueConditional(() => result != null);

            EnqueueCallback(delegate
            {
                Assert.IsNull(result.InnerAsyncResult);

                ExceptionHelper.ExpectArgumentNullException(
                    () => dc.EndSubmit(result.InnerAsyncResult),
                    "asyncResult");
            });

            EnqueueTestComplete();
        }
Example #17
0
 /// <summary>
 /// Method called by the framework to begin an Invoke operation asynchronously. Overrides
 /// should not call the base method.
 /// </summary>
 /// <param name="invokeArgs">The arguments to the Invoke operation.</param>
 /// <param name="cancellationToken"><see cref="CancellationToken"/> which may be used to request cancellation</param>
 /// <returns>The results returned by the invocation.</returns>
 protected abstract Task <InvokeCompletedResult> InvokeAsyncCore(InvokeArgs invokeArgs, CancellationToken cancellationToken);