예제 #1
0
        public InvocationResult Dispatch( RpcServerSession session, int messageId, string methodName, IList<MessagePackObject> arguments )
        {
            Contract.Assert( session != null );
            Contract.Assert( !String.IsNullOrWhiteSpace( methodName ) );
            Contract.Assert( arguments != null );

            RuntimeMethodHandle handle = this._targetResolver.ResolveMethod( methodName );
            var targetMethod = MethodBase.GetMethodFromHandle( handle ) as MethodInfo;
            if ( targetMethod == null )
            {
                throw new RpcMissingMethodException( methodName, "Specified member is not method.", MethodBase.GetMethodFromHandle( handle ).ToString() );
            }

            var invoker = this._invokerProvider.GetInvoker( targetMethod );
            var filteredArguments = arguments;
            foreach ( var filter in this._preInvocationFilters )
            {
                filteredArguments = filter.GetFilter().Process( targetMethod, arguments );
            }

            var result = this.Invoke( invoker, targetMethod, arguments );

            foreach ( var filter in this._postInvocationFilters )
            {
                result = filter.GetFilter().Process( targetMethod, result );
            }

            return result;
        }
예제 #2
0
        public void Send( RpcServerSession session, MessageType type, int messageId, object returnValue, bool isVoid, Exception exception )
        {
            if ( session == null )
            {
                throw new ArgumentNullException( "session" );
            }

            switch ( type )
            {
                case MessageType.Response:
                {
                    break;
                }
                default:
                {
                    throw new ArgumentOutOfRangeException( "type", type, "'type' must be 'Response'." );
                }
            }

            if ( isVoid && returnValue != null )
            {
                throw new ArgumentException( "'returnValue' must be null if 'isVoid' is true.", "returnValue" );
            }

            Contract.EndContractBlock();

            this.SendCore( session, type, messageId, returnValue, isVoid, exception );
        }
예제 #3
0
        public void OnReceived( RpcServerSession session )
        {
            if ( session == null )
            {
                throw new ArgumentNullException( "session" );
            }

            Contract.EndContractBlock();

            this.OnReceivedCore( session );
        }
예제 #4
0
        protected override sealed void SendCore( RpcServerSession session, MessageType messageType, int messageId, object returnValue, bool isVoid, Exception exception )
        {
            RpcException rpcException = exception as RpcException;
            if ( rpcException == null && exception != null )
            {
                rpcException = new RpcException( RpcError.CallError, "Remote method throws exception.", exception.ToString() );
            }

            // FIXME: Buffer strategy
            RpcOutputBuffer buffer = new RpcOutputBuffer( ChunkBuffer.CreateDefault() );
            var error = this._responseSerializer.Serialize( messageId, returnValue, isVoid, rpcException, buffer );
            if ( !error.IsSuccess )
            {
                this._eventLoop.HandleError( new RpcTransportErrorEventArgs( RpcTransportOperation.Deserialize, messageId, error ) );
                return;
            }

            this._eventLoop.SendAsync( session.Context, buffer.ReadBytes() );
        }
예제 #5
0
        protected override sealed void OnReceivedCore( RpcServerSession session )
        {
            // Deserialize
            RequestMessage request;
            #warning TODO: specify appropriate buffer.
            var error = this._requestSerializer.Deserialize( null, out request );
            if ( !error.IsSuccess )
            {
                this._eventLoop.HandleError( new RpcTransportErrorEventArgs( RpcTransportOperation.Deserialize, error ) );
                return;
            }

            // Fire Dispatch
            session.ProcessRequest( request );
        }
예제 #6
0
 protected abstract void SendCore( RpcServerSession session, MessageType type, int messageId, object returnValue, bool isVoid, Exception exception );
예제 #7
0
 protected abstract void OnReceivedCore( RpcServerSession session );