示例#1
0
        protected bool GetParameter(string message, out ComplexMessage parameters)
        {
            string[] strs = message.Split(new string[] { " ", Constants.CQNewLine }, 2, StringSplitOptions.RemoveEmptyEntries);

            if (strs.Length > 0 && strs[0].ToLower() == ResponseCommand)
            {
                if (strs.Length == 1)
                {
                    parameters = null;
                }
                else
                {
                    var splitter = new CommandSplitter();
                    var command  = splitter.Split(strs[1]);
                    parameters = command?.Select(x => ComplexMessage.Parse(x).ToMessageElement()).ToComplexMessage();
                }

                return(true);
            }
            else
            {
                parameters = null;
                return(false);
            }
        }
示例#2
0
        private void parseVRule(String word)
        {
            String[] tokens1 = CommandSplitter.split(word);
            if (tokens1.Length < 2 || tokens1.Length > 3)
            {
                throw new ArgumentException("Invalid VRULE statement: " + word);
            }

            String[] tokens2 = tokens1[1].Split('#');
            if (tokens2.Length != 2)
            {
                throw new ArgumentException("Invalid VRULE statement: " + word);
            }

            long timestamp;

            if (!long.TryParse(tokens2[0], out timestamp))
            {
                DateTime time;
                if (!DateTime.TryParse(tokens2[0], out time))
                {
                    throw new ArgumentException("Wrong time format in VRULE " + tokens2[0]);
                }
                timestamp = Util.getTimestamp(time);
            }
            Color color = Util.parseColor(tokens2[1]);

            gdef.vrule(timestamp, color, tokens1.Length == 3 ? tokens1[2] : null);
        }
示例#3
0
 private void parseComment(String word)
 {
     String[] tokens = CommandSplitter.split(word);
     if (tokens.Length != 2)
     {
         throw new ArgumentException("Invalid COMMENT specification: " + word);
     }
     gdef.comment(tokens[1]);
 }
示例#4
0
 private void ParseShift(String word)
 {
     String[] tokens = CommandSplitter.split(word);
     if (tokens.Length < 3)
     {
         throw new ArgumentException("Invalid SHIFT specification: " + word);
     }
     gdef.datasource(tokens[1], long.Parse(tokens[2]));
 }
        public Bash(ILogger logger, IProcessStarter processStarter)
        {
            this.logger = logger;

            commandSplitter = new CommandSplitter();
            variableManager = new VariableManager();
            commandParser   = new SubcommandParser();
            commandExecutor = new CommandExecutor(logger, processStarter);
        }
示例#6
0
        private void parsePrint(String word)
        {
            String[] tokens   = CommandSplitter.split(word);
            bool     strftime = (tokens[tokens.Length - 1].Contains("strftime"));

            if (tokens.Length < 3)
            {
                throw new ArgumentException("Invalid GPRINT specification: " + word);
            }
            gdef.print(tokens[1], tokens[2], strftime);
        }
示例#7
0
        public static bool CommandProcessor(string command, ref ShareLib.RenderStruct.RenderSettings obj)
        {
            if (command == "")
            {
                return(true);
            }

            var sp = CommandSplitter.SplitCommand(command);

            if (sp.Count == 0)
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                return(true);
            }
            var main = sp[0];

            sp.RemoveAt(0);
            switch (main)
            {
            case "render":
                Render.RenderKernel(obj);
                break;

            case "tt":
                try {
                    var cache = Tutorial();
                    obj = cache;
                } catch (Exception) {
                    ConsoleAssistance.WriteLine("Error occured! All setting is lost", ConsoleColor.Red);
                }
                break;

            case "ls":
                OutputRenderSettings(obj);
                break;

            case "exit":
                //save settings
                ConfigManager.Write <ShareLib.RenderStruct.RenderSettings>(obj, ConfigManager.RenderSettingsFile);
                return(false);

            case "help":
                Help();
                break;

            default:
                ConsoleAssistance.WriteLine("Unknow command", ConsoleColor.Red);
                break;
            }

            return(true);
        }
示例#8
0
        private void parseCDef(String word)
        {
            String[] tokens1 = CommandSplitter.split(word);
            if (tokens1.Length != 2)
            {
                throw new ArgumentException("Invalid CDEF specification: " + word);
            }

            String[] tokens2 = tokens1[1].Split('=');
            if (tokens2.Length != 2)
            {
                throw new ArgumentException("Invalid DEF specification: " + word);
            }

            gdef.datasource(tokens2[0], tokens2[1]);
        }
示例#9
0
        public static string Process(Client invoker, string command)
        {
            var cache = CommandSplitter.SplitCommand(command);

            if (cache.Count == 0)
            {
                return("Error command");
            }

            switch (cache[0])
            {
            //todo:finish command
            default:
                return("No such command.");
            }
        }
