public IHttpActionResult GetByProject(string projectId, DateTime?start = null, DateTime?end = null, bool hidden = false, bool @fixed = false, bool notfound = true) { if (String.IsNullOrEmpty(projectId)) { return(NotFound()); } Project project = _projectRepository.GetById(projectId, true); if (project == null || !CanAccessOrganization(project.OrganizationId)) { return(NotFound()); } var range = GetDateRange(start, end); if (range.Item1 == range.Item2) { return(BadRequest("End date must be greater than start date.")); } DateTime retentionUtcCutoff = _organizationRepository.GetById(project.OrganizationId, true).GetRetentionUtcCutoff(); ProjectEventStatsResult result = _statsHelper.GetProjectErrorStats(projectId, _projectRepository.GetDefaultTimeOffset(projectId), start, end, retentionUtcCutoff, hidden, @fixed, notfound); result.MostFrequent = null; result.MostRecent = null; return(Ok(result)); }
public IHttpActionResult Frequent(string projectId, int page = 1, int limit = 10, DateTime?start = null, DateTime?end = null, bool hidden = false, bool @fixed = false, bool notfound = true) { if (String.IsNullOrEmpty(projectId)) { return(NotFound()); } Project project = _projectRepository.GetById(projectId, true); if (project == null || !CanAccessOrganization(project.OrganizationId)) { return(NotFound()); } var range = GetDateRange(start, end); if (range.Item1 == range.Item2) { return(BadRequest("End date must be greater than start date.")); } limit = GetLimit(limit); DateTime retentionUtcCutoff = _organizationRepository.GetById(project.OrganizationId, true).GetRetentionUtcCutoff(); var frequent = _statsHelper.GetProjectErrorStats(projectId, _projectRepository.GetDefaultTimeOffset(projectId), start, end, retentionUtcCutoff, hidden, @fixed, notfound).MostFrequent; var results = frequent.Results.Skip(GetSkip(page, limit)).Take(limit).ToList(); var stacks = _stackRepository.GetByIds(results.Select(s => s.Id).ToList()); foreach (var esr in results) { var stack = stacks.SingleOrDefault(s => s.Id == esr.Id); if (stack == null) { results.RemoveAll(r => r.Id == esr.Id); continue; } // Stat's Id and Total properties are already calculated in the Results. esr.Type = stack.SignatureInfo.ContainsKey("ExceptionType") ? stack.SignatureInfo["ExceptionType"] : null; esr.Method = stack.SignatureInfo.ContainsKey("Method") ? stack.SignatureInfo["Method"] : null; esr.Path = stack.SignatureInfo.ContainsKey("Path") ? stack.SignatureInfo["Path"] : null; esr.Is404 = stack.SignatureInfo.ContainsKey("Path"); esr.Title = stack.Title; esr.First = stack.FirstOccurrence; esr.Last = stack.LastOccurrence; } Dictionary <string, IEnumerable <string> > header = null; if (frequent.Results.Count != limit && frequent.TotalLimitedByPlan.HasValue) { header = GetLimitedByPlanHeader(frequent.TotalLimitedByPlan.Value); } return(OkWithResourceLinks(results, frequent.Results.Count > (GetSkip(page, limit) + limit), e => e.Id, header)); }
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); }