Пример #1
0
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelType == typeof(SubmissionRequest))
            {
                try
                {
                    var jsonStr       = actionContext.Request.Content.ReadAsStringAsync().Result;
                    var jsonTokens    = jsonStr.Replace("\"", string.Empty).TrimStart('{').TrimEnd('}').Split(',');
                    var submitRequest = new SubmissionRequest
                    {
                        AuthToken   = jsonTokens.First(x => x.Contains("AuthToken:")).Split(':').Last(),
                        SubmitEvent = new SubmitEvent
                        {
                            CourseId     = Convert.ToInt32(jsonTokens.First(x => x.Contains("CourseId:")).Split(':').Last()),
                            AssignmentId =
                                Convert.ToInt32(jsonTokens.First(x => x.Contains("AssignmentId:")).Split(':').Last()),
                            SolutionName = jsonTokens.First(x => x.Contains("SolutionName:")).Split(':').Last(),
                        }
                    };

                    var encodedSolution = jsonTokens.First(x => x.Contains("RequestData:")).Split(':').Last();
                    submitRequest.SubmitEvent.CreateSolutionBinary(HttpServerUtility.UrlTokenDecode(encodedSolution));

                    bindingContext.Model = submitRequest;
                    return(true);
                }
                catch (Exception ex)
                {
                    var msg = ex.Message;
                    return(false);
                }
            }
            return(false);
        }
Пример #2
0
 public override Task <SubmissionResponse> SubmitNetworkTraffic(SubmissionRequest request, ServerCallContext context)
 {
     return(Task.FromResult(new SubmissionResponse
     {
         Message = string.Empty,
         Success = true
     }));
 }
Пример #3
0
        public async Task ExecuteAsync(ImageEntity imageEntity, ImageContext context, CancellationToken ct)
        {
            var request = new SubmissionRequest(context.User.Cookies, imageEntity.SubmissionType.GetAttributeValue());
            var parser  = new SubmissionResponseParser();
            var key     = await Gate.SendAsync <SubmissionRequest, string, SubmissionResponseParser>(request, parser);

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new SubmissionException("Form key not found");
            }

            context.FormKey = key;
        }
Пример #4
0
 private async Task VerificaThread(SubmisionDto submissionDtoModel)
 {
     semaphoreSlim.Wait();
     try
     {
         var submRequest = new SubmissionRequest(_submissionHub, _submisionRepository, _hubContext,
                                                 _serializeTests, _evaluationRepository);
         await submRequest.MakeSubmissionRequestAsync(submissionDtoModel, _compilationApi, _executionApi);
     }
     finally
     {
         semaphoreSlim.Release();
     }
 }
Пример #5
0
 private async void ProcessLogForIntervention(SubmissionRequest request)
 {
     using (InterventionController intervention = new InterventionController())
     {
         intervention.ProcessActivityEvent(
             EventCollectionControllerHelper.GetActivityEvent(
                 new EventPostRequest
         {
             AuthToken   = request.AuthToken,
             SubmitEvent = request.SubmitEvent
         }
                 ));
     }
 }
Пример #6
0
        public SubmissionResult SubmitCsr(SubmissionRequest s)
        {
            var submission = this.certTool.SubmitRequest(s.CmcRequest, s.AdminContactName, s.AdminAddress);

            var result = new SubmissionResult(submission.Message, submission.RequestId, (SubmissionStatus)submission.Outcome, submission.AuthorityResponse);

            if (this.configuration.CaConfiguration.AutoApprove)
            {
                return(this.AcceptCsr(result.RequestId.ToString()));
            }
            else
            {
                return(result);
            }
        }
        /// <summary>
        /// Asynchronous web api call to submit an assinment to the server.
        /// </summary>
        /// <param name="submitEvent">submitevent for the assignment to be submitted</param>
        /// <param name="authToken">authorization token</param>
        /// <returns>HttpResponseMessage</returns>
        public static async Task <HttpResponseMessage> SubmitAssignment(SubmitEvent submitEvent, string authToken)
        {
            using (var client = ServiceClient.GetClient())
            {
                //package submitevent and authtoken within a SubmissionRequest
                var request = new SubmissionRequest
                {
                    AuthToken   = authToken,
                    SubmitEvent = submitEvent,
                };

                var response = await client.PostAsXmlAsync("api/course/post", request);

                return(response);
            }
        }
Пример #8
0
        public static async Task <int> SubmitAssignment(SubmitEvent submitEvent, string authToken)
        {
            using (var client = GetClient())
            {
                var request = new SubmissionRequest
                {
                    AuthToken   = authToken,
                    SubmitEvent = submitEvent,
                };
                var response = await client.PostAsXmlAsync("api/course/post", request);

                return(response.IsSuccessStatusCode
                        ? JsonConvert.DeserializeObject <int>(response.Content.ReadAsStringAsync().Result)
                        : 0);
            }
        }