示例#10
0
        private void parseSDef(String word)
        {
            String[] tokens1 = CommandSplitter.split(word);
            if (tokens1.Length != 2)
            {
                throw new ArgumentException("Invalid SDEF specification: " + word);
            }

            String[] tokens2 = tokens1[1].Split('=');
            if (tokens2.Length != 2)
            {
                throw new ArgumentException("Invalid SDEF specification: " + word);
            }

            string[] tokens3 = tokens2[1].Split(',');
            gdef.datasource(tokens2[0], tokens3[0], AggregateFunction.Create(tokens3[1]));
        }
        public void Resolve(CommandSplitter.SplittedCommand cmd)
        {
            ICommand command = null;

            if (this.cache.ContainsKey(cmd.Command))
            {
                command = this.cache[cmd.Command];
            }
            else
            {
                command =
                    (from item in this.commands
                     let type = item.GetType()
                     let commandAttribute =
                         type.GetCustomAttributes(typeof(CommandAttribute), true).FirstOrDefault()
                     where commandAttribute != null
                     && (commandAttribute as CommandAttribute).Command == cmd.Command
                     select item).FirstOrDefault();

                this.cache.Add(cmd.Command, command);
            }

            if (command == null)
            {
                var failMessage = CommandrConfiguration.COMMAND_NOT_FOUND_MESSAGE.Replace("%cmd%", "\"" + cmd.Command + "\"");
                output.Write(failMessage);
                return;
            }

            var arguments =
                from item in command.GetType().GetCustomAttributes(typeof(ArgumentAttribute), true)
                select item as ArgumentAttribute;

            foreach (var argument in arguments.Where(arg => arg.IsRequired))
            {
                if (!cmd.Arguments.ContainsKey(argument.Name))
                {
                    output.Write("The argument " + argument.Name + " is missing!");
                    return;
                }
            }

            command.Output = this.output;
            command.Run(cmd.Arguments);
        }
示例#12
0
        public static void Process(string command)
        {
            var cache = CommandSplitter.SplitCommand(command);

            if (cache.Count == 0)
            {
                ConsoleAssistance.WriteLine("Error command", ConsoleColor.Red);
                return;
            }

            switch (cache[0])
            {
            //todo:finish command
            default:
                ConsoleAssistance.WriteLine("No such command.", ConsoleColor.Red);
                break;
            }
        }
示例#13
0
        private void parseHRule(String word)
        {
            String[] tokens1 = CommandSplitter.split(word);
            if (tokens1.Length < 2 || tokens1.Length > 3)
            {
                throw new ArgumentException("Invalid HRULE statement: " + word);
            }

            String[] tokens2 = tokens1[1].Split('#');
            if (tokens2.Length != 2)
            {
                throw new ArgumentException("Invalid HRULE statement: " + word);
            }

            double value = double.Parse(tokens2[0]);
            Color  color = Util.parseColor(tokens2[1]);

            gdef.hrule(value, color, tokens1.Length == 3 ? tokens1[2] : null);
        }
示例#14
0
        //DEF:<vname>=<rrdfile>:<ds-name>:<CF>[:step=<step>][:start=<time>][:end=<time>][:reduce=<CF>]
        private void parseDef(String word)
        {
            String[] tokens1 = CommandSplitter.split(word);
            if (tokens1.Length < 4)
            {
                throw new ArgumentException("Invalid DEF specification: " + word);
            }
            int parameterIndex = 1;

            string[] pair = tokens1[parameterIndex].Split('=');
            Def      def  = new Def(pair[0], pair[1]);

            parameterIndex++;
            def.dsName = tokens1[parameterIndex];
            parameterIndex++;
            def.SetConsulFunType(tokens1[parameterIndex]);
            parameterIndex++;
            while (parameterIndex < tokens1.Length)
            {
                pair = tokens1[parameterIndex].Split('=');
                switch (pair[0])
                {
                case "step":
                    def.Step = long.Parse(pair[1]);
                    break;

                case "start":
                    def.StartTime = Util.ParseDateTime(pair[1]);
                    break;

                case "end":
                    def.EndTime = Util.ParseDateTime(pair[1]);
                    break;

                case "reduce":
                    def.ReduceName = pair[1];
                    break;
                }
                parameterIndex++;
            }
            gdef.AddDatasource(def);
        }
示例#15
0
        private void parseStack(String word)
        {
            String[] tokens1 = CommandSplitter.split(word);
            if (tokens1.Length != 2 && tokens1.Length != 3)
            {
                throw new ArgumentException("Invalid STACK statement: " + word);
            }

            String[] tokens2 = tokens1[1].Split('#');
            if (tokens2.Length != 1 && tokens2.Length != 2)
            {
                throw new ArgumentException("Invalid STACK statement: " + word);
            }

            String name   = tokens2[0];
            Color  color  = tokens2.Length == 2 ? Util.parseColor(tokens2[1]) : BLIND_COLOR;
            String legend = tokens1.Length == 3 ? tokens1[2] : null;

            gdef.stack(name, color, legend);
        }
