Exemplo n.º 1
0
        public ActionResult WhatIfReprocess(string issueId)
        {
            var request = new ReprocessIssueErrorsRequest
            {
                IssueId     = issueId,
                CurrentUser = Core.AppContext.CurrentUser,
                WhatIf      = true,
            };

            var httpTask = Core.Session.ReceiveHttpClient.PostJsonAsync("ReprocessIssueErrors", request);

            httpTask.Wait();

            if (!httpTask.Result.IsSuccessStatusCode)
            {
                Response.StatusCode = 500;
                return(Content("error"));
            }

            var contentTask = httpTask.Result.Content.ReadAsStringAsync();

            contentTask.Wait();

            var response = JsonConvert.DeserializeObject <ReprocessIssueErrorsResponse>(contentTask.Result);

            if (response.Status == ReprocessIssueErrorsStatus.NotAuthorised)
            {
                throw new ErrorditeAuthorisationException(new Issue {
                    Id = issueId
                }, Core.AppContext.CurrentUser);
            }

            return(Content(response.GetMessage(Issue.GetId(issueId)).ToString()));
        }
Exemplo n.º 2
0
        public ActionResult Reprocess(string issueId)
        {
            var request = new ReprocessIssueErrorsRequest
            {
                IssueId     = issueId,
                CurrentUser = Core.AppContext.CurrentUser
            };

            var httpTask = Core.Session.ReceiveHttpClient.PostJsonAsync("ReprocessIssueErrors", request);

            httpTask.Wait();

            if (!httpTask.Result.IsSuccessStatusCode)
            {
                ErrorNotification("An error has occured while attempting to reprocess errors, its likely this is a concurrency problem so please try again.");
            }
            else
            {
                var contentTask = httpTask.Result.Content.ReadAsStringAsync();
                contentTask.Wait();

                var response = JsonConvert.DeserializeObject <ReprocessIssueErrorsResponse>(contentTask.Result);

                if (response.Status == ReprocessIssueErrorsStatus.NotAuthorised)
                {
                    throw new ErrorditeAuthorisationException(new Issue {
                        Id = issueId
                    }, Core.AppContext.CurrentUser);
                }

                //getting consistent concurrency exceptions when this is executed in the service, so moved it to here
                Core.Session.Raven.Store(new IssueHistory
                {
                    DateAddedUtc       = DateTime.UtcNow.ToDateTimeOffset(request.CurrentUser.ActiveOrganisation.TimezoneId),
                    UserId             = request.CurrentUser.Id,
                    Type               = HistoryItemType.ErrorsReprocessed,
                    ReprocessingResult = response.AttachedIssueIds,
                    IssueId            = Issue.GetId(issueId),
                    ApplicationId      = response.ApplicationId,
                    SystemMessage      = true
                });

                ConfirmationNotification(response.GetMessage(Errordite.Core.Domain.Error.Issue.GetId(issueId)));
            }

            return(RedirectToAction("index", new { id = issueId.GetFriendlyId(), tab = IssueTab.Details.ToString() }));
        }
Exemplo n.º 3
0
        public HttpResponseMessage Post(string orgId, ReprocessIssueErrorsRequest request)
        {
            try
            {
                SetOrganisation(orgId);

                Auditor.Trace(GetType(), "Received reprocess issue errors request, IssueId:={0}, ", request.IssueId);
                var response = _reprocessIssueErrorsCommand.Invoke(request);
                Session.Commit();

                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (Exception e)
            {
                Auditor.Error(GetType(), e);
                throw;
            }
        }
        public ReprocessIssueErrorsResponse Invoke(ReprocessIssueErrorsRequest request)
        {
            Trace("Starting...");
            TraceObject(request);

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

            if (issue == null)
            {
                return new ReprocessIssueErrorsResponse
                       {
                           Status = ReprocessIssueErrorsStatus.IssueNotFound,
                           WhatIf = request.WhatIf,
                       }
            }
            ;

            try
            {
                _authorisationManager.Authorise(issue, request.CurrentUser);
            }
            catch (ErrorditeAuthorisationException)
            {
                return(new ReprocessIssueErrorsResponse
                {
                    Status = ReprocessIssueErrorsStatus.NotAuthorised,
                    WhatIf = request.WhatIf,
                });
            }

            var errors = _getApplicationErrorsQuery.Invoke(new GetApplicationErrorsRequest
            {
                ApplicationId  = issue.ApplicationId,
                IssueId        = issue.Id,
                OrganisationId = issue.OrganisationId,
                Paging         = new PageRequestWithSort(1, _configuration.MaxPageSize)
            }).Errors;

            var responses = errors.Items.Select(error => _receiveErrorCommand.Invoke(new ReceiveErrorRequest
            {
                ApplicationId   = issue.ApplicationId,
                Error           = error,
                ExistingIssueId = issue.Id,
                Organisation    = request.CurrentUser.ActiveOrganisation,
                WhatIf          = request.WhatIf,
            })).ToList();

            var response = new ReprocessIssueErrorsResponse
            {
                AttachedIssueIds = responses.GroupBy(r => r.IssueId).ToDictionary(g => g.Key, g => g.Count()),
                Status           = ReprocessIssueErrorsStatus.Ok,
                WhatIf           = request.WhatIf,
                ApplicationId    = issue.ApplicationId,
            };

            if (request.WhatIf)
            {
                return(response);
            }

            if (response.AttachedIssueIds.Any(i => i.Key == issue.Id))
            {
                //if some errors were moved from this issue, then we need to reset the counters
                //as we have lost the ability to know which counts refer to this issue
                if (response.AttachedIssueIds.Count > 1)
                {
                    //re-sync the error counts
                    Session.AddCommitAction(new SendMessageCommitAction(new SyncIssueErrorCountsMessage
                    {
                        IssueId         = issue.Id,
                        OrganisationId  = request.CurrentUser.OrganisationId,
                        TriggerEventUtc = DateTime.UtcNow,
                    }, _configuration.GetEventsQueueAddress(request.CurrentUser.ActiveOrganisation.RavenInstance.FriendlyId)));
                }
            }
            else
            {
                //if no errors remain attached to the current issue, then short-circuit the zeroing of the
                //counts.  Note we do NOT want to call purge as this may delete all the errors previously-owned
                //errors if the index has not caught up yet!
                Session.AddCommitAction(new DeleteAllDailyCountsCommitAction(issue.Id));

                var hourlyCount = Session.Raven.Load <IssueHourlyCount>("IssueHourlyCount/{0}".FormatWith(issue.FriendlyId));
                if (hourlyCount != null)
                {
                    hourlyCount.Initialise();
                }

                issue.ErrorCount  = 0;
                issue.LimitStatus = ErrorLimitStatus.Ok;
            }

            Session.SynchroniseIndexes <Indexing.Issues, Indexing.Errors>();
            return(response);
        }
    }