private PlanPagedResult <ErrorStackResult> Frequent(List <ErrorStackResult> result, long totalLimitedByPlan, int page = 1, int pageSize = 10) { int skip = (page - 1) * pageSize; if (skip < 0) { skip = 0; } if (pageSize < 1) { pageSize = 10; } var ers = new PlanPagedResult <ErrorStackResult>(result.Skip(skip).Take(pageSize).ToList(), totalLimitedByPlan); IQueryable <ErrorStack> errorStacks = _errorStackRepository.GetByIds(ers.Results.Select(s => s.Id)); foreach (ErrorStackResult stats in ers.Results.ToList()) { ErrorStack stack = errorStacks.SingleOrDefault(s => s.Id == stats.Id); if (stack == null) { ers.Results.RemoveAll(r => r.Id == stats.Id); continue; } // Stat's Id and Total properties are already calculated in the Results. stats.Type = stack.SignatureInfo.ContainsKey("ExceptionType") ? stack.SignatureInfo["ExceptionType"] : null; stats.Method = stack.SignatureInfo.ContainsKey("Method") ? stack.SignatureInfo["Method"] : null; stats.Path = stack.SignatureInfo.ContainsKey("Path") ? stack.SignatureInfo["Path"] : null; stats.Is404 = stack.SignatureInfo.ContainsKey("Path"); stats.Title = stack.Title; stats.First = stack.FirstOccurrence; stats.Last = stack.LastOccurrence; } ers.TotalLimitedByPlan = ers.Results.Count != pageSize ? totalLimitedByPlan : 0; ers.TotalCount = result.Count + totalLimitedByPlan; ers.Page = page > 1 ? page : 1; ers.PageSize = pageSize >= 1 ? pageSize : 10; return(ers); }
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 <ErrorStack> 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 = _errorStatsHelper.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); }