示例#1
0
        /// <summary>
        ///		Processes asynchronous operation completion logic.
        /// </summary>
        /// <param name="context">The response context which holds response data.</param>
        /// <param name="exception">The exception occured.</param>
        /// <param name="completedSynchronously">When operation is completed same thread as initiater then <c>true</c>; otherwise, <c>false</c>.</param>
        public void OnCompleted(ClientResponseContext context, Exception exception, bool completedSynchronously)
        {
            if (exception != null)
            {
                base.OnError(exception, completedSynchronously);
            }
            else
            {
                var error = ErrorInterpreter.UnpackError(context);
                if (!error.IsSuccess)
                {
                    base.OnError(error.ToException(), completedSynchronously);
                }
                else
                {
                    Interlocked.CompareExchange(ref this._result, new ResultHolder(Unpacking.UnpackObject(context.ResultBuffer)), null);
                    base.Complete(completedSynchronously);
                }
            }

            var callback = this.AsyncCallback;

            if (callback != null)
            {
                callback(this);
            }
        }
        public void TestUnpackError_RoundTripped()
        {
            var detail  = Guid.NewGuid().ToString();
            var message = new RpcErrorMessage(RpcError.CallError, detail);
            var context = CreateContext(message);
            var result  = ErrorInterpreter.UnpackError(context);

            Assert.That(message == result, result.ToString());
        }