Beispiel #1
0
        static async Task Main(string[] args)
        {
            // var result = KataService.EnglishToMorse("The wizard quickly jinxed the gnomes before they vaporized.");
            var result = KataService.MorseToEnglish("..- .... ..-. .-.. --- .-    ...-");

            Console.WriteLine(result);
        }
Beispiel #2
0
        public async Task <CardAttemptPayload> AttemptKataAsync(
            AttemptKataInput input,
            [GlobalState] int currentUserId,
            [Service] AppDbContext db,
            [Service] KataService kata,
            CancellationToken cancellationToken)
        {
            var now        = DateTime.UtcNow;
            var engineName = input.EvaluationEngine switch {
                EvaluationEngine.Python => "python",
                _ => throw new QueryException(
                          ErrorBuilder
                          .New()
                          .SetMessage("Invalid execution engine")
                          .SetCode("INVALID_EXECUTION_ENGINE").Build())
            };

            var req = new KataRequest
            {
                Source = input.Guess,
                ExecutionEnvironment = engineName,
                ExecutionContext     = "default",
            };

            try
            {
                var kataResult = await kata.RunKata(req);

                var user = await db.Users.FindAsync(currentUserId);

                var card = await db.Cards.FindAsync(input.CardId);

                var cardAttempt = new CardAttempt
                {
                    Result               = (AttemptResult)kataResult.ResponseCode,
                    ResultText           = kataResult.ResponseText,
                    TimeBeforeResponding = TimeSpan.FromSeconds(1), // TODO
                    AttemptedAt          = now,
                    User = user,
                    Card = card,
                };

                card.MarkAttempt(cardAttempt.Result);
                db.CardAttempts.Add(cardAttempt);
                await db.SaveChangesAsync();

                return(new CardAttemptPayload(cardAttempt, input.ClientMutationId));
            }
            catch (KataExecutionException)
            {
                throw new QueryException(
                          ErrorBuilder
                          .New()
                          .SetMessage("Internal error, kata did not execute.")
                          .SetCode("KATA_RUNTIME").Build());
            }
        }
Beispiel #3
0
 public KataService_IsPrimeShould()
 {
     _kataService = new KataService();
 }