Exemplo n.º 1
0
        private void ProcessSummaryNotification(SummaryNotification data)
        {
            var project      = _projectRepository.GetById(data.Id, true);
            var organization = _organizationRepository.GetById(project.OrganizationId, true);
            var userIds      = project.NotificationSettings.Where(n => n.Value.SendDailySummary).Select(n => n.Key).ToList();

            if (userIds.Count == 0)
            {
                return;
            }

            var users = _userRepository.GetByIds(userIds).Where(u => u.IsEmailAddressVerified).ToList();

            if (users.Count == 0)
            {
                return;
            }

            long count;
            var  paging = new PagingOptions {
                Limit = 5
            };
            List <Stack> newest = _stackRepository.GetNew(project.Id, data.UtcStartTime, data.UtcEndTime, paging).ToList();

            var result       = _stats.GetTermsStats(data.UtcStartTime, data.UtcEndTime, "stack_id", "project:" + data.Id, max: 5);
            var mostFrequent = result.Terms.Take(5).ToList();
            var stacks       = _stackRepository.GetByIds(mostFrequent.Select(s => s.Term).ToList());

            foreach (var frequent in mostFrequent)
            {
                var stack = stacks.SingleOrDefault(s => s.Id == frequent.Term);
                if (stack == null)
                {
                    mostFrequent.RemoveAll(r => r.Term == frequent.Term);
                    continue;
                }

                // Stat's Id and Total properties are already calculated in the Results.
                //frequent.Type = stack.SignatureInfo.ContainsKey("ExceptionType") ? stack.SignatureInfo["ExceptionType"] : null;
                //frequent.Method = stack.SignatureInfo.ContainsKey("Method") ? stack.SignatureInfo["Method"] : null;
                //frequent.Path = stack.SignatureInfo.ContainsKey("Path") ? stack.SignatureInfo["Path"] : null;
                //frequent.Is404 = stack.SignatureInfo.ContainsKey("Path");

                //frequent.Title = stack.Title;
                //frequent.First = stack.FirstOccurrence;
                //frequent.Last = stack.LastOccurrence;
            }

            var notification = new SummaryNotificationModel {
                ProjectId   = project.Id,
                ProjectName = project.Name,
                StartDate   = data.UtcStartTime,
                EndDate     = data.UtcEndTime,
                //Total = result.Total,
                //PerHourAverage = result.PerHourAverage,
                //NewTotal = result.NewTotal,
                //New = newest,
                //UniqueTotal = result.UniqueTotal,
                //MostFrequent = mostFrequent,
                //HasSubmittedErrors = project.TotalErrorCount > 0,
                IsFreePlan = organization.PlanId == BillingManager.FreePlan.Id
            };

            foreach (var user in users.Where(u => u.EmailNotificationsEnabled))
            {
                _mailer.SendSummaryNotification(user.EmailAddress, notification);
            }
        }
        private object ProcessSummaryNotification(IMessage <SummaryNotification> message)
        {
            var project      = _projectRepository.GetByIdCached(message.GetBody().Id);
            var organization = _organizationRepository.GetByIdCached(project.OrganizationId);
            var userIds      = project.NotificationSettings.Where(n => n.Value.SendDailySummary).Select(n => n.Key).ToList();

            if (userIds.Count == 0)
            {
                return(null);
            }

            var users = _userRepository.GetByIds(userIds).Where(u => u.IsEmailAddressVerified).ToList();

            if (users.Count == 0)
            {
                return(null);
            }

            long         count;
            List <Stack> newest = _stackRepository.GetNew(project.Id, message.GetBody().UtcStartTime, message.GetBody().UtcEndTime, 0, 5, out count).ToList();

            DateTime start        = _projectRepository.UtcToDefaultProjectLocalTime(project.Id, message.GetBody().UtcStartTime);
            DateTime end          = _projectRepository.UtcToDefaultProjectLocalTime(project.Id, message.GetBody().UtcEndTime);
            var      result       = _eventStatsHelper.GetProjectErrorStats(project.Id, _projectRepository.GetDefaultTimeOffset(project.Id), start, end);
            var      mostFrequent = result.MostFrequent.Results.Take(5).ToList();
            var      errorStacks  = _stackRepository.GetByIds(mostFrequent.Select(s => s.Id));

            foreach (var frequent in mostFrequent)
            {
                var stack = errorStacks.SingleOrDefault(s => s.Id == frequent.Id);
                if (stack == null)
                {
                    mostFrequent.RemoveAll(r => r.Id == frequent.Id);
                    continue;
                }

                // Stat's Id and Total properties are already calculated in the Results.
                frequent.Type   = stack.SignatureInfo.ContainsKey("ExceptionType") ? stack.SignatureInfo["ExceptionType"] : null;
                frequent.Method = stack.SignatureInfo.ContainsKey("Method") ? stack.SignatureInfo["Method"] : null;
                frequent.Path   = stack.SignatureInfo.ContainsKey("Path") ? stack.SignatureInfo["Path"] : null;
                frequent.Is404  = stack.SignatureInfo.ContainsKey("Path");

                frequent.Title = stack.Title;
                frequent.First = stack.FirstOccurrence;
                frequent.Last  = stack.LastOccurrence;
            }

            var notification = new SummaryNotificationModel {
                ProjectId          = project.Id,
                ProjectName        = project.Name,
                StartDate          = start,
                EndDate            = end,
                Total              = result.Total,
                PerHourAverage     = result.PerHourAverage,
                NewTotal           = result.NewTotal,
                New                = newest,
                UniqueTotal        = result.UniqueTotal,
                MostFrequent       = mostFrequent,
                HasSubmittedErrors = project.TotalErrorCount > 0,
                IsFreePlan         = organization.PlanId == BillingManager.FreePlan.Id
            };

            foreach (var user in users.Where(u => u.EmailNotificationsEnabled))
            {
                _mailer.SendSummaryNotification(user.EmailAddress, notification);
            }

            return(null);
        }
