예제 #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));
 }