Пример #1
0
        public override Answer ask()
        {
            var prompt = new TextPrompt <string>(Question)
                         .InvalidChoiceMessage("[red]That's not a valid option[/]");

            foreach (var o in Options)
            {
                prompt.AddChoice(o);
            }
            var response = AnsiConsole.Prompt(prompt);

            return(new MultipleChoiceAnswer(this, "voterName", response));
        }
Пример #2
0
        static void Main(string[] args)
        {
            Dictionary <int, List <string> > answers = new Dictionary <int, List <string> >();
            string filePath = AnsiConsole.Ask <string>("Please Enter the file path.");

            InputReader inputReader = new InputReader(filePath);

            //var survey = new Survey();
            //var question = survey.GetQuestion();

            var question = inputReader.GetQuestion();


            var prompt = new TextPrompt <string>(question.Question);

            foreach (var a in question.Answers)
            {
                prompt.AddChoice(a);
            }
            var answer = AnsiConsole.Prompt(prompt);

            List <string> lst_answ = new List <string>();

            lst_answ.Add(question.Question);
            lst_answ.Add(answer);

            answers.Add(1, lst_answ);
            Console.WriteLine(answers);
            if (answer == inputReader.GetCorrectAnswer())
            {
                AnsiConsole.Markup("That's [underline green]correct[/]!");
            }



            // var prompt = new TextPrompt<string>(question.Question);
            // foreach(var a in question.Answers) {
            //     prompt.AddChoice(a);
            // }
            // var answer = AnsiConsole.Prompt(prompt);

            // if(answer == survey.GetCorrectAnswer()) {
            //     AnsiConsole.Markup("That's [underline green]correct[/]!");
            // }
            // else {
            //     AnsiConsole.Markup("That's [underline red]wrong[/]!");
            // }
        }
Пример #3
0
        static void Main(string[] args)
        {
            var survey   = new Survey();
            var question = survey.GetQuestion();

            var prompt = new TextPrompt <string>(question.Question);

            foreach (var a in question.Answers)
            {
                prompt.AddChoice(a);
            }
            var answer = AnsiConsole.Prompt(prompt);

            if (answer == survey.GetCorrectAnswer())
            {
                AnsiConsole.Markup("That's [underline green]correct[/]!");
            }
            else
            {
                AnsiConsole.Markup("That's [underline red]wrong[/]!");
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            TextPrompt <string> modePrompt = new TextPrompt <string>("Select DynamoDB Connect Mode")
                                             .InvalidChoiceMessage("[red]Invalid Mode[/]")
                                             .AddChoice("ApiKey")
                                             .AddChoice("CredentialsFile")
                                             .DefaultValue("ApiKey");

            var    apiKey = ApiKey;
            var    secret = Secret;
            string credentialsFilePath = string.Empty;
            string profileName         = string.Empty;

            var mode = AnsiConsole.Prompt(modePrompt);

            if (mode == "ApiKey")
            {
                if (string.IsNullOrEmpty(apiKey))
                {
                    apiKey = AnsiConsole.Ask <string>("Enter your DynamoDB [blue]API Key[/]");
                }

                TextPrompt <string> secretPrompt = new TextPrompt <string>("Enter your DynamoDB [blue]API Secret[/]")
                                                   .PromptStyle("red")
                                                   .Secret();

                if (string.IsNullOrEmpty(secret))
                {
                    secret = AnsiConsole.Prompt(secretPrompt);
                }
            }
            else
            {
                var credentialsFilePathPrompt = new TextPrompt <string>("Enter your [blue]Credentials File Path[/]");
                credentialsFilePath = AnsiConsole.Prompt(credentialsFilePathPrompt);

                var profilePrompt = new TextPrompt <string>("Enter your [blue]Credentials Profile name[/]");

                profileName = AnsiConsole.Prompt(profilePrompt);
            }

            TextPrompt <string> regionPrompt = new TextPrompt <string>("Enter your DynamoDB [blue]Region[/]?")
                                               .InvalidChoiceMessage("[red]Invalid Region[/]")
                                               .DefaultValue("APNortheast2");

            foreach (string regionName in Enum.GetNames(typeof(AwsRegion)))
            {
                regionPrompt.AddChoice(regionName);
            }

            var region = AnsiConsole.Prompt(regionPrompt);

            var connection = new PrimarSqlConnection(new PrimarSqlConnectionStringBuilder
            {
                AccessKey           = apiKey,
                AccessSecretKey     = secret,
                CredentialsFilePath = credentialsFilePath,
                ProfileName         = profileName,
                AwsRegion           = Enum.Parse <AwsRegion>(region),
            });

            connection.Open();

            while (true)
            {
                try
                {
                    var query   = AnsiConsole.Prompt(new TextPrompt <string>("[blue]Query[/]"));
                    var command = connection.CreateDbCommand(query);
                    using var dbDataReader = command.ExecuteReader();

                    var table = new Table
                    {
                        Border = TableBorder.Rounded
                    };

                    for (int i = 0; i < dbDataReader.FieldCount; i++)
                    {
                        table.AddColumn($"[green]{Markup.Escape(dbDataReader.GetName(i))}[/]");
                    }

                    while (dbDataReader.Read())
                    {
                        var list = new List <string>();

                        for (int i = 0; i < dbDataReader.FieldCount; i++)
                        {
                            var value = dbDataReader[i];

                            list.Add(Markup.Escape(value switch
                            {
                                byte[] bArr => Convert.ToBase64String(bArr),
                                DateTime dt => dt.ToString("u"),
                                _ => value.ToString()
                            }));
                        }

                        table.AddRow(list.ToArray());
                    }