Пример #1
0
        //A recursive function for handling the creation of the macro commands

        public static Command CreateMacro(MacroCommand macroCommand, StreamReader sr)
        {
            var line = sr.ReadLine();

            //base case, macro section is complete
            if (line.ElementAt(0) == 'E')
            {
                return(macroCommand);
            }

            //nested macro case
            else if (line.ElementAt(0) == 'B')
            {
                macroCommand.commands.Add(CreateMacro(new MacroCommand(), sr));
            }

            //add line to macro and run function again
            else
            {
                ArgStruct args = Parser.ParseLine(line);
                macroCommand.commands.Add(Factory.MakeCommand(args));
                CreateMacro(macroCommand, sr);
            }

            return(macroCommand);
        }
Пример #2
0
        /// <summary>
        /// Parse the entire file, send off to subroutines as required to create Commands and save them to the invoker
        /// </summary>
        /// <param name="path"></param>
        public static void ParseFile(string path)
        {
            using (StreamReader sr = new StreamReader(path))   //Read the file in, create Commands and add to list
            {
                while (!sr.EndOfStream)
                {
                    Command newCommand;
                    var     line = sr.ReadLine();
                    if (line.ElementAt(0) != 'B')
                    {
                        ArgStruct args = ParseLine(line);
                        newCommand = Factory.MakeCommand(args);
                    }
                    else
                    {
                        newCommand = Factory.CreateMacro(new MacroCommand(), sr);
                    }

                    Invoker.commands.Add(newCommand);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a list of Commands from the temp file
        /// </summary>
        /// <param name="filePath"></param>
        private void CreateCommandList(string filePath)
        {
            commands.Clear();
            commands.Add(new MacroCommand());
            using (StreamReader sr = new StreamReader(filePath))
            {
                while (!sr.EndOfStream)
                {
                    Command newCommand;
                    var     line = sr.ReadLine();
                    if (line.ElementAt(0) != 'B')
                    {
                        ArgStruct args = ParseLine(line);
                        newCommand = FunctionsDictionary[args._command](args);
                    }
                    else
                    {
                        newCommand = CreateMacro(new MacroCommand(), sr);
                    }

                    commands.Add(newCommand);
                }
            }
        }
Пример #4
0
        static Command MakeUpdate(ArgStruct args)
        {
            Command command = new UpdateCommand(args._database, args._key, args._value);

            return(command);
        }
Пример #5
0
        static Command MakeAdd(ArgStruct args)
        {
            Command command = new AddCommand(args._database, args._key, args._value);

            return(command);
        }
Пример #6
0
        //The following methods are for creating the Command Objects

        public static Command MakeCommand(ArgStruct args)
        {
            return(FunctionsDictionary[args._command](args));
        }
Пример #7
0
 static Command MakeUpdate(ArgStruct args)
 {
     return(new UpdateCommand(args._database, args._key, args._value));
 }
Пример #8
0
 static Command MakeRemove(ArgStruct args)
 {
     return(new RemoveCommand(args._database, args._key, args._value));
 }
Пример #9
0
 static Command MakeAdd(ArgStruct args)
 {
     return(new AddCommand(args._database, args._key, args._value));
 }