예제 #1
0
        private IDictionary Invoke(IDictionary request)
        {
            Exception exception;

            ValidationUtils.ArgumentNotNull(request, "request");
            object error  = null;
            object result = null;
            object id     = request["id"];
            string s      = request["credentials"] as string;

            if (!StringUtils.IsNullOrEmpty(s))
            {
                try
                {
                    CommandMessage message = new CommandMessage(8)
                    {
                        body = s
                    };
                    IMessage message2 = this.MessageBroker.RouteMessage(message);
                    if (message2 is ErrorMessage)
                    {
                        error = this.FromException(message2 as ErrorMessage);
                        return(CreateResponse(id, result, error));
                    }
                }
                catch (Exception exception1)
                {
                    exception = exception1;
                    error     = this.FromException(exception);
                    return(CreateResponse(id, result, error));
                }
            }
            if (JavaScriptConvert.IsNull(id))
            {
                throw new NotSupportedException("Notification are not yet supported.");
            }
            log.Debug(string.Format("Received request with the ID {0}.", id.ToString()));
            string str2 = StringUtils.MaskNullString((string)request["method"]);

            if (str2.Length == 0)
            {
                throw new JsonRpcException("No method name supplied for this request.");
            }
            try
            {
                RemotingMessage message3 = new RemotingMessage {
                    destination = base.Request.QueryString["destination"],
                    source      = base.Request.QueryString["source"],
                    operation   = str2
                };
                object   obj5     = request["params"];
                object[] objArray = (obj5 as JavaScriptArray).ToArray();
                message3.body = objArray;
                IMessage message4 = this.MessageBroker.RouteMessage(message3);
                if (message4 is ErrorMessage)
                {
                    error = this.FromException(message4 as ErrorMessage);
                }
                else
                {
                    result = message4.body;
                }
            }
            catch (Exception exception2)
            {
                exception = exception2;
                log.Error(exception.Message, exception);
                throw;
            }
            return(CreateResponse(id, result, error));
        }
예제 #2
0
        private IDictionary Invoke(IDictionary request)
        {
            ValidationUtils.ArgumentNotNull(request, "request");
            object error  = null;
            object result = null;

            ISession session = this.MessageBroker.SessionManager.GetHttpSession(HttpContext.Current);

            FluorineContext.Current.SetSession(session);
            //Context initialized, notify listeners.
            if (session != null && session.IsNew)
            {
                session.NotifyCreated();
            }

            // Get the ID of the request.
            object id          = request["id"];
            string credentials = request["credentials"] as string;

            if (!StringUtils.IsNullOrEmpty(credentials))
            {
                try
                {
                    CommandMessage commandMessage = new CommandMessage(CommandMessage.LoginOperation);
                    commandMessage.body = credentials;
                    IMessage message = this.MessageBroker.RouteMessage(commandMessage);
                    if (message is ErrorMessage)
                    {
                        error = FromException(message as ErrorMessage);
                        return(CreateResponse(id, result, error));
                    }
                }
                catch (Exception ex)
                {
                    error = FromException(ex);
                    return(CreateResponse(id, result, error));
                }
            }

            // If the ID is not there or was not set then this is a notification
            // request from the client that does not expect any response. Right
            // now, we don't support this.
            bool isNotification = JavaScriptConvert.IsNull(id);

            if (isNotification)
            {
                throw new NotSupportedException("Notification are not yet supported.");
            }

            log.Debug(string.Format("Received request with the ID {0}.", id.ToString()));

            // Get the method name and arguments.
            string methodName = StringUtils.MaskNullString((string)request["method"]);

            if (methodName.Length == 0)
            {
                throw new JsonRpcException("No method name supplied for this request.");
            }

            if (methodName == "clearCredentials")
            {
                try
                {
                    CommandMessage commandMessage = new CommandMessage(CommandMessage.LogoutOperation);
                    IMessage       message        = this.MessageBroker.RouteMessage(commandMessage);
                    if (message is ErrorMessage)
                    {
                        error = FromException(message as ErrorMessage);
                        return(CreateResponse(id, result, error));
                    }
                    else
                    {
                        return(CreateResponse(id, message.body, null));
                    }
                }
                catch (Exception ex)
                {
                    error = FromException(ex);
                    return(CreateResponse(id, result, error));
                }
            }

            //Info("Invoking method {1} on service {0}.", ServiceName, methodName);

            // Invoke the method on the service and handle errors.
            try
            {
                RemotingMessage message = new RemotingMessage();
                message.destination = this.Request.QueryString["destination"] as string;
                message.source      = this.Request.QueryString["source"] as string;
                message.operation   = methodName;
                object   argsObject = request["params"];
                object[] args       = (argsObject as JavaScriptArray).ToArray();
                message.body = args;
                IMessage response = this.MessageBroker.RouteMessage(message);
                if (response is ErrorMessage)
                {
                    error = FromException(response as ErrorMessage);
                }
                else
                {
                    result = response.body;
                }

                /*
                 * Method method = serviceClass.GetMethodByName(methodName);
                 *
                 * object[] args;
                 * string[] names = null;
                 *
                 * object argsObject = request["params"];
                 * IDictionary argByName = argsObject as IDictionary;
                 *
                 * if (argByName != null)
                 * {
                 *  names = new string[argByName.Count];
                 *  argByName.Keys.CopyTo(names, 0);
                 *  args = new object[argByName.Count];
                 *  argByName.Values.CopyTo(args, 0);
                 * }
                 * else
                 * {
                 *  args = (argsObject as JavaScriptArray).ToArray();
                 * }
                 *
                 * result = method.Invoke(instance, names, args);
                 */
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                throw;
            }

            // Setup and return the response object.
            return(CreateResponse(id, result, error));
        }