예제 #1
0
            public override void PrintError(CopyMachine copyMachine)
            {
                ConsolePrintHelper.WriteLabel("Произошла ошибка: ");
                ConsolePrintHelper.WriteLineValue(copyMachine.Error);

                copyMachine.State = new ReturnDeliveryState();
                copyMachine.State.ReturnDelivery(copyMachine);
            }
 public override void ReturnDelivery(CopyMachine copyMachine)
 {
     if (copyMachine.Cash > 0)
     {
         ConsolePrintHelper.WriteLabel("Возьмите сдачу: ");
         ConsolePrintHelper.WriteLineValue(copyMachine.Cash.ToString());
         copyMachine.Cash = 0;
     }
     copyMachine.State = new GoodbyeState();
     copyMachine.State.SayGoodbye(copyMachine);
 }
예제 #3
0
 static void PrintBanner()
 {
     ConsolePrintHelper.PrintSeparationLine(40);
     Console.WriteLine("Publish/Subscriber Service Fabric Client");
     ConsolePrintHelper.PrintSeparationLine(40);
 }
예제 #4
0
        /// <summary>
        /// Main entry point for the input and command validation
        /// </summary>
        static async Task <bool> Run()
        {
            Console.Clear();
            Console.ResetColor();
            PrintBanner();

            try
            {
                if (!FlatDisplay)
                {
                    ConsolePrintHelper.PrintCommands(_groups);
                }
                else
                {
                    ConsolePrintHelper.PrintCommands(_flatCommands);
                }

                int? numericCommand;
                bool switchGroup;
                _userInput.GetUserCommandSelection(out switchGroup, out numericCommand);
                if (numericCommand.HasValue)
                {
                    //select and execute the right command

                    int         index     = numericCommand.Value - 1;
                    Func <Task> operation = null;
                    if (index >= 0)
                    {
                        operation = FlatDisplay ? _flatCommands.GetCommand(index) : _groups.GetCommand(switchGroup, index);
                    }

                    if (operation != null)
                    {
                        ConsolePrintHelper.PrintSeparationLine(80, '-');
                        await operation();
                    }
                    else
                    {
                        Console.WriteLine("Numeric value {0} does not have a valid operation", numericCommand.Value);
                    }
                }
                else
                {
                    Console.WriteLine("Missing command");
                }
            }
            catch (CommandFailedException commandFailed)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"The command failed: {commandFailed.Message}");
                if (commandFailed.InnerException != null)
                {
                    Console.WriteLine("Inner: {0}", commandFailed.InnerException.Message);
                }
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Ooops, something wrong: {0}", ex.Message);
                Console.ReadKey();
            }
            finally
            {
            }

            return(true);
        }
예제 #5
0
 public override void Cancel(CopyMachine copyMachine)
 {
     ConsolePrintHelper.WriteLineLabel("Печать отменена.");
     copyMachine.State = new ReturnDeliveryState();
     copyMachine.State.ReturnDelivery(copyMachine);
 }
예제 #6
0
 public override void SayGoodbye(CopyMachine copyMachine)
 {
     copyMachine.State = null;
     ConsolePrintHelper.WriteLineLabel("До свидания!");
 }