コード例 #1
0
		public void TestOnCompleted_CompletedSynchronouly_True_SetTrue()
		{
			object owner = new object();
			var target = new NotificationMessageAsyncResult( owner, null, null );
			target.OnCompleted( null, true );
			Assert.That( ( target as IAsyncResult ).CompletedSynchronously, Is.True );
		}
コード例 #2
0
        public void TestConstructor_MessageIsNull()
        {
            var owner  = new object();
            var target = new NotificationMessageAsyncResult(owner, null, null);

            Assert.That(target.MessageId, Is.Null);
        }
コード例 #3
0
		public void TestOnCompleted_ErrorIsSet()
		{
			object owner = new object();
			var target = new NotificationMessageAsyncResult( owner, null, null );
			var error = new Exception();
			target.OnCompleted( error, false );
			Assert.That( target.Error, Is.SameAs( error ) );
		}
コード例 #4
0
        public void TestOnCompleted_CompletedSynchronouly_True_SetTrue()
        {
            object owner  = new object();
            var    target = new NotificationMessageAsyncResult(owner, null, null);

            target.OnCompleted(null, true);
            Assert.That((target as IAsyncResult).CompletedSynchronously, Is.True);
        }
コード例 #5
0
        public void TestOnCompleted_ErrorIsSet()
        {
            object owner  = new object();
            var    target = new NotificationMessageAsyncResult(owner, null, null);
            var    error  = new Exception();

            target.OnCompleted(error, false);
            Assert.That(target.Error, Is.SameAs(error));
        }
コード例 #6
0
        /// <summary>
        ///		Sends specified remote method with specified argument as notification message asynchronously.
        /// </summary>
        /// <param name="methodName">
        ///		The name of target method.
        /// </param>
        /// <param name="arguments">
        ///		Argument to be passed to the server.
        ///		All values must be able to be serialized with MessagePack serializer.
        /// </param>
        /// <param name="asyncCallback">
        ///		The callback method invoked when the notification is sent or the reponse is received.
        ///		This value can be <c>null</c>.
        ///		Usually this callback get the result of invocation via <see cref="EndNotify"/>.
        /// </param>
        /// <param name="asyncState">
        ///		User supplied state object which can be gotten via <see cref="IAsyncResult.AsyncState"/> in the <paramref name="asyncCallback"/> callback.
        ///		This value can be <c>null</c>.
        /// </param>
        /// <returns>
        ///		An <see cref="IAsyncResult" /> which can be passed to <see cref="EndNotify"/> method.
        ///		Usually, this value will be ignored because same instance will be passed to the <paramref name="asyncCallback"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///		<paramref name="methodName"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///		<paramref name="methodName"/> is not valid.
        /// </exception>
        public IAsyncResult BeginNotify(string methodName, object[] arguments, AsyncCallback asyncCallback, object asyncState)
        {
            this.VerifyIsNotDisposed();
            this.EnsureConnected();

            var asyncResult = new NotificationMessageAsyncResult(this, asyncCallback, asyncState);

            bool isSucceeded = false;
            var  context     = this._transport.GetClientRequestContext();

            try
            {
                context.SetNotification(methodName, asyncResult.OnCompleted);
                if (arguments == null)
                {
                    context.ArgumentsPacker.Pack(new MessagePackObject[0]);
                }
                else
                {
                    context.ArgumentsPacker.PackArrayHeader(arguments.Length);
                    foreach (var arg in arguments)
                    {
                        if (arg == null)
                        {
                            context.ArgumentsPacker.PackNull();
                        }
                        else
                        {
                            this._serializationContext.GetSerializer(arg.GetType()).PackTo(context.ArgumentsPacker, arg);
                        }
                    }
                }

                this._transport.Send(context);
                isSucceeded = true;
            }
            finally
            {
                if (!isSucceeded)
                {
                    this._transport.ReturnContext(context);
                }
            }

            return(asyncResult);
        }
コード例 #7
0
		public void TestConstructor_MessageIsNull()
		{
			var owner = new object();
			var target = new NotificationMessageAsyncResult( owner, null, null );
			Assert.That( target.MessageId, Is.Null );
		}
コード例 #8
0
		/// <summary>
		///		Sends specified remote method with specified argument as notification message asynchronously.
		/// </summary>
		/// <param name="methodName">
		///		The name of target method.
		/// </param>
		/// <param name="arguments">
		///		Argument to be passed to the server.
		///		All values must be able to be serialized with MessagePack serializer.
		/// </param>
		/// <param name="asyncCallback">
		///		The callback method invoked when the notification is sent or the reponse is received.
		///		This value can be <c>null</c>.
		///		Usually this callback get the result of invocation via <see cref="EndNotify"/>.
		/// </param>
		/// <param name="asyncState">
		///		User supplied state object which can be gotten via <see cref="IAsyncResult.AsyncState"/> in the <paramref name="asyncCallback"/> callback.
		///		This value can be <c>null</c>.
		/// </param>
		/// <returns>
		///		An <see cref="IAsyncResult" /> which can be passed to <see cref="EndNotify"/> method.
		///		Usually, this value will be ignored because same instance will be passed to the <paramref name="asyncCallback"/>.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		///		<paramref name="methodName"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="ArgumentException">
		///		<paramref name="methodName"/> is not valid.
		/// </exception>
		public IAsyncResult BeginNotify( string methodName, object[] arguments, AsyncCallback asyncCallback, object asyncState )
		{
			this.VerifyIsNotDisposed();
			this.EnsureConnected();

			var asyncResult = new NotificationMessageAsyncResult( this, asyncCallback, asyncState );

			bool isSucceeded = false;
			var context = this._transport.GetClientRequestContext();
			try
			{
				context.SetNotification( methodName, asyncResult.OnCompleted );
				if ( arguments == null )
				{
					context.ArgumentsPacker.Pack( new MessagePackObject[ 0 ] );
				}
				else
				{
					context.ArgumentsPacker.PackArrayHeader( arguments.Length );
					foreach ( var arg in arguments )
					{
						if ( arg == null )
						{
							context.ArgumentsPacker.PackNull();
						}
						else
						{
							this._serializationContext.GetSerializer( arg.GetType() ).PackTo( context.ArgumentsPacker, arg );
						}
					}
				}

				this._transport.Send( context );
				isSucceeded = true;
			}
			finally
			{
				if ( !isSucceeded )
				{
					this._transport.ReturnContext( context );
				}
			}

			return asyncResult;
		}