示例#16
0
        private void parseLine(String word)
        {
            String[] tokens1 = CommandSplitter.split(word);
            if (tokens1.Length != 2 && tokens1.Length != 3)
            {
                throw new ArgumentException("Invalid LINE statement: " + word);
            }

            String[] tokens2 = tokens1[1].Split('#');
            if (tokens2.Length != 1 && tokens2.Length != 2)
            {
                throw new ArgumentException("Invalid LINE statement: " + word);
            }

            float  width  = int.Parse(tokens1[0].Substring(tokens1[0].Length - 1));
            String name   = tokens2[0];
            Color  color  = tokens2.Length == 2 ? Util.parseColor(tokens2[1]) : BLIND_COLOR;
            String legend = tokens1.Length == 3 ? tokens1[2] : null;

            gdef.line(name, color, legend, width);
        }
        public void TestSingleCommandSplit()
        {
            IList <string> commands = CommandSplitter.Split("test");

            AssertList(commands, "test");
        }
示例#18
0
        public static bool Process(string command)
        {
            return(parser.ParseArguments <ExitOption, ConfigOption, SwitchOption, ClientOption, ImportOption, LsOption, ShowOption, AddpkgOption, EditpkgOption, DelpkgOption, AddverOption, EditverOption, DelverOption, HelpOption>(
                       CommandSplitter.Split(command))
                   .MapResult(
                       (ExitOption opt) => {
                if (opt.IsForce)
                {
                    return true;
                }
                else
                {
                    if (!General.IsMaintaining)
                    {
                        General.CoreTcpProcessor.StopListen();
                        Console.WriteLine("Waiting the release of resources...");
                        if (General.ManualResetEventList.Count != 0)
                        {
                            WaitHandle.WaitAll(General.ManualResetEventList.ToArray());
                        }
                    }
                    else
                    {
                        General.GeneralDatabase.Close();
                    }

                    General.RecordFileManager.Close();
                    return true;
                }
            },
                       (ConfigOption opt) => {
                if (opt.Key is null)
                {
                    foreach (var item in General.ConfigManager.Configuration.Keys)
                    {
                        Console.Write($"{item}: ");
                        Console.Write($"{General.ConfigManager.Configuration[item]}\n");
                    }
                }
                else
                {
                    if (opt.NewValue is null)
                    {
                        if (General.ConfigManager.Configuration.Keys.Contains(opt.Key))
                        {
                            Console.WriteLine(General.ConfigManager.Configuration[opt.Key]);
                        }
                    }
                    else
                    {
                        if (General.ConfigManager.Configuration.Keys.Contains(opt.Key))
                        {
                            General.ConfigManager.Configuration[opt.Key] = opt.NewValue;
                            General.ConfigManager.Save();
                            Console.WriteLine("New value has been applied");
                        }
                    }
                }
                return false;
            },
                       (SwitchOption opt) => {
                if (!General.IsMaintaining)
                {
                    General.CoreTcpProcessor.StopListen();
                    Console.WriteLine("Waiting the release of resources...");
                    if (General.ManualResetEventList.Count != 0)
                    {
                        WaitHandle.WaitAll(General.ManualResetEventList.ToArray());
                    }

                    General.GeneralDatabase.Open();

                    General.IsMaintaining = true;
                    ConsoleAssistance.WriteLine("Switch to maintain mode successfully.", ConsoleColor.Yellow);
                }
                else
                {
                    General.GeneralDatabase.Close();
                    //force update verify code
                    ConsoleAssistance.WriteLine("Updating verify code....", ConsoleColor.White);
                    General.VerifyBytes = SignVerifyHelper.SignData(Information.WorkPath.Enter("package.db").Path, Information.WorkPath.Enter("pri.key").Path);
                    General.ConfigManager.Configuration["VerifyBytes"] = Convert.ToBase64String(General.VerifyBytes);
                    General.ConfigManager.Save();

                    General.CoreTcpProcessor.StartListen();

                    General.IsMaintaining = false;
                    ConsoleAssistance.WriteLine("Switch to running mode successfully.", ConsoleColor.Yellow);
                }
                return false;
            },
                       (ClientOption opt) => {
                if (!CheckStatus(false))
                {
                    return false;
                }

                ConsoleAssistance.WriteLine($"Current client: {General.ManualResetEventList.Count}", ConsoleColor.Yellow);
                return false;
            },
                       (ImportOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }

                ConsoleAssistance.WriteLine("import is a dangerous command. It will load all script and run it without any error judgement! It couldn't be stopped before all of commands has been executed!", ConsoleColor.Yellow);
                var confirm = new Random().Next(100, 9999);
                ConsoleAssistance.WriteLine($"Type this random number to confirm your operation: {confirm}", ConsoleColor.Yellow);
                if (Console.ReadLine() == confirm.ToString())
                {
                    if (System.IO.File.Exists(opt.FilePath))
                    {
                        ImportStack.AppendImportedCommands(opt.FilePath);
                    }
                    else
                    {
                        ConsoleAssistance.WriteLine("Cannot find specific file", ConsoleColor.Red);
                    }
                }
                return false;
            },
                       (LsOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }

                if (opt.Condition is null)
                {
                    PackageManager.Ls(General.GeneralDatabase, "");
                }
                else
                {
                    PackageManager.Ls(General.GeneralDatabase, opt.Condition);
                }
                return false;
            },
                       (ShowOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.Show(General.GeneralDatabase, opt.FullPackageName);
                return false;
            },
                       (AddpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.AddPackage(General.GeneralDatabase, opt);
                return false;
            },
                       (EditpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.EditPackage(General.GeneralDatabase, opt);
                return false;
            },
                       (DelpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.RemovePackage(General.GeneralDatabase, opt.Name);
                return false;
            },
                       (AddverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.AddVersion(General.GeneralDatabase, opt);
                return false;
            },
                       (EditverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.EditVersion(General.GeneralDatabase, opt);
                return false;
            },
                       (DelverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.RemoveVersion(General.GeneralDatabase, opt.Name);
                return false;
            },
                       (HelpOption opt) => {
                OutputHelp();
                return false;
            },
                       errs => { ConsoleAssistance.WriteLine("Unknow command. Use help to find the correct command", ConsoleColor.Red); return false; }));
        }
