Ejemplo n.º 1
0
        /// <summary>
        /// 解析js端传入的command字符串,创建command对象
        /// </summary>
        /// <param name="commandStr">js 端传入的command string</param>
        /// <returns>js端传人的command错误则返回null,正常返回command对象</returns>
        public static XCommand parse(string commandStr)
        {
            if (string.IsNullOrEmpty(commandStr))
            {
                return null;
            }

            string[] split = commandStr.Split('/');
            if (split.Length < 3)
            {
                return null;
            }

            XCommand command = new XCommand();

            command.className = split[0];
            command.methodName = split[1];
            command.callbackId = split[2];
            command.arguments = split.Length <= 3 ? String.Empty : String.Join("/", split.Skip(3));

            // 检查非法名字
            if (command.className.IndexOfAny(new char[] { '@', ':', ',', '!', ' ' }) > -1)
            {
                return null;
            }

            return command;
        }
Ejemplo n.º 2
0
        private void SendCommand(XCommand command)
        {
            if (null == command || null == command.methodName)
            {
                XLog.WriteError("in exec :: command can not be null!!");
                return;
            }

            //执行App command
            if (TryExecuteXApplicationCmd(command))
            {
                return;
            }
        }
Ejemplo n.º 3
0
 private bool TryExecuteXApplicationCmd(XCommand cmd)
 {
     if (IsXApplicationCmd(cmd))
     {
         //处理了close事件
         if (cmd.methodName.Equals("closeApplication"))
         {
             if (null != AppClose)
             {
                 AppClose(this, AppInfo.AppId);
                 //清空注册的handle
                 AppClose = null;
                 AppSendMessage = null;
             }
         }
         else
         {
             //处理appSendMessage 事件
             string msgId = JsonHelper.Deserialize<string[]>(cmd.arguments)[0];
             if (null != AppSendMessage)
             {
                 AppSendMessage(this, msgId);
             }
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 private bool IsXApplicationCmd(XCommand cmd)
 {
     return cmd.methodName.Equals("closeApplication") || cmd.methodName.Equals("appSendMessage");
 }