コード例 #1
0
        public PlanPagedResult <ErrorStackResult> Recent(string projectId, int page = 1, int pageSize = 10, DateTime?start = null, DateTime?end = null, bool hidden = false, bool @fixed = false, bool notfound = true)
        {
            if (String.IsNullOrEmpty(projectId))
            {
                throw new ArgumentNullException("projectId"); // TODO: These should probably throw http Response exceptions.
            }
            Project project = _projectRepository.GetByIdCached(projectId);

            if (project == null || !User.CanAccessOrganization(project.OrganizationId))
            {
                throw new ArgumentException("Invalid project id.", "projectId"); // TODO: These should probably throw http Response exceptions.
            }
            start = start ?? DateTime.MinValue;
            end   = end ?? DateTime.MaxValue;

            if (end.Value <= start.Value)
            {
                throw new ArgumentException("End date must be greater than start date.", "end"); // TODO: These should probably throw http Response exceptions.
            }
            DateTime utcStart           = _projectRepository.DefaultProjectLocalTimeToUtc(projectId, start.Value);
            DateTime utcEnd             = _projectRepository.DefaultProjectLocalTimeToUtc(projectId, end.Value);
            DateTime retentionUtcCutoff = _organizationRepository.GetByIdCached(project.OrganizationId).GetRetentionUtcCutoff();

            int skip = (page - 1) * pageSize;

            if (skip < 0)
            {
                skip = 0;
            }

            if (pageSize < 1)
            {
                pageSize = 10;
            }

            long count;
            List <ErrorStack> query       = _errorStackRepository.GetMostRecent(projectId, utcStart, utcEnd, skip, pageSize, out count, hidden, @fixed, notfound).ToList();
            List <ErrorStack> errorStacks = query.Where(es => es.LastOccurrence >= retentionUtcCutoff).ToList();

            var result = new PlanPagedResult <ErrorStackResult>(null, query.Count - errorStacks.Count);

            result.Results.AddRange(errorStacks.Select(s => new ErrorStackResult {
                Id     = s.Id,
                Type   = s.SignatureInfo.ContainsKey("ExceptionType") ? s.SignatureInfo["ExceptionType"] : null,
                Method = s.SignatureInfo.ContainsKey("Method") ? s.SignatureInfo["Method"] : null,
                Path   = s.SignatureInfo.ContainsKey("Path") ? s.SignatureInfo["Path"] : null,
                Is404  = s.SignatureInfo.ContainsKey("Path"),
                Title  = s.Title,
                Total  = s.TotalOccurrences,
                First  = s.FirstOccurrence,
                Last   = s.LastOccurrence
            }));

            result.TotalCount = count;
            result.Page       = page > 1 ? page : 1;
            result.PageSize   = pageSize >= 1 ? pageSize : 10;

            return(result);
        }
