Inheritance: MessageBase
Example #1
0
 protected override MessageBase CopyImpl(MessageBase clone)
 {
     // Instantiate the clone, if a derived type hasn't already.
     if (clone == null) clone = new RemotingMessage();
     // Allow base type(s) to copy their state into the new clone.
     base.CopyImpl(clone);
     // Copy our state into the clone.
     ((RemotingMessage)clone)._source = _source;
     ((RemotingMessage)clone)._operation = _operation;
     return clone;
 }
Example #2
0
        public Notify InvokeRemotingMessage(string service, string operation, params object[] args)
        {
            var msg = new RemotingMessage();
            msg.operation = operation;
            msg.destination = service;
            msg.headers["DSRequestTimeout"] = 60;
            msg.headers["DSId"] = RtmpUtil.RandomUidString();
            msg.headers["DSEndpoint"] = "my-rtmps";
            msg.body = args;
            msg.messageId = RtmpUtil.RandomUidString();

            return Invoke(msg);
        }
 protected override MessageBase CopyImpl(MessageBase clone)
 {
     // Instantiate the clone, if a derived type hasn't already.
     if (clone == null)
     {
         clone = new RemotingMessage();
     }
     // Allow base type(s) to copy their state into the new clone.
     base.CopyImpl(clone);
     // Copy our state into the clone.
     ((RemotingMessage)clone)._source    = _source;
     ((RemotingMessage)clone)._operation = _operation;
     return(clone);
 }
        public object invokeService(string service, string operation, object[] args)
        {
            MessageBroker messageBroker = MessageBroker.GetMessageBroker(null);

            RemotingMessage remotingMessage = new RemotingMessage();
            remotingMessage.source = service;
            remotingMessage.operation = operation;
            string destinationId = messageBroker.GetDestinationId(remotingMessage);
            remotingMessage.destination = destinationId;
            if (args != null)
            {
                for(int i = 0; i <args.Length; i++)
                {
                    object obj = args[i];
                    if (obj is ASObject)
                    {
                        ASObject aso = obj as ASObject;
                        Type type = null;
                        //if (aso.ContainsKey("TypeName"))
                        //    type = TypeHelper.Locate(aso["TypeName"] as string);
                        if (aso.ContainsKey("__type"))
                            type = TypeHelper.Locate(aso["__type"] as string);
                        if (type != null)
                        {
                            string tmp = JavaScriptConvert.SerializeObject(obj);
                            args[i] = JavaScriptConvert.DeserializeObject(tmp, type);
                        }
                    }
                }
            }
            remotingMessage.body = args;
            remotingMessage.timestamp = Environment.TickCount;
            IMessage response = messageBroker.RouteMessage(remotingMessage);
            return response;
        }
        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);
        }