private void loadQuestion()
        {
            GetQuestionRequest getQuestionRequest = new GetQuestionRequest();

            app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(getQuestionRequest, Constants.GET_QUESTION_REQUEST)).ContinueWith(task =>
            {
                ResponseInfo response = task.Result;
                GetQuestionResponse getQuestionResponse = JsonDeserializer.deserializeResponse <GetQuestionResponse>(response.buffer);

                switch (getQuestionResponse.status)
                {
                case Constants.GET_QUESTION_SUCCESS:

                    this.Dispatcher.Invoke(() =>
                    {
                        LoadQuestionToUI(getQuestionResponse);
                    });
                    break;

                case Constants.GET_QUESTION_FINISHED:
                    thr.Abort();
                    MyMessageQueue.Enqueue("You finished!");
                    this.Dispatcher.Invoke(() =>
                    {
                        NavigationService ns = NavigationService.GetNavigationService(this);
                        ns.Navigate(new Uri("LeaderboardScreen.xaml", UriKind.Relative));
                    });
                    break;
                }
            });
        }
示例#2
0
        public void GetQuestionRequestObject()
        {
            moq::Mock <QuestionService.QuestionServiceClient> mockGrpcClient = new moq::Mock <QuestionService.QuestionServiceClient>(moq::MockBehavior.Strict);
            GetQuestionRequest request = new GetQuestionRequest
            {
                QuestionName = QuestionName.FromProjectLocationQuestion("[PROJECT]", "[LOCATION]", "[QUESTION]"),
                ReadMask     = new wkt::FieldMask(),
            };
            Question expectedResponse = new Question
            {
                QuestionName          = QuestionName.FromProjectLocationQuestion("[PROJECT]", "[LOCATION]", "[QUESTION]"),
                Scopes                = { "scopes35c99a1e", },
                Query                 = "queryf0c71c1b",
                DataSourceAnnotations =
                {
                    "data_source_annotationscbcadb22",
                },
                InterpretError  = new InterpretError(),
                Interpretations =
                {
                    new Interpretation(),
                },
                CreateTime = new wkt::Timestamp(),
                UserEmail  = "user_emaildc7bc240",
                DebugFlags = new DebugFlags(),
                DebugInfo  = new wkt::Any(),
            };

            mockGrpcClient.Setup(x => x.GetQuestion(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            QuestionServiceClient client = new QuestionServiceClientImpl(mockGrpcClient.Object, null);
            Question response            = client.GetQuestion(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
 public async Task<QuestionDto> Get([FromUri] int id)
 {
     var request = new GetQuestionRequest
     {
         Id = id
     };
     return await _mediator.ExecuteAsync(request).ConfigureAwait(false);
 }
        public async Task <QuestionDto> Get([FromUri] int id)
        {
            var request = new GetQuestionRequest
            {
                Id = id
            };

            return(await _mediator.ExecuteAsync(request).ConfigureAwait(false));
        }
示例#5
0
        public override Task <GetQuestionReply> GetQuestion(GetQuestionRequest request, ServerCallContext context)
        {
            //var question = new Question() { Content = "question from server" };
            //var answers = new List<Answer>() {
            //new Answer(){ Id = 1, Content = "First answer" },
            //new Answer(){ Id = 2, Content = "Some other answer" },
            //new Answer(){ Id = 3, Content = "Bad one" }};

            //var reply = new GetQuestionReply() { Question = question };
            //reply.PossibleAnswers.AddRange(answers);

            var response = GetQuestionFromDb(request.QuestionNumber);

            return(Task.FromResult(response.Result));
        }
 /// <summary>Snippet for GetQuestion</summary>
 public void GetQuestionRequestObject()
 {
     // Snippet: GetQuestion(GetQuestionRequest, CallSettings)
     // Create client
     QuestionServiceClient questionServiceClient = QuestionServiceClient.Create();
     // Initialize request argument(s)
     GetQuestionRequest request = new GetQuestionRequest
     {
         QuestionName = QuestionName.FromProjectLocationQuestion("[PROJECT]", "[LOCATION]", "[QUESTION]"),
         ReadMask     = new FieldMask(),
     };
     // Make the request
     Question response = questionServiceClient.GetQuestion(request);
     // End snippet
 }
        /// <summary>Snippet for GetQuestionAsync</summary>
        public async Task GetQuestionRequestObjectAsync()
        {
            // Snippet: GetQuestionAsync(GetQuestionRequest, CallSettings)
            // Additional: GetQuestionAsync(GetQuestionRequest, CancellationToken)
            // Create client
            QuestionServiceClient questionServiceClient = await QuestionServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetQuestionRequest request = new GetQuestionRequest
            {
                QuestionName = QuestionName.FromProjectLocationQuestion("[PROJECT]", "[LOCATION]", "[QUESTION]"),
                ReadMask     = new FieldMask(),
            };
            // Make the request
            Question response = await questionServiceClient.GetQuestionAsync(request);

            // End snippet
        }
示例#8
0
        public async stt::Task GetQuestionResourceNamesAsync()
        {
            moq::Mock <QuestionService.QuestionServiceClient> mockGrpcClient = new moq::Mock <QuestionService.QuestionServiceClient>(moq::MockBehavior.Strict);
            GetQuestionRequest request = new GetQuestionRequest
            {
                QuestionName = QuestionName.FromProjectLocationQuestion("[PROJECT]", "[LOCATION]", "[QUESTION]"),
            };
            Question expectedResponse = new Question
            {
                QuestionName          = QuestionName.FromProjectLocationQuestion("[PROJECT]", "[LOCATION]", "[QUESTION]"),
                Scopes                = { "scopes35c99a1e", },
                Query                 = "queryf0c71c1b",
                DataSourceAnnotations =
                {
                    "data_source_annotationscbcadb22",
                },
                InterpretError  = new InterpretError(),
                Interpretations =
                {
                    new Interpretation(),
                },
                CreateTime = new wkt::Timestamp(),
                UserEmail  = "user_emaildc7bc240",
                DebugFlags = new DebugFlags(),
                DebugInfo  = new wkt::Any(),
            };

            mockGrpcClient.Setup(x => x.GetQuestionAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Question>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            QuestionServiceClient client  = new QuestionServiceClientImpl(mockGrpcClient.Object, null);
            Question responseCallSettings = await client.GetQuestionAsync(request.QuestionName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Question responseCancellationToken = await client.GetQuestionAsync(request.QuestionName, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
示例#9
0
        public GetQuestionResponse GetQuestion(GetQuestionRequest request)
        {
            GetQuestionResponse response = new GetQuestionResponse();

            AuthToken authToken = null;

            try
            {
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.AuthToken, "Auth Token");

                if (!UserController.ValidateSession(request.AuthToken, out authToken))
                {
                    throw new AuthenticationException("Authentication failed.");
                }

                DbContext context = DataController.CreateDbContext();

                E::Question question = context.Questions
                                       .Where(q => q.ID == request.QuestionID)
                                       .FirstOrDefault();

                response.QuestionBody = DataController.DownloadBlob(question.QuestionBody.ToString());

                response.Name            = question.Name;
                response.LastUpdatedBy   = question.LastUpdatedBy;
                response.LastUpdatedDate = question.LastUpdatedDate.ToShortDateString();
                response.CreatedBy       = question.CreatedBy;
                response.CreatedDate     = question.CreatedDate.ToShortDateString();

                response.CanEdit = !context.InterviewQuestions
                                   .Where(q => q.QuestionID == request.QuestionID)
                                   .Where(q => q.Interview.StartedDate.HasValue)
                                   .Any();

                response.IsCodedTest = question.QuestionTypeID == (short)QuestionType.Coded;

                if (!response.IsCodedTest)
                {
                    var tests = TestsController.FromJson(DataController.DownloadBlob(question.Tests.Value.ToString()));

                    IList <QuestionTest> questionTests = new List <QuestionTest>();

                    foreach (var test in tests.AsEnumerable())
                    {
                        QuestionTest questionTest = new QuestionTest();

                        questionTest.ID             = test.ID;
                        questionTest.Name           = test.Name;
                        questionTest.Input          = test.Input;
                        questionTest.ExpectedOutput = test.ExpectedOutput;

                        questionTests.Add(questionTest);
                    }

                    response.Tests = questionTests.ToArray();
                }
                else
                {
                    response.Tests = new QuestionTest[0];
                }
            }
            catch (AuthenticationException ex)
            {
                throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            catch (Common.Exceptions.ValidationException ex)
            {
                throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            catch (Exception ex)
            {
                ExceptionHelper.Log(ex, authToken == null ? null : authToken.Username);
                throw new WebFaultException <string>("An unknown error has occurred.", System.Net.HttpStatusCode.InternalServerError);
            }

            return(response);
        }
示例#10
0
 public string BuildQueryString(GetQuestionRequest request)
 => string.Format(QueryTemplates.MillionaireRequestQueryTemplate, Quiz.LifeIsPornConnection, Quiz.ScriptMillionaire, (int)request.QType, request.Count, request.ApiKey);