Esempio n. 1
0
#pragma warning disable 1998
        public async Task<IndexViewModel> Fill([NotNull] Db db)
#pragma warning restore 1998
        {
            var issues = from issue in db.Issues
                         where issue.ParentId == null
                         select new
                         {
                             Issue = issue,
                             // for some reason, Count() does not work. Probably a bug, this workaround is quite heavy, but works fine.
                             DuplicatesCount = db.Issues.Where(x => x.ParentId == issue.Id || x.Id == issue.Id).Select(x => x.Id).ToList(),
                             DuplicatesDate = db.Issues.Where(x => x.ParentId == issue.Id || x.Id == issue.Id).Max(x => x.CreationDateTime)
                         };

            Issues = new List<Issue>();
            foreach (var i in issues)
            {
                var issue = new Issue
                {
                    Id = i.Issue.Id,
                    StackTrace = i.Issue.StackTrace,
                    Message = i.Issue.Message,
                    CountWithDuplicates = i.DuplicatesCount.Count,
                    CreationDateTimeWithDuplicates = i.DuplicatesDate,
                    Ignore = i.Issue.Ignore,
                    AdditionalInfo = i.Issue.AdditionalInfo,
                    Source = i.Issue.Source,
                    User = i.Issue.User,
                    FormattedCreationDateTimeWithDuplicates = i.DuplicatesDate.ToString("dd-MMM, hh:mm:ss")
                };

                if (issue.CreationDateTimeWithDuplicates.Date == DateTime.UtcNow.Date)
                {
                    var differenceInSeconds = (DateTime.UtcNow - issue.CreationDateTimeWithDuplicates).TotalSeconds;
                    if (differenceInSeconds < 10)
                    {
                        issue.FormattedCreationDateTimeWithDuplicates = "just now";
                    }
                    else if (differenceInSeconds < 120)
                    {
                        issue.FormattedCreationDateTimeWithDuplicates = differenceInSeconds.ToString("####") + "s ago";
                    }
                    else if (differenceInSeconds < 60*120)
                    {
                        issue.FormattedCreationDateTimeWithDuplicates = (differenceInSeconds / 60).ToString("####") + "m ago";
                    }
                    else
                    {
                        issue.FormattedCreationDateTimeWithDuplicates = i.DuplicatesDate.ToString("hh:mm:ss");
                    }
                }


                Issues.Add(issue);
            }

            Issues = Issues.OrderByDescending(x => x.CreationDateTimeWithDuplicates).ToList();
            return this;
        }
Esempio n. 2
0
        public async Task CreateOrIgnore([NotNull] Db db, [NotNull] CreateViewModel model)
        {

            var issue = new Issue
            {
                CreationDateTime = DateTime.UtcNow,
                Ignore = false,
                Message = model.Message,
                AdditionalInfo = model.AdditionalInfo,
                Source = model.Source,
                StackTrace = model.StackTrace,
                User = model.User
            };

            var duplicate = await FindDuplicate(db, issue);
            if (duplicate == null)
            {
                db.Issues.Add(issue);
                await db.SaveChangesAsync();
                return;
            }

            if (duplicate.CreationDateTime < DateTime.UtcNow.AddMinutes(-1) || (duplicate.StackTrace ?? "").Length != (issue.StackTrace ?? "").Length)
            {
                // if the duplicates stacktrace contains less info than the new stacktrace, switch the stacktraces so that the parent has the "best" stacktrace
                if ((issue.StackTrace ?? "").Length > (duplicate.StackTrace ?? "").Length)
                {
                    var s = duplicate.StackTrace;
                    duplicate.StackTrace = issue.StackTrace;
                    issue.StackTrace = s;
                }

                issue.ParentId = duplicate.Id;
                db.Issues.Add(issue);
                await db.SaveChangesAsync();
            }
        }