Ejemplo n.º 1
0
        public void SendAnalytics()
        {
            LogRequestDTO  newLog = new LogRequestDTO();
            LoggingService _ls    = new LoggingService();

            newLog.setSource(DTO.Constants.Constants.Sources.Session);
            newLog.details = "testing stacktrace";
            Random rand = new Random();

            for (var i = 0; i < 20; i++)
            {
                User    newUser    = CreateUserObject();
                Session newSession = CreateSessionObject(newUser);
                CreateSessionInDb(newSession);
                newLog.ssoUserId = newUser.Id.ToString();
                newLog.setPage(DTO.Constants.Constants.Pages.PointDetails);
                for (var j = 0; j < 3; j++)
                {
                    var month = rand.Next(8, 12);
                    newLog.logCreatedAt = new DateTime(2018, 12, 21);
                    newLog.setSource(DTO.Constants.Constants.Sources.Login);
                    var pageDuration = rand.Next(1, 600);
                    newLog.pageDuration = pageDuration;
                    if (j == 0)
                    {
                        newLog.setSource(DTO.Constants.Constants.Sources.Registration);
                        newLog.setPage(DTO.Constants.Constants.Pages.MapView);
                    }
                    var duration = rand.Next(1, 1000);
                    if (duration < 300)
                    {
                        newLog.setPage(DTO.Constants.Constants.Pages.AdminDashboard);
                    }
                    else if (duration < 500)
                    {
                        newLog.setPage(DTO.Constants.Constants.Pages.PointDetails);
                    }
                    else if (duration < 700)
                    {
                        newLog.setPage(DTO.Constants.Constants.Pages.PointEditor);
                    }

                    newLog.sessionCreatedAt = newSession.CreatedAt;
                    newLog.sessionExpiredAt = newSession.ExpiresAt.AddSeconds(duration);
                    newLog.sessionUpdatedAt = newSession.UpdatedAt.AddSeconds(duration);
                    newLog.token            = newSession.Token;
                    newLog = (LogRequestDTO)getLogContent(newLog);
                    _ls.sendLogSync(newLog);
                }
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult LogWebpageUsage(LogWebpageUsageRequest payload)
        {
            try
            {
                // Throws SessionNotFound
                //var session = ControllerHelpers.ValidateSession(Request);
                var isValidPage = Enum.IsDefined(typeof(Constants.Pages), payload.Page);
                if (!isValidPage)
                {
                    return(Content(HttpStatusCode.PreconditionFailed, "Webpage is not valid."));
                }

                var session = ControllerHelpers.ValidateAndUpdateSession(Request);
                newLog = new LogRequestDTO(Constants.Sources.Analytics, session.UserId.ToString(), session.CreatedAt, session.UpdatedAt,
                                           session.ExpiresAt, session.Token);
                Constants.Pages page;
                Enum.TryParse(payload.Page, out page);
                newLog.setPage(page);
                newLog.pageDuration = payload.GetDuration();
                logger.sendLogAsync(newLog);

                return(Ok("Webpage (" + payload.Page + ") usage has been logged."));
            }
            catch (Exception e) when(e is NoTokenProvidedException ||
                                     e is SessionNotFoundException)
            {
                return(Content(HttpStatusCode.Unauthorized, e.Message));
            }
            catch (Exception e) when(e is ArgumentException)
            {
                return(Content(HttpStatusCode.PreconditionFailed, e.Message));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, e.Message));
            }
        }