public AttachToExistingIssueResponse Invoke(AttachToExistingIssueRequest request)
        {
            Trace("Attempting to load issue with Id {0} from database {1}", request.IssueId, Session.OrganisationDatabaseName);

            var issue = Load <Issue>(request.IssueId);

            issue.ErrorCount++;

            if (request.Error.TimestampUtc > issue.LastErrorUtc)
            {
                issue.LastErrorUtc = request.Error.TimestampUtc;
            }

            var issueDailyCount = Load <IssueDailyCount>("IssueDailyCount/{0}-{1}".FormatWith(issue.FriendlyId, request.Error.TimestampUtc.ToString("yyyy-MM-dd")));

            if (issueDailyCount == null)
            {
                issueDailyCount = new IssueDailyCount
                {
                    Id            = "IssueDailyCount/{0}-{1}".FormatWith(issue.FriendlyId, request.Error.TimestampUtc.ToString("yyyy-MM-dd")),
                    IssueId       = issue.Id,
                    Count         = 1,
                    Date          = request.Error.TimestampUtc.Date,
                    ApplicationId = issue.ApplicationId
                };

                Store(issueDailyCount);
            }
            else
            {
                issueDailyCount.Count++;
            }

            var issueHourlyCount = Load <IssueHourlyCount>("IssueHourlyCount/{0}".FormatWith(issue.FriendlyId));

            if (issueHourlyCount == null)
            {
                issueHourlyCount = new IssueHourlyCount
                {
                    IssueId       = issue.Id,
                    Id            = "IssueHourlyCount/{0}".FormatWith(issue.FriendlyId),
                    ApplicationId = issue.ApplicationId
                };

                issueHourlyCount.Initialise();
                issueHourlyCount.IncrementHourlyCount(issue.CreatedOnUtc);
                Store(issueHourlyCount);
            }
            else
            {
                issueHourlyCount.IncrementHourlyCount(request.Error.TimestampUtc);
            }

            SetLimitStatus(issue);

            Trace("Assigning issue Id to error with Id:={0}, Existing Error IssueId:={1}, New IssueId:={2}", request.Error.Id, request.Error.IssueId, issue.Id);
            request.Error.IssueId = issue.Id;

            //only store the error is it is a new error, not the result of reprocessing
            if (request.Error.Id.IsNullOrEmpty())
            {
                Trace("It's a new error, so Store it");
                Store(request.Error);

                //if the matching issue is solved, send an email and set it back to Acknowledged
                if (issue.Status == IssueStatus.Solved)
                {
                    issue.LastNotified = DateTime.UtcNow;

                    issue.Status = IssueStatus.Acknowledged;
                    SendNotification(issue, request.Application,
                                     NotificationType.NotifyOnNewInstanceOfSolvedIssue
                                     , request.Error, request.Organisation);
                }
                else if ((issue.NotifyFrequency ?? "0") != "0" && issue.LastNotified.GetValueOrDefault() < DateTime.UtcNow - new Duration(issue.NotifyFrequency))
                {
                    issue.LastNotified = DateTime.UtcNow;
                    SendNotification(issue, request.Application, NotificationType.AlwaysNotifyOnInstanceOfIssue,
                                     request.Error, request.Organisation, new Duration(issue.NotifyFrequency));
                }
            }

            if (issue.LimitStatus == ErrorLimitStatus.Exceeded)
            {
                _makeExceededErrorsUnloggedCommand.Invoke(new MakeExceededErrorsUnloggedRequest {
                    IssueId = issue.Id
                });
            }

            return(new AttachToExistingIssueResponse
            {
                Issue = issue
            });
        }
예제 #2
0
        public AttachToNewIssueResponse Invoke(AttachToNewIssueRequest request)
        {
            Trace("Starting...");

            //mark the error as unclassified
            var error            = request.Error;
            var application      = request.Application;
            var matchRuleFactory = _matchRuleFactoryFactory.Create(application.MatchRuleFactoryId);
            var rules            = matchRuleFactory.Create(error).ToList();

            var issue = new Issue
            {
                Name            = "{0} ({1})".FormatWith(error.ExceptionInfos.First().Type, error.TimestampUtc.ToString("yyyy.MM.ddTHH.mm.ss")),
                Rules           = rules,
                ApplicationId   = application.Id,
                CreatedOnUtc    = error.TimestampUtc,
                LastModifiedUtc = error.TimestampUtc,
                UserId          = application.DefaultUserId,
                ErrorCount      = 1,
                LastErrorUtc    = error.TimestampUtc,
                OrganisationId  = application.OrganisationId,
                TestIssue       = error.TestError,
                NotifyFrequency = application.DefaultNotificationFrequency.IsNullOrEmpty() ? "0" : application.DefaultNotificationFrequency
            };

            Store(issue);
            Store(new IssueHistory
            {
                DateAddedUtc     = DateTime.UtcNow.ToDateTimeOffset(application.TimezoneId),
                Type             = HistoryItemType.AutoCreated,
                ExceptionType    = error.ExceptionInfos.First().Type,
                ExceptionMethod  = error.ExceptionInfos.First().MethodName,
                ExceptionMachine = error.MachineName,
                SystemMessage    = true,
                IssueId          = issue.Id,
                ApplicationId    = issue.ApplicationId,
            });

            var issueHourlyCount = new IssueHourlyCount
            {
                IssueId       = issue.Id,
                Id            = "IssueHourlyCount/{0}".FormatWith(issue.FriendlyId),
                ApplicationId = issue.ApplicationId
            };

            issueHourlyCount.Initialise();
            issueHourlyCount.IncrementHourlyCount(issue.CreatedOnUtc);
            Store(issueHourlyCount);

            var issueDailyCount = new IssueDailyCount
            {
                Id            = "IssueDailyCount/{0}-{1}".FormatWith(issue.FriendlyId, issue.CreatedOnUtc.ToString("yyyy-MM-dd")),
                IssueId       = issue.Id,
                Count         = 1,
                Date          = issue.CreatedOnUtc.Date,
                ApplicationId = issue.ApplicationId
            };

            Store(issueDailyCount);

            Trace("AttachTod issue: Id:={0}, Name:={1}", issue.Id, issue.Name);
            error.IssueId = issue.Id;
            SendNotification(issue, application, NotificationType.NotifyOnNewIssueCreated, error, request.Organisation);

            //tell the issue cache we have a new issue
            _receptionServiceIssueCache.Add(issue);

            Store(error);

            Trace("Complete");

            return(new AttachToNewIssueResponse
            {
                Issue = issue
            });
        }