示例#19
0
 public void SetUp()
 {
     commandSplitter = new CommandSplitter();
 }
        public void TestMultipleCommandsSplit()
        {
            IList <string> commands = CommandSplitter.Split("test1 && test2");

            AssertList(commands, "test1", "test2");
        }
        public void TestMultipleCommandsWithArgSplit()
        {
            IList <string> commands = CommandSplitter.Split("test1 --arg1 && test2 --arg2");

            AssertList(commands, "test1 --arg1", "test2 --arg2");
        }
        public void TestSingleCommandWithArgsSingleQuotesAndInnerQuotesSplit()
        {
            IList <string> commands = CommandSplitter.Split("test --arg1 'argument \"&&\" quotes'");

            AssertList(commands, "test --arg1 'argument \"&&\" quotes'");
        }
        public void TestSingleCommandWithArgsQuotesAndInnerSingleQuotesSplit()
        {
            IList <string> commands = CommandSplitter.Split("test --arg1 \"argument '&&' quotes\"");

            AssertList(commands, "test --arg1 \"argument '&&' quotes\"");
        }
示例#24
0
        // http://apike.ca/prog_svg_paths.html
        public PathShape(SVG svg, XmlNode node)
            : base(svg, node)
        {
            if (DefaultFill == null)
            {
                DefaultFill = new Fill(svg);
                DefaultFill.Color = svg.PaintServers.Parse("black");
            }

            this.ClosePath = false;
            string path = XmlUtil.AttrValue(node, "d", string.Empty);
            CommandSplitter cmd = new CommandSplitter(path);
            string commandstring;
            char command;
            List<PathElement> elements = this.m_elements;
            while (true)
            {
                commandstring = cmd.ReadNext();
                if (commandstring.Length == 0)
                    break;
                ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command);
                if (command == 'm' || command == 'M')
                {
                    elements.Add(new MoveTo(command, split));
                    if (split.More)
                        elements.Add(new LineTo(command, split));
                    continue;
                }
                if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v')
                {
                    elements.Add(new LineTo(command, split));
                    continue;
                }
                if (command == 'c' || command == 'C')
                {
                    while (split.More)
                        elements.Add(new CurveTo(command, split));
                    continue;
                }
                if (command == 's' || command == 'S')
                {
                    while (split.More)
                    {
                        CurveTo lastshape = elements[elements.Count - 1] as CurveTo;
                        System.Diagnostics.Debug.Assert(lastshape != null);
                        elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2));
                    }
                    continue;
                }
                if (command == 'a' || command == 'A')
                {
                    elements.Add(new EllipticalArcTo(command, split));
                    while (split.More)
                        elements.Add(new EllipticalArcTo(command, split));
                    continue;
                }
                if (command == 'z' || command == 'Z')
                {
                    this.ClosePath = true;
                    continue;
                }

                // extended format moveto or lineto can contain multiple points which should be translated into lineto
                PathElement lastitem = elements[elements.Count-1];
                if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo)
                {
                    //Point p = Point.Parse(s);
                    //elements.Add(new LineTo(p));
                    continue;
                }

                System.Diagnostics.Debug.Assert(false, string.Format("type '{0}' not supported", commandstring));
            }
        }
