Exemplo n.º 1
0
        public ActionResult Post([FromBody] EventPostRequest request = null)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                EventModel item = _mapper.Map <EventModel>(request);
                item.Id         = Guid.NewGuid();
                item.CreateDate = DateTime.UtcNow;
                item.UpdateDate = DateTime.UtcNow;
                ResultService result = this._eventsService.Insert(item);
                if (result.Success)
                {
                    return(CreatedAtAction("Post", new { item.Id }, item.Id));
                }
                else
                {
                    return(StatusCode(500, result.ErrorCode));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ErrorCode.Unknown));
                //TODO: Log the Exception.
            }
        }
Exemplo n.º 2
0
        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"));

                var request = new EventPostRequest
                {
                    // the event save should've been tested in the logic tests
                    // here only needs to test the data can go across the wire
                    AuthToken    = "83-B6-77-B8-54-83-30-7D-0F-EE-68-38-6D-E7-42-5E-2A-D1-3A-72",
                    AskHelpEvent = new AskForHelpEvent
                    {
                        SolutionName = "solution",
                        Code         = "c#",
                        SenderId     = 1
                    }
                };

                var response = await client.PostAsJsonAsync("api/eventcollection/post", request);

                return(response.IsSuccessStatusCode);
            }
        }
Exemplo n.º 3
0
        private static EventPostRequest GetEventPostWebRequest(IActivityEvent log, string authToken)
        {
            var request = new EventPostRequest
            {
                AuthToken = authToken,
            };

            switch (log.EventType)
            {
            case EventType.AskForHelpEvent:
                request.AskHelpEvent = (AskForHelpEvent)log;
                break;

            case EventType.BuildEvent:
                request.BuildEvent = (BuildEvent)log;
                break;

            case EventType.CutCopyPasteEvent:
                request.CutCopyPasteEvent = (CutCopyPasteEvent)log;
                break;

            case EventType.DebugEvent:
                request.DebugEvent = (DebugEvent)log;
                break;

            case EventType.EditorActivityEvent:
                request.EditorActivityEvent = (EditorActivityEvent)log;
                break;

            case EventType.ExceptionEvent:
                request.ExceptionEvent = (ExceptionEvent)log;
                break;

            case EventType.FeedPostEvent:
                request.FeedPostEvent = (FeedPostEvent)log;
                break;

            case EventType.LogCommentEvent:
                request.LogCommentEvent = (LogCommentEvent)log;
                break;

            case EventType.HelpfulMarkGivenEvent:
                request.HelpfulMarkEvent = (HelpfulMarkGivenEvent)log;
                break;

            case EventType.SaveEvent:
                request.SaveEvent = (SaveEvent)log;
                break;

            case EventType.SubmitEvent:
                request.SubmitEvent = (SubmitEvent)log;
                break;
            }

            return(request);
        }
        /// <summary>
        /// Finds the first non-null Event in an EventPostRequest and returns that
        /// </summary>
        /// <param name="requestObject">
        /// requestObject has the following POCO format
        /// public AskForHelpEvent AskHelpEvent { get; set; }
        /// public BuildEvent BuildEvent { get; set; }
        /// public CutCopyPasteEvent CutCopyPasteEvent { get; set; }
        /// public DebugEvent DebugEvent { get; set; }
        /// public EditorActivityEvent EditorActivityEvent { get; set; }
        /// public ExceptionEvent ExceptionEvent { get; set; }
        /// public FeedPostEvent FeedPostEvent { get; set; }
        /// public HelpfulMarkGivenEvent HelpfulMarkEvent { get; set; }
        /// public LogCommentEvent LogCommentEvent { get; set; }
        /// public SaveEvent SaveEvent { get; set; }
        /// public SubmitEvent SubmitEvent { get; set; }
        /// </param>
        /// <returns></returns>
        public static ActivityEvent GetActivityEvent(EventPostRequest requestObject)
        {
            if (requestObject.AskHelpEvent != null)
            {
                return(requestObject.AskHelpEvent);
            }

            if (requestObject.BuildEvent != null)
            {
                return(requestObject.BuildEvent);
            }

            if (requestObject.CutCopyPasteEvent != null)
            {
                return(requestObject.CutCopyPasteEvent);
            }

            if (requestObject.DebugEvent != null)
            {
                return(requestObject.DebugEvent);
            }

            if (requestObject.EditorActivityEvent != null)
            {
                return(requestObject.EditorActivityEvent);
            }

            if (requestObject.ExceptionEvent != null)
            {
                return(requestObject.ExceptionEvent);
            }

            if (requestObject.FeedPostEvent != null)
            {
                return(requestObject.FeedPostEvent);
            }

            if (requestObject.HelpfulMarkEvent != null)
            {
                return(requestObject.HelpfulMarkEvent);
            }

            if (requestObject.LogCommentEvent != null)
            {
                return(requestObject.LogCommentEvent);
            }

            if (requestObject.SubmitEvent != null)
            {
                return(requestObject.SubmitEvent);
            }

            return(requestObject.SaveEvent);
        }
Exemplo n.º 5
0
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public async Task <RepositoryResponse> AddEventAsync(Event @event)
        {
            var client          = _httpClientFactory.CreateClient(HttpClientNames.UserAuthorized);
            var request         = new EventPostRequest(@event.Name);
            var httpRequestFunc = () => client.PostAsJsonAsync(Server.Endpoints.Event.Post, request, Json.ServerSerializerOptions);
            var response        = await _httpResponseHandler.HandleAsync <EventPostResponse>(httpRequestFunc).ConfigureAwait(false);

            if (response.IsSuccesfull)
            {
                @event.Id = response.Value !.Id;
            }

            return(response);
        }
Exemplo n.º 6
0
        public static async Task <int> SubmitLog(EventPostRequest request)
        {
            using (var client = GetClient())
            {
                try
                {
                    var   task = client.PostAsXmlAsync("api/eventcollection/post", request);
                    await task;

                    var result = JsonConvert.DeserializeObject <int>(task.Result.Content.ReadAsStringAsync().Result);
                    return(result);
                }
                catch (Exception)
                {
                    return(0);
                }
            }
        }
Exemplo n.º 7
0
        public HttpResponseMessage Post(EventPostRequest request)
        {
            var auth = new Authentication();

            if (!auth.IsValidKey(request.AuthToken))
            {
                return new HttpResponseMessage {
                           StatusCode = HttpStatusCode.Forbidden
                }
            }
            ;

            var log = EventCollectionControllerHelper.GetActivityEvent(request);

            log.SenderId = auth.GetActiveUserId(request.AuthToken);

            var result = Posts.SaveEvent(log);

            //For now we're only pushing these events to the hub
            if (log.EventType.ToString() == "AskForHelpEvent" || log.EventType.ToString() == "SubmitEvent")
            {
                //post to feed hub here.
                NotifyHub(result, log.SenderId, log.EventType.ToString(), log.CourseId ?? 0);
            }

            //we've processed the log, now process for intervention.
            ProcessLogForIntervention(log);


            //push suggestion changes (it will only do so if suggestions need refreshing)
            NotifyNewSuggestion(log.SenderId, log.CourseId ?? 0, request.AuthToken);

            return(new HttpResponseMessage
            {
                StatusCode = result > 0 ? HttpStatusCode.OK : HttpStatusCode.InternalServerError,
                Content = new StringContent(result.ToString())
            });
        }