Пример #9
0
        public async Task Submit_GivenValidTicketAndToken_Expect200Ok()
        {
            //Arrange
            var mockVault = Substitute.For <IVault>();

            mockVault.GetGameTokenAsync("Token").Returns(Task.FromResult(new Token
            {
                Value          = "Token",
                ExpirationDate = DateTime.UtcNow.Add(new TimeSpan(0, 0, 0, 10)) /* 10s in the future. */
            }));
            mockVault.AddGameTokenAsync(Arg.Any <Token>()).Returns(Task.CompletedTask);
            var mockKeyGenerator = Substitute.For <IKeyGenerator>();

            mockKeyGenerator.GenerateKey().Returns("Ticket");
            mockKeyGenerator.GenerateGameTokenAsync(Arg.Any <string>()).Returns(Task.FromResult("Token"));
            var database    = new DatabaseRepository(mockVault, mockKeyGenerator);
            var agniKaiRepo = new AgniKaiRepository(mockVault, mockKeyGenerator, database);
            var controller  = new UserController(database, mockVault);

            //Act
            var ticket = await agniKaiRepo.InitiateAgniKaiAsync();

            var token = await database.AddPlayerAsync("Player-1");

            var request = new SubmissionRequest
            {
                Ticket = ticket,
                Token  = token.Value
            };
            var action = await controller.SubmitAgniKaiTicket(request);

            var submitResponse = action as OkNegotiatedContentResult <Field>;

            //Assert
            Assert.NotNull(submitResponse);
            Assert.AreNotEqual(submitResponse.Content, Field.Empty);
            Assert.AreEqual(await database.GetPlayerCountAsync(), 1);
            await mockKeyGenerator.Received(1).GenerateKey();

            await mockVault.Received(1).AddAgniKaiTicket("Ticket");

            await mockVault.Received(1).GetGameTokenAsync("Token");
        }
Пример #10
0
        private static async Task <bool> RunAsync()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(StringConstants.DataServiceRoot);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                SubmitEvent temp = CreateSubmitEvent();

                var request = new SubmissionRequest
                {
                    AuthToken   = "83-B6-77-B8-54-83-30-7D-0F-EE-68-38-6D-E7-42-5E-2A-D1-3A-72",
                    SubmitEvent = temp,
                };
                var response = await client.PostAsJsonAsync("api/course/post", request);

                return(response.IsSuccessStatusCode);
            }
        }
Пример #11
0
        public string Submission([FromBody] SubmissionRequest submissionRequest)
        {
            var reviewerId = _QuestionRepository.AddReviewer(submissionRequest.Reviewer);

            var commentList = new List <Comment>();

            foreach (var question in submissionRequest.Questions)
            {
                if (!string.IsNullOrEmpty(question.CommentText))
                {
                    commentList.Add(new Comment {
                        QuestionId = question.Id, ReviewerId = reviewerId, CommentText = question.CommentText
                    });
                }
            }

            _QuestionRepository.AddComments(commentList);

            return(commentList.Any(x => x.CommentText.ToLower().Contains("bizlibrary")) ? "EASTER-EGG-COMMENCE" : "");
        }
Пример #12
0
        public async Task Create_GivenTicket_ExpectAICreated()
        {
            //Arrange
            var mockGamerRepo = Substitute.For <IGamerRepository>();

            mockGamerRepo.CreateGamerAsync(Arg.Any <string>()).Returns(Task.CompletedTask);
            var vault      = Substitute.For <IVault>();
            var controller = new GamerController(mockGamerRepo);
            var request    = new SubmissionRequest
            {
                Ticket = "Ticket",
                Token  = "Token"
            };

            //Act
            var action = await controller.Create(request);

            var createResponse = action as OkResult;

            //Assert
            Assert.IsNotNull(createResponse);
            await mockGamerRepo.Received(1).CreateGamerAsync("Ticket");
        }
Пример #13
0
 /// <summary>
 /// Submits a certificate signing request to the AMI.
 /// </summary>
 /// <param name="submissionRequest">The certificate signing request.</param>
 /// <returns>Returns the submission result.</returns>
 public SubmissionResult SubmitCertificateSigningRequest(SubmissionRequest submissionRequest)
 {
     return(this.Client.Post <SubmissionRequest, SubmissionResult>("Csr", submissionRequest));
 }
Пример #14
0
        public HttpResponseMessage Post(SubmissionRequest request)
        {
            var auth = new Authentication();

            if (!auth.IsValidKey(request.AuthToken))
            {
                throw new Exception("CourseController Post() authentication failure.");
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden
                });
            }

            bool eventSenderNotNull = false;

            if (request.SubmitEvent.Sender == null)
            {
                var sender = auth.GetActiveUser(request.AuthToken);
                request.SubmitEvent.SenderId = sender.IUserId;
                request.SubmitEvent.Sender   = new User
                {
                    IUserId   = sender.IUserId,
                    FirstName = sender.FirstName,
                    LastName  = sender.LastName
                };
                eventSenderNotNull = true;
            }

            int eventLogId = Posts.SaveEvent(request.SubmitEvent);

            AddToSubmitEventProperties(eventLogId);

            Posts.SaveToFileSystem(request.SubmitEvent);

            try //don't want hub notification to break post
            {
                //push the event to the hub
                if (eventSenderNotNull)
                {
                    using (EventCollectionController ecc = new EventCollectionController())
                    {
                        ecc.NotifyHub(eventLogId, request.SubmitEvent.SenderId, request.SubmitEvent.EventType.ToString(), request.SubmitEvent.CourseId ?? 0);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Failed to notifyHub in CourseController Post method. ", e);
            }

            //submit to intervetion controller
            try
            {
                ProcessLogForIntervention(request);
            }
            catch (Exception e)
            {
                throw new Exception("failed to ProcessLogForIntervention(request)", e);
            }

            return(new HttpResponseMessage
            {
                Content = new StringContent(eventLogId.ToString())
            });
        }