Esempio n. 1
0
 internal static void TraceInvocationResult <T>(long sessionId, MessageType messageType, int messageId, string operationId, RpcErrorMessage error, T result)
 {
     if (error.IsSuccess)
     {
         if (MsgPackRpcServerDispatchTrace.ShouldTrace(MsgPackRpcServerDispatchTrace.OperationSucceeded))
         {
             MsgPackRpcServerDispatchTrace.TraceEvent(
                 MsgPackRpcServerDispatchTrace.OperationSucceeded,
                 "Operation succeeded. {{ \"SessionId\" : {0}, \"MessageType\" : \"{1}\", \"MessageID\" : {2}, \"OperationID\" : \"{3}\", \"Result\" : \"{4}\" }}",
                 sessionId,
                 messageType,
                 messageId,
                 operationId,
                 result
                 );
         }
     }
     else
     {
         MsgPackRpcServerDispatchTrace.TraceEvent(
             MsgPackRpcServerDispatchTrace.OperationFailed,
             "Operation failed. {{ \"SessionId\" : {0}, \"MessageType\" : \"{1}\", \"MessageID\" : {2}, \"OperationID\" : \"{3}\", \"RpcError\" : {4} }}",
             sessionId,
             messageType,
             messageId,
             operationId,
             error
             );
     }
 }
Esempio n. 2
0
        public static RpcErrorMessage HandleInvocationException(long sessionId, MessageType messageType, int?messageId, string operationId, Exception exception, bool isDebugMode)
        {
            MsgPackRpcServerDispatchTrace.TraceEvent(
                MsgPackRpcServerDispatchTrace.OperationThrewException,
                "Operation threw exception. {{ \"SessionId\" : {0}, \"MessageType\" : \"{1}\", \"MessageID\" : {2}, \"OperationID\" : \"{3}\", \"Exception\" : \"{4}\" }}",
                sessionId,
                messageType,
                messageId,
                operationId,
                exception
                );

            return(HandleInvocationException(exception, operationId, isDebugMode));
        }
Esempio n. 3
0
        public sealed override Task InvokeAsync(ServerRequestContext requestContext, ServerResponseContext responseContext)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }

            Contract.Ensures(Contract.Result <Task>() != null);

            var messageId = requestContext.MessageId;
            var arguments = requestContext.ArgumentsUnpacker;

            bool readMustSuccess = arguments.Read();

            Contract.Assert(readMustSuccess, "Arguments is not an array.");
            Contract.Assert(arguments.IsArrayHeader);

            SafeStartLogicalOperation();
            if (MsgPackRpcServerDispatchTrace.ShouldTrace(MsgPackRpcServerDispatchTrace.OperationStart))
            {
                MsgPackRpcServerDispatchTrace.TraceData(
                    MsgPackRpcServerDispatchTrace.OperationStart,
                    "Operation starting.",
                    responseContext == null ? MessageType.Notification : MessageType.Request,
                    messageId,
                    this.OperationId
                    );
            }

            AsyncInvocationResult result;

            try
            {
                result = this.InvokeCore(arguments);
            }
            catch (Exception ex)
            {
                result = new AsyncInvocationResult(InvocationHelper.HandleInvocationException(requestContext.SessionId, requestContext.MessageType, requestContext.MessageId, this.OperationId, ex, this.IsDebugMode));
            }

            var tuple = Tuple.Create(this, requestContext.SessionId, messageId.GetValueOrDefault(), this.OperationId, responseContext, result.InvocationError);

            if (result.AsyncTask == null)
            {
                return(Task.Factory.StartNew(state => HandleInvocationResult(null, state as Tuple <AsyncServiceInvoker <T>, long, int, string, ServerResponseContext, RpcErrorMessage>), tuple));
            }
            else
            {
#if NET_4_5
                return
                    (result.AsyncTask.ContinueWith(
                         (previous, state) => HandleInvocationResult(
                             previous,
                             state as Tuple <AsyncServiceInvoker <T>, long, int, string, ServerResponseContext, RpcErrorMessage>
                             ),
                         tuple
                         ));
#else
                return
                    (result.AsyncTask.ContinueWith(
                         previous => HandleInvocationResult(
                             previous,
                             tuple
                             )
                         ));
#endif
            }
        }