Exemplo n.º 3
0
        private void ProcessSummaryNotification(SummaryNotification data)
        {
            var project      = _projectRepository.GetById(data.Id, true);
            var organization = _organizationRepository.GetById(project.OrganizationId, true);
            var userIds      = project.NotificationSettings.Where(n => n.Value.SendDailySummary).Select(n => n.Key).ToList();

            if (userIds.Count == 0)
            {
                Log.Info().Message("Project \"{0}\" has no users to send summary to.", project.Id).Write();
                return;
            }

            var users = _userRepository.GetByIds(userIds).Where(u => u.IsEmailAddressVerified && u.EmailNotificationsEnabled && u.OrganizationIds.Contains(organization.Id)).ToList();

            if (users.Count == 0)
            {
                Log.Info().Message("Project \"{0}\" has no users to send summary to.", project.Id).Write();
                return;
            }

            Log.Info().Message("Sending daily summary: users={0} project={1}", users.Count, project.Id).Write();
            var paging = new PagingOptions {
                Limit = 5
            };
            List <Stack> newest = _stackRepository.GetNew(project.Id, data.UtcStartTime, data.UtcEndTime, paging).ToList();

            var  result             = _stats.GetTermsStats(data.UtcStartTime, data.UtcEndTime, "stack_id", "project:" + data.Id, max: 5);
            var  termStatsList      = result.Terms.Take(5).ToList();
            var  stacks             = _stackRepository.GetByIds(termStatsList.Select(s => s.Term).ToList());
            bool hasSubmittedErrors = result.Total > 0;

            if (!hasSubmittedErrors)
            {
                hasSubmittedErrors = _eventRepository.GetCountByProjectId(project.Id) > 0;
            }

            var mostFrequent = new List <EventStackResult>();

            foreach (var termStats in termStatsList)
            {
                var stack = stacks.SingleOrDefault(s => s.Id == termStats.Term);
                if (stack == null)
                {
                    continue;
                }

                mostFrequent.Add(new EventStackResult {
                    First  = termStats.FirstOccurrence,
                    Last   = termStats.LastOccurrence,
                    Id     = stack.Id,
                    Title  = stack.Title,
                    Total  = termStats.Total,
                    Type   = stack.SignatureInfo.ContainsKey("ExceptionType") ? stack.SignatureInfo["ExceptionType"] : null,
                    Method = stack.SignatureInfo.ContainsKey("Method") ? stack.SignatureInfo["Method"] : null,
                    Path   = stack.SignatureInfo.ContainsKey("Source") ? stack.SignatureInfo["Source"] : null,
                    Is404  = stack.SignatureInfo.ContainsKey("Type") && stack.SignatureInfo["Type"] == "404"
                });
            }

            var notification = new DailySummaryModel {
                ProjectId          = project.Id,
                ProjectName        = project.Name,
                StartDate          = data.UtcStartTime,
                EndDate            = data.UtcEndTime,
                Total              = result.Total,
                PerHourAverage     = result.Total / data.UtcEndTime.Subtract(data.UtcStartTime).TotalHours,
                NewTotal           = result.New,
                New                = newest,
                UniqueTotal        = result.Unique,
                MostFrequent       = mostFrequent,
                HasSubmittedEvents = hasSubmittedErrors,
                IsFreePlan         = organization.PlanId == BillingManager.FreePlan.Id
            };

            foreach (var user in users)
            {
                _mailer.SendDailySummary(user.EmailAddress, notification);
            }

            Log.Info().Message("Done sending daily summary: users={0} project={1} events={2}", users.Count, project.Id, notification.Total).Write();
        }