Example #1
0
        /// <summary>
        /// Reads commands from stdin. If a command is correct, it is executed. If not, invalid HTML is printed.
        /// </summary>
        /// <param name="commandReader">Text reader. Has to read STDIN.</param>
        public void InititateCommandProcessing(TextReader commandReader, StoreViewer storeViewer)
        {
            this.storeViewer = storeViewer;

            while (true)
            {
                string      line       = commandReader.ReadLine();
                CommandType type       = default(CommandType);
                int         customerId = default(int);
                int         bookId     = default(int);

                if (line == EmptyInput || line == null)
                {
                    break;
                }

                if (ParseCommand(line, out type, out customerId, out bookId))
                {
                    ExecuteCommand(type, customerId, bookId);
                }
                else
                {
                    this.storeViewer.InvalidRequest();
                    this.storeViewer.Indent();
                }
            }
        }
Example #2
0
        /// <summary>
        /// This method takes care of launching the actual program.
        /// It creates instances of objects needed in the end it disposes them.
        /// Also it shuts the program down in case of Data error.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            StoreViewer      storeViewer = new StoreViewer(Console.Out);
            SupremeCommander Thor        = new SupremeCommander();
            bool             wrongStoreInput;

            Thor.GetData(Console.In, out wrongStoreInput);

            if (wrongStoreInput)
            {
                Thor.PrintDataError();

                return;
            }

            Thor.InititateCommandProcessing(Console.In, storeViewer);

            Thor.DisposeStore();
            storeViewer.Dispose();
        }