Exemplo n.º 1
0
        static async Task <bool> Run()
        {
            Console.ResetColor();
            try
            {
                ConsoleHelper.PrintCommands(groups);

                int? numericCommand;
                bool switchGroup;
                userInput.GetUserCommandSelection(out switchGroup, out numericCommand);
                if (numericCommand.HasValue)
                {
                    int         index     = numericCommand.Value - 1;
                    Func <Task> operation = null;
                    if (index >= 0)
                    {
                        operation = groups.GetCommand(switchGroup, index);
                    }

                    if (operation != null)
                    {
                        await operation();
                    }
                    else
                    {
                        Console.WriteLine("Numeric value {0} does not have a valid operation", numericCommand.Value);
                    }
                }
                else
                {
                    Console.WriteLine("Missing command");
                }
            }
            catch (HttpOperationException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Ooops, something broke: {0}", ex.Message);

                var error = SafeJsonConvert.DeserializeObject <PBIExceptionBody>(ex.Response.Content);
                if (error != null && error.Error != null)
                {
                    if (error.Error.Details != null && error.Error.Details.FirstOrDefault() != null)
                    {
                        Console.WriteLine(error.Error.Details.FirstOrDefault().Message);
                    }
                    else if (error.Error.Code != null)
                    {
                        Console.WriteLine(error.Error.Code);
                    }
                }

                IEnumerable <string> requestIds;
                ex.Response.Headers.TryGetValue("RequestId", out requestIds);
                if (requestIds != null && !string.IsNullOrEmpty(requestIds.FirstOrDefault()))
                {
                    Console.WriteLine("RequestId : {0}", requestIds.FirstOrDefault());
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Ooops, something broke: {0}", ex.Message);
                Console.WriteLine();
            }
            return(true);
        }