示例#1
0
 static void PrintBanner()
 {
     ConsolePrintHelper.PrintSeparationLine(40);
     Console.WriteLine("Publish/Subscriber Service Fabric Client");
     ConsolePrintHelper.PrintSeparationLine(40);
 }
示例#2
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);
        }