Пример #1
0
 /// <summary>
 /// Initializes the parameter binder controller for
 /// the specified native command and engine context.
 /// </summary>
 /// <param name="command">
 /// The command that the parameters will be bound to.
 /// </param>
 internal MinishellParameterBinderController(
     NativeCommand command)
     : base(command)
 {
     InputFormat = NativeCommandIOFormat.Xml;
     OutputFormat = NativeCommandIOFormat.Text;
 }
Пример #2
0
        public virtual bool Parse(bool keepQuotes = false)
        {
            LastError = null;

            if (string.IsNullOrEmpty(NativeCommand))
            {
                LastError = "Command is empty";
                return(false);
            }

            int nOpen  = NativeCommand.Count(f => f == '(');
            int nClose = NativeCommand.Count(f => f == ')');

            if (nOpen < 1 || nClose < 1)
            {
                LastError = "Open or closing bracket is missing";
                return(false);
            }

            var nativeArguments =
                NativeCommand.Substring(NativeCommand.IndexOf("(", StringComparison.OrdinalIgnoreCase) + 1);

            nativeArguments = nativeArguments.Trim();
            nativeArguments = nativeArguments.TrimEnd(')');
            nativeArguments = nativeArguments.Trim();

            var argumentParts = nativeArguments.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var p in argumentParts)
            {
                if (string.IsNullOrEmpty(p))
                {
                    continue;
                }

                CommandArgument arg = new CommandArgument();
                if (!arg.Parse(p, keepQuotes))
                {
                    LastError = "Parsing of argument list failed: " + p;
                    return(false);
                }

                Arguments.Add(arg);
            }

            return(true);
        }
Пример #3
0
        public static void handleJsmod2(int id, String json, Dictionary <string, string> mapper, TcpClient client)
        {
            try
            {
                //指令注册
                if (id == 0x53)
                {
                    //处理指令注册
                    NativeCommand command = JsonConvert.DeserializeObject(json, typeof(NativeCommand)) as NativeCommand;
                    ProxyHandler.handler.Info("registered jsmod2 command");
                    ProxyHandler.handler.AddCommand(command.commandName, new CommandHandler(command));
                    client.Close();
                }
                else
                {
                    object o = null;
                    if (mapper.ContainsKey("player"))
                    {
                        string apiId = mapper["player"];//获取api对象id
                        o = ProxyHandler.handler.apiMapping[apiId];
                    }

                    if (handlers.ContainsKey(id))
                    {
                        JsonSetting[] response = null;


                        ProxyHandler.handler.Info("handling the " + id);
                        Handler handler = handlers[id];
                        //ProxyHandler.handler.Info(json);//
                        try
                        {
                            response = handler.handle(o, mapper);
                        }
                        catch (Exception e)
                        {
                            //ProxyHandler.handler.Info(e.Message);
                            if (e is NullReferenceException)
                            {
                                sendNull(client);
                                return;
                            }
                        }

                        if (response != null)
                        {
                            if (response.Length == 0)
                            {
                                sendNull(client);
                            }
                            else
                            {
                                //将response对象发出去
                                ProxyHandler.handler.sendObjects(client, response);
                            }

                            client.Close();
                        }
                        else
                        {
                            client.Close();
                        }
                    }
                    else
                    {
                        client.Close();
                    }
                }
            }
            catch (Exception e)
            {
                ProxyHandler.handler.Error(e.GetType() + "");
                ProxyHandler.handler.Error(e.Message);
                ProxyHandler.handler.Error(e.StackTrace);
            }

            if (Lib.getBool(ProxyHandler.handler.reader.get("jsmod2.debug")))
            {
                ProxyHandler.handler.Info("packet: id: " + id + " json: " + json + " finish a packet about jsmod2");
            }
        }
 /// <summary>
 /// Initializes the cmdlet parameter binder controller for
 /// the specified native command and engine context.
 /// </summary>
 /// <param name="command">
 /// The command that the parameters will be bound to.
 /// </param>
 internal NativeCommandParameterBinderController(NativeCommand command)
     : base(command.MyInvocation, command.Context, new NativeCommandParameterBinder(command))
 {
 }