public static EditorReplaceMessage Parse(string[] argument)
        {
            if (argument.Length != 3)
                return null;

            if (!File.Exists(argument[0]))
                return null;
            var content = File.ReadAllText(argument[0]);
            if (content.EndsWith(Environment.NewLine))
                content = content.Substring(0, content.Length - Environment.NewLine.Length);

            var goTo = new PositionArgumentParser().Parse(argument[1]);
            if (goTo == null)
                return null;
            if (!File.Exists(goTo.File))
                return null;

            int line, column;
            var chunks = argument[2].Split(new[] {"|"}, StringSplitOptions.RemoveEmptyEntries);
            if (chunks.Length != 2)
                return null;
            if (!int.TryParse(chunks[0], out line))
                return null;
            if (!int.TryParse(chunks[1], out column))
                return null;
            return new EditorReplaceMessage(
                    content,
                    goTo,
                    new GoTo()
                        {
                            File = goTo.File,
                            Line = line,
                            Column = column
                        });
        }
        public static EditorRemoveMessage Parse(string[] argument)
        {
            if (argument.Length != 2)
                return null;

            var goTo = new PositionArgumentParser().Parse(argument[0]);
            if (goTo == null)
                return null;
            if (!File.Exists(goTo.File))
                return null;

            int line, column;
            var chunks = argument[1].Split(new[] {"|"}, StringSplitOptions.RemoveEmptyEntries);
            if (chunks.Length != 2)
                return null;
            if (!int.TryParse(chunks[0], out line))
                return null;
            if (!int.TryParse(chunks[1], out column))
                return null;
            return new EditorRemoveMessage(
                    goTo,
                    new GoTo()
                        {
                            Line = line,
                            Column = column
                        });
        }
Esempio n. 3
0
        private GoTo getLocation(string arguments)
        {
            var goTo = new PositionArgumentParser().Parse(arguments);
            if (goTo == null)
            {
                invalidArgs();
                return null;
            }

            return goTo;
        }
Esempio n. 4
0
 public static EditorInsertMessage Parse(string[] argument)
 {
     if (argument.Length < 2)
         return null;
     if (!File.Exists(argument[0]))
         return null;
     var goTo = new PositionArgumentParser().Parse(argument[1]);
     if (goTo == null)
         return null;
     if (!File.Exists(goTo.File))
         return null;
     var content = File.ReadAllText(argument[0]);
     if (content.EndsWith(Environment.NewLine))
         content = content.Substring(0, content.Length - Environment.NewLine.Length);
     Position moveOffset = null;
     if (argument.Length > 2)
         moveOffset = Position.Parse(argument[2]);
     return new EditorInsertMessage(
             content,
             goTo,
             moveOffset);
 }