示例#25
0
        static bool NodeProcessor(string command, List <ShareLib.DataStruct.LineNodeItem> obj, string workSpaceDesc)
        {
            if (command == "")
            {
                return(true);
            }

            var sp = CommandSplitter.SplitCommand(command);

            if (sp.Count == 0)
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                return(true);
            }
            var main = sp[0];

            sp.RemoveAt(0);
            switch (main)
            {
            case "ls":
                if (sp.Count == 0)
                {
                    OutputHelper.OutputNodeList(obj);
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "new":
                if (sp.Count == 0)
                {
                    obj.Add(new ShareLib.DataStruct.LineNodeItem());
                }
                else if (sp.Count == 1)
                {
                    //check param
                    int index;
                    try {
                        index = int.Parse(sp[0]);
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    if (index < 0 || index > obj.Count)
                    {
                        ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                        return(true);
                    }

                    obj.Insert(index, new ShareLib.DataStruct.LineNodeItem());
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "rm":
                if (sp.Count == 1)
                {
                    //check param
                    int index;
                    try {
                        index = int.Parse(sp[0]);
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    if (index < 0 || index >= obj.Count)
                    {
                        ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                        return(true);
                    }

                    obj.RemoveAt(index);
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "mv":
                if (sp.Count == 2)
                {
                    //check param
                    int index, newI;
                    try {
                        index = int.Parse(sp[0]);
                        newI  = int.Parse(sp[1]);
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    if ((index < 0 || index >= obj.Count) || (newI < 0 || newI > obj.Count - 1))
                    {
                        ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                        return(true);
                    }

                    var cache = obj[index];
                    obj.RemoveAt(index);
                    obj.Insert(newI, cache);
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "pos":
                if (sp.Count == 4)
                {
                    //check param
                    int index, x = 0, y = 0, z = 0;
                    try {
                        index = int.Parse(sp[0]);
                        if (sp[1] != "~")
                        {
                            x = int.Parse(sp[1]);
                        }
                        if (sp[2] != "~")
                        {
                            y = int.Parse(sp[2]);
                        }
                        if (sp[3] != "~")
                        {
                            z = int.Parse(sp[3]);
                        }
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    if (index < 0 || index >= obj.Count)
                    {
                        ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                        return(true);
                    }

                    if (sp[1] == "~")
                    {
                        x = obj[index].NodePosition.X;
                    }
                    if (sp[2] == "~")
                    {
                        y = obj[index].NodePosition.Y;
                    }
                    if (sp[3] == "~")
                    {
                        z = obj[index].NodePosition.Z;
                    }

                    obj[index].NodePosition = new ShareLib.DataStruct.Coordinate(x, y, z);
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "attach":
                if (sp.Count == 2)
                {
                    //check param
                    int index = 0;
                    try {
                        index = int.Parse(sp[0]);
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    if (index < 0 || index >= obj.Count)
                    {
                        ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                        return(true);
                    }

                    obj[index].AttachedStationId = sp[1];
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "following":
                if (sp.Count == 3)
                {
                    //check param
                    int  index, railWidth = 0;
                    bool isBuilding = false;
                    try {
                        index = int.Parse(sp[0]);
                        if (sp[1] != "~")
                        {
                            railWidth = int.Parse(sp[1]);
                        }
                        if (sp[2] != "~")
                        {
                            isBuilding = bool.Parse(sp[2]);
                        }
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    if (index < 0 || index >= obj.Count)
                    {
                        ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                        return(true);
                    }

                    if (sp[1] != "~")
                    {
                        obj[index].FollowingRailwayWidth = railWidth;
                    }
                    if (sp[2] != "~")
                    {
                        obj[index].FollowingRailIsBuilding = isBuilding;
                    }
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "builder":
                if (sp.Count == 1)
                {
                    //check param
                    int index;
                    try {
                        index = int.Parse(sp[0]);
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    if (index < 0 || index >= obj.Count)
                    {
                        ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                        return(true);
                    }

                    var inputObj     = obj[index];
                    var innerCommand = "";
                    while (true)
                    {
                        ConsoleAssistance.Write($"Builder editor ({workSpaceDesc} Node:{index})> ", ConsoleColor.Green);
                        innerCommand = ConsoleAssistance.ReadLine();
                        if (!BuilderProcessor(innerCommand, inputObj.FollowingBuilder))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "back":
                return(false);

            case "help":
                Help();
                break;

            default:
                ConsoleAssistance.WriteLine("Unknow command", ConsoleColor.Red);
                break;
            }

            return(true);
        }
        public void TestMoar()
        {
            IList <string> commands = CommandSplitter.Split("bind t 'echo \"test-1\" && echo \"test-2\"'");

            AssertList(commands, "bind t 'echo \"test-1\" && echo \"test-2\"'");
        }
        public void TestMultipleCommandsWithArgsSingleQuotesAndInnerQuotesSplit()
        {
            IList <string> commands = CommandSplitter.Split("test1 --arg1 'a1 \"&&\" a2' && test2 --arg2 'b1 \"&&\" b2'");

            AssertList(commands, "test1 --arg1 'a1 \"&&\" a2'", "test2 --arg2 'b1 \"&&\" b2'");
        }
示例#28
0
        static bool StationProcessor(string command, List <ShareLib.DataStruct.StationItem> obj)
        {
            if (command == "")
            {
                return(true);
            }

            var sp = CommandSplitter.SplitCommand(command);

            if (sp.Count == 0)
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                return(true);
            }
            var main = sp[0];

            sp.RemoveAt(0);
            switch (main)
            {
            case "ls":
                if (sp.Count == 0)
                {
                    OutputHelper.OutputStationList(obj);
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "info":
                if (sp.Count == 1)
                {
                    //search
                    var search = from item in obj
                                 where item.StationId == sp[0]
                                 select item;
                    if (!search.Any())
                    {
                        ConsoleAssistance.WriteLine("No matched item", ConsoleColor.Red);
                        return(true);
                    }

                    //list
                    var data = search.First();
                    OutputHelper.OutputStationItem(data);
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "new":
                if (sp.Count == 1)
                {
                    //search
                    var search = from item in obj
                                 where item.StationId == sp[0]
                                 select item;
                    if (search.Any())
                    {
                        ConsoleAssistance.WriteLine("Existed id", ConsoleColor.Red);
                        return(true);
                    }

                    obj.Add(new ShareLib.DataStruct.StationItem()
                    {
                        StationId = sp[0]
                    });
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "rm":
                if (sp.Count == 1)
                {
                    //search
                    var search = from item in obj
                                 where item.StationId == sp[0]
                                 select item;
                    if (!search.Any())
                    {
                        ConsoleAssistance.WriteLine("No matched item", ConsoleColor.Red);
                        return(true);
                    }

                    obj.Remove(search.First());
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "re":
                if (sp.Count == 2)
                {
                    //search
                    var search = from item in obj
                                 where item.StationId == sp[0]
                                 select item;
                    if (!search.Any())
                    {
                        ConsoleAssistance.WriteLine("No matched item", ConsoleColor.Red);
                        return(true);
                    }

                    //check name
                    var search2 = from item in obj
                                  where item.StationId == sp[1]
                                  select item;
                    if (search2.Any())
                    {
                        ConsoleAssistance.WriteLine("Existed id", ConsoleColor.Red);
                        return(true);
                    }

                    search.First().StationId = sp[1];
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "edit":
                if (sp.Count == 7)
                {
                    //search
                    var search = from item in obj
                                 where item.StationId == sp[0]
                                 select item;
                    if (!search.Any())
                    {
                        ConsoleAssistance.WriteLine("No matched item", ConsoleColor.Red);
                        return(true);
                    }

                    //check param
                    bool isBuilding = false;
                    int  renderDirection = 0, renderOffset = 0;
                    try {
                        if (sp[3] != "~")
                        {
                            isBuilding = bool.Parse(sp[3]);
                        }
                        if (sp[4] != "~")
                        {
                            renderDirection = int.Parse(sp[4]);
                        }
                        if (sp[5] != "~")
                        {
                            renderOffset = int.Parse(sp[5]);
                        }
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    var cache = search.First();
                    if (sp[1] != "~")
                    {
                        cache.StationName = sp[1];
                    }
                    if (sp[2] != "~")
                    {
                        cache.StationSubtitle = sp[2];
                    }
                    if (sp[3] != "~")
                    {
                        cache.IsBuilding = isBuilding;
                    }
                    if (sp[4] != "~")
                    {
                        cache.RenderDirection = renderDirection;
                    }
                    if (sp[5] != "~")
                    {
                        cache.RenderOffset = renderOffset;
                    }
                    if (sp[6] != "~")
                    {
                        cache.StationDescription = sp[6];
                    }
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "pos":
                if (sp.Count == 4)
                {
                    //search
                    var search = from item in obj
                                 where item.StationId == sp[0]
                                 select item;
                    if (!search.Any())
                    {
                        ConsoleAssistance.WriteLine("No matched item", ConsoleColor.Red);
                        return(true);
                    }

                    //check param
                    int x = 0, y = 0, z = 0;
                    try {
                        if (sp[1] != "~")
                        {
                            x = int.Parse(sp[1]);
                        }
                        if (sp[2] != "~")
                        {
                            y = int.Parse(sp[2]);
                        }
                        if (sp[3] != "~")
                        {
                            z = int.Parse(sp[3]);
                        }
                    } catch (Exception) {
                        ConsoleAssistance.WriteLine("Wrong formation", ConsoleColor.Red);
                        return(true);
                    }

                    var operate = search.First();
                    if (sp[1] == "~")
                    {
                        x = operate.Position.X;
                    }
                    if (sp[2] == "~")
                    {
                        y = operate.Position.Y;
                    }
                    if (sp[3] == "~")
                    {
                        z = operate.Position.Z;
                    }

                    operate.Position = new ShareLib.DataStruct.Coordinate(x, y, z);
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "builder":
                if (sp.Count == 1)
                {
                    //search
                    var search = from item in obj
                                 where item.StationId == sp[0]
                                 select item;
                    if (!search.Any())
                    {
                        ConsoleAssistance.WriteLine("No matched item", ConsoleColor.Red);
                        return(true);
                    }

                    var inputObj     = search.First();
                    var innerCommand = "";
                    while (true)
                    {
                        ConsoleAssistance.Write($"Builder editor ({inputObj.StationId} - {inputObj.StationName})> ", ConsoleColor.Green);
                        innerCommand = ConsoleAssistance.ReadLine();
                        if (!BuilderProcessor(innerCommand, inputObj.Builder))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "layout":
                if (sp.Count == 1)
                {
                    //search
                    var search = from item in obj
                                 where item.StationId == sp[0]
                                 select item;
                    if (!search.Any())
                    {
                        ConsoleAssistance.WriteLine("No matched item", ConsoleColor.Red);
                        return(true);
                    }

                    var inputObj     = search.First();
                    var innerCommand = "";
                    while (true)
                    {
                        ConsoleAssistance.Write($"Layout editor ({inputObj.StationId} - {inputObj.StationName})> ", ConsoleColor.Green);
                        innerCommand = ConsoleAssistance.ReadLine();
                        if (!LayoutProcessor(innerCommand, inputObj.StationLayoutList))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    ConsoleAssistance.WriteLine("Illegal parameter count", ConsoleColor.Red);
                }
                break;

            case "back":
                return(false);

            case "help":
                Help();
                break;

            default:
                ConsoleAssistance.WriteLine("Unknow command", ConsoleColor.Red);
                break;
            }

            return(true);
        }
示例#29
0
        public static bool Process(string command)
        {
            return(parser.ParseArguments <ExitOption, ConfigOption, LoadOption, BuildOption, ExecOption, HelpOption>(
                       CommandSplitter.Split(command))
                   .MapResult(
                       (ExitOption opt) => {
                return true;
            },
                       (ConfigOption opt) => {
                if (opt.Key is null)
                {
                    foreach (var item in General.ConfigManager.Configuration.Keys)
                    {
                        Console.Write($"{item}: ");
                        Console.Write($"{General.ConfigManager.Configuration[item]}\n");
                    }
                }
                else
                {
                    if (opt.NewValue is null)
                    {
                        if (General.ConfigManager.Configuration.Keys.Contains(opt.Key))
                        {
                            Console.WriteLine(General.ConfigManager.Configuration[opt.Key]);
                        }
                    }
                    else
                    {
                        if (General.ConfigManager.Configuration.Keys.Contains(opt.Key))
                        {
                            General.ConfigManager.Configuration[opt.Key] = opt.NewValue;
                            General.ConfigManager.Save();
                            Console.WriteLine("New value has been applied");
                        }
                    }
                }
                return false;
            },
                       (LoadOption opt) => {
                if (General.CurrentAppStatus == AppStatus.Build)
                {
                    //load
                    try {
                        General.LoadedModule = Assembly.Load(File.ReadAllBytes("Test.dll"));
                        General.ScriptSettings.CleanSettings();
                        General.CurrentAppStatus = AppStatus.Loaded;
                    } catch (Exception e) {
                        ConsoleAssistance.WriteLine("Loading assembly error" + Environment.NewLine + e.Message, ConsoleColor.Yellow);
                    }
                }
                else
                {
                    //unload
                    General.CurrentAppStatus = AppStatus.Build;
                }

                return false;
            },
                       (BuildOption opt) => {
                if (!CheckStatus(AppStatus.Build))
                {
                    return false;
                }

                File.Delete("Test.dll");
                try {
                    //read code
                    var fs = new StreamReader("setup.cs", Encoding.UTF8);
                    var code = General.CodeTemplate.Replace("{PersonalCode}", fs.ReadToEnd());
                    fs.Close();
                    fs.Dispose();

                    //compile
                    var compiler = CSharpCompilation.Create("bpm_Plugin")
                                   .WithOptions(new CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind.DynamicallyLinkedLibrary))
                                   .AddReferences(MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location))
                                   .AddReferences(MetadataReference.CreateFromFile(typeof(Console).GetTypeInfo().Assembly.Location))
                                   .AddReferences(MetadataReference.CreateFromFile(typeof(File).GetTypeInfo().Assembly.Location))
                                   .AddReferences(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Runtime")).Location))
                                   .AddReferences(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.IO")).Location))
                                   //.AddReferences(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Text")).Location))
                                   .AddReferences(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Linq")).Location))
                                   .AddReferences(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Collections")).Location))
                                   .AddReferences(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.ValueTuple")).Location))
                                   .AddReferences(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Runtime.Extensions")).Location))
                                   //.AddReferences(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.IO.FileSystem")).Location))
                                   .AddSyntaxTrees(CSharpSyntaxTree.ParseText(code));

                    var res = compiler.Emit("Test.dll");
                    string r = "";
                    foreach (var item in res.Diagnostics)
                    {
                        r += item.ToString() + Environment.NewLine;
                    }

                    if (!res.Success)
                    {
                        ConsoleAssistance.WriteLine("Compile error:" + Environment.NewLine + r, ConsoleColor.Yellow);
                    }
                    else
                    {
                        ConsoleAssistance.WriteLine("Compile OK:" + Environment.NewLine + r);
                    }
                } catch (Exception e) {
                    ConsoleAssistance.WriteLine("Compile runtime error:" + Environment.NewLine + e.Message, ConsoleColor.Yellow);
                }

                return false;
            },
                       (ExecOption opt) => {
                if (!CheckStatus(AppStatus.Loaded))
                {
                    return false;
                }
                if (!CheckSettings())
                {
                    return false;
                }

                switch (opt.MethodName)
                {
                case "Install":
                    OutputRunningResult(((bool status, string desc))(General.LoadedModule.GetType("Plugin").GetMethod("Install").Invoke(null,
                                                                                                                                        new object[] { General.ConfigManager.Configuration["GamePath"],
                                                                                                                                                       Information.WorkPath.Path,
                                                                                                                                                       (Func <Dictionary <string, string> >)(General.ScriptSettings.GetSettings),
                                                                                                                                                       (Action <Dictionary <string, string> >)(General.ScriptSettings.SetSettings),
                                                                                                                                                       General.ConfigManager.Configuration["I18N"] })));
                    OutputSettingsValue(General.ScriptSettings);
                    break;
        public void TestSingleCommandWithArgsSplit()
        {
            IList <string> commands = CommandSplitter.Split("test --arg1 --arg2");

            AssertList(commands, "test --arg1 --arg2");
        }
示例#31
0
        // http://apike.ca/prog_svg_paths.html
        public PathShape(SVG svg, XmlNode node) : base(svg, node)
        {
            if (DefaultFill == null)
            {
                DefaultFill       = new Fill(svg);
                DefaultFill.Color = svg.PaintServers.Parse("black");
            }

            ClosePath = false;
            string             path = XmlUtil.AttrValue(node, "d", string.Empty);
            CommandSplitter    cmd  = new CommandSplitter(path);
            string             commandstring;
            char               command;
            List <PathElement> elements = m_elements;

            while (true)
            {
                commandstring = cmd.ReadNext();
                if (commandstring.Length == 0)
                {
                    break;
                }
                ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command);
                if (command == 'm' || command == 'M')
                {
                    elements.Add(new MoveTo(command, split));
                    if (split.More)
                    {
                        elements.Add(new LineTo(command, split));
                    }
                    continue;
                }
                if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v')
                {
                    elements.Add(new LineTo(command, split));
                    continue;
                }
                if (command == 'c' || command == 'C')
                {
                    while (split.More)
                    {
                        elements.Add(new CurveTo(command, split));
                    }
                    continue;
                }
                if (command == 's' || command == 'S')
                {
                    while (split.More)
                    {
                        CurveTo lastshape = elements[elements.Count - 1] as CurveTo;
                        System.Diagnostics.Debug.Assert(lastshape != null);
                        elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2));
                    }
                    continue;
                }
                if (command == 'a' || command == 'A')
                {
                    elements.Add(new EllipticalArcTo(command, split));
                    while (split.More)
                    {
                        elements.Add(new EllipticalArcTo(command, split));
                    }
                    continue;
                }
                if (command == 'z' || command == 'Z')
                {
                    ClosePath = true;
                    continue;
                }

                // extended format moveto or lineto can contain multiple points which should be translated into lineto
                PathElement lastitem = elements[elements.Count - 1];
                if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo)
                {
                    //Point p = Point.Parse(s);
                    //elements.Add(new LineTo(p));
                    continue;
                }


                System.Diagnostics.Debug.Assert(false, string.Format("type '{0}' not supported", commandstring));
            }
        }
        public void TestMultipleCommandsWithArgsQuotesAndInnerQuotesSplit()
        {
            IList <string> commands = CommandSplitter.Split("test1 --arg1 \"a1 \\\"&&\\\" a2\" && test2 --arg2 \"b1 \\\"&&\\\" b2\"");

            AssertList(commands, "test1 --arg1 \"a1 \\\"&&\\\" a2\"", "test2 --arg2 \"b1 \\\"&&\\\" b2\"");
        }