コード例 #2
0
        public PlanPagedResult <ErrorResult> GetByStack(string stackId, int page = 1, int pageSize = 10, DateTime?start = null, DateTime?end = null)
        {
            if (String.IsNullOrEmpty(stackId))
            {
                throw new ArgumentNullException("stackId"); // TODO: These should probably throw http Response exceptions.
            }
            ErrorStack errorStack = ErrorStackRepository.GetByIdCached(stackId);

            if (errorStack == null || !User.CanAccessOrganization(errorStack.OrganizationId))
            {
                throw new ArgumentException("Invalid error stack id.", "stackId"); // TODO: These should probably throw http Response exceptions.
            }
            start = start ?? DateTime.MinValue;
            end   = end ?? DateTime.MaxValue;

            if (end.Value <= start.Value)
            {
                throw new ArgumentException("End date must be greater than start date.", "end"); // TODO: These should probably throw http Response exceptions.
            }
            DateTime utcStart = _projectRepository.DefaultProjectLocalTimeToUtc(errorStack.ProjectId, start.Value);
            DateTime utcEnd   = _projectRepository.DefaultProjectLocalTimeToUtc(errorStack.ProjectId, end.Value);

            Project  project            = _projectRepository.GetByIdCached(errorStack.ProjectId);
            DateTime retentionUtcCutoff = _organizationRepository.GetByIdCached(project.OrganizationId).GetRetentionUtcCutoff();

            int skip = (page - 1) * pageSize;

            if (skip < 0)
            {
                skip = 0;
            }

            if (pageSize < 1)
            {
                pageSize = 10;
            }

            long         count;
            List <Error> query = _repository.GetByErrorStackIdOccurrenceDate(stackId, utcStart, utcEnd, skip, pageSize, out count).ToList();

            List <ErrorResult> models = query.Where(m => m.OccurrenceDate.UtcDateTime >= retentionUtcCutoff).Select(e => e.ToProjectLocalTime(_projectRepository)).Select(Mapper.Map <Error, ErrorResult>).ToList();

            long totalLimitedByPlan = (query.Count - models.Count) > 0 ? count - (skip + models.Count) : 0;
            var  result             = new PlanPagedResult <ErrorResult>(models, totalLimitedByPlan)
            {
                Page       = page > 1 ? page : 1,
                PageSize   = pageSize >= 1 ? pageSize : 10,
                TotalCount = count
            };

            // TODO: Only return the populated fields (currently all properties are being returned).
            return(result);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public PlanPagedResult<ErrorStackResult> RecentInternal(string projectId, int page = 1, int pageSize = 10, DateTime? start = null, DateTime? end = null, bool hidden = false, bool @fixed = false, bool notfound = true) {
            if (String.IsNullOrEmpty(projectId))
                throw new ArgumentNullException();

            Project project = _projectRepository.GetByIdCached(projectId);
            if (project == null || !User.CanAccessOrganization(project.OrganizationId))
                throw new ArgumentException();

            var range = GetDateRange(start, end);
            DateTime utcStart = _projectRepository.DefaultProjectLocalTimeToUtc(projectId, range.Item1);
            DateTime utcEnd = _projectRepository.DefaultProjectLocalTimeToUtc(projectId, range.Item2);
            DateTime retentionUtcCutoff = _organizationRepository.GetByIdCached(project.OrganizationId).GetRetentionUtcCutoff();

            pageSize = GetPageSize(pageSize);
            int skip = GetSkip(page, pageSize);

            long count;
            List<ErrorStack> query = _errorStackRepository.GetMostRecent(projectId, utcStart, utcEnd, skip, pageSize, out count, hidden, @fixed, notfound).ToList();
            List<ErrorStack> errorStacks = query.Where(es => es.LastOccurrence >= retentionUtcCutoff).ToList();

            var result = new PlanPagedResult<ErrorStackResult>(null, totalLimitedByPlan: query.Count - errorStacks.Count, totalCount: count);
            result.Results.AddRange(errorStacks.Select(s => new ErrorStackResult {
                Id = s.Id,
                Type = s.SignatureInfo.ContainsKey("ExceptionType") ? s.SignatureInfo["ExceptionType"] : null,
                Method = s.SignatureInfo.ContainsKey("Method") ? s.SignatureInfo["Method"] : null,
                Path = s.SignatureInfo.ContainsKey("Path") ? s.SignatureInfo["Path"] : null,
                Is404 = s.SignatureInfo.ContainsKey("Path"),
                Title = s.Title,
                Total = s.TotalOccurrences,
                First = s.FirstOccurrence,
                Last = s.LastOccurrence
            }));

            result.Page = page > 1 ? page : 1;
            result.PageSize = pageSize >= 1 ? pageSize : 10;

            return result;
        }
コード例 #5
0
        private PlanPagedResult<ErrorStackResult> Frequent(List<ErrorStackResult> result, long totalLimitedByPlan, int page = 1, int pageSize = 10) {
            pageSize = GetPageSize(pageSize);
            int skip = GetSkip(page, pageSize);

            var ers = new PlanPagedResult<ErrorStackResult>(result.Skip(skip).Take(pageSize).ToList());
            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;
        }
コード例 #6
0
        public PlanPagedResult<ErrorStackResult> Recent(string projectId, int page = 1, int pageSize = 10, DateTime? start = null, DateTime? end = null, bool hidden = false, bool @fixed = false, bool notfound = true) {
            if (String.IsNullOrEmpty(projectId))
                throw new ArgumentNullException("projectId"); // TODO: These should probably throw http Response exceptions.

            Project project = _projectRepository.GetByIdCached(projectId);
            if (project == null || !User.CanAccessOrganization(project.OrganizationId))
                throw new ArgumentException("Invalid project id.", "projectId"); // TODO: These should probably throw http Response exceptions.

            start = start ?? DateTime.MinValue;
            end = end ?? DateTime.MaxValue;

            if (end.Value <= start.Value)
                throw new ArgumentException("End date must be greater than start date.", "end"); // TODO: These should probably throw http Response exceptions.

            DateTime utcStart = _projectRepository.DefaultProjectLocalTimeToUtc(projectId, start.Value);
            DateTime utcEnd = _projectRepository.DefaultProjectLocalTimeToUtc(projectId, end.Value);
            DateTime retentionUtcCutoff = _organizationRepository.GetByIdCached(project.OrganizationId).GetRetentionUtcCutoff();

            int skip = (page - 1) * pageSize;
            if (skip < 0)
                skip = 0;

            if (pageSize < 1)
                pageSize = 10;

            long count;
            List<ErrorStack> query = _errorStackRepository.GetMostRecent(projectId, utcStart, utcEnd, skip, pageSize, out count, hidden, @fixed, notfound).ToList();
            List<ErrorStack> errorStacks = query.Where(es => es.LastOccurrence >= retentionUtcCutoff).ToList();

            var result = new PlanPagedResult<ErrorStackResult>(null, query.Count - errorStacks.Count);
            result.Results.AddRange(errorStacks.Select(s => new ErrorStackResult {
                Id = s.Id,
                Type = s.SignatureInfo.ContainsKey("ExceptionType") ? s.SignatureInfo["ExceptionType"] : null,
                Method = s.SignatureInfo.ContainsKey("Method") ? s.SignatureInfo["Method"] : null,
                Path = s.SignatureInfo.ContainsKey("Path") ? s.SignatureInfo["Path"] : null,
                Is404 = s.SignatureInfo.ContainsKey("Path"),
                Title = s.Title,
                Total = s.TotalOccurrences,
                First = s.FirstOccurrence,
                Last = s.LastOccurrence
            }));

            result.TotalCount = count;
            result.Page = page > 1 ? page : 1;
            result.PageSize = pageSize >= 1 ? pageSize : 10;

            return result;
        }