public DeleteOrganisationResponse Invoke(DeleteOrganisationRequest request) { var organisation = Session.MasterRaven .Load <Organisation>(request.OrganisationId); if (organisation == null) { return(new DeleteOrganisationResponse(request.OrganisationId, true)); } Session.MasterRavenDatabaseCommands.DeleteByIndex( CoreConstants.IndexNames.UserOrganisationMappings, new IndexQuery { Query = "Organisations:{0}".FormatWith(Organisation.GetId(request.OrganisationId)) }, true); Session.MasterRavenDatabaseCommands.DeleteByIndex( CoreConstants.IndexNames.Organisations, new IndexQuery { Query = "Id:{0}".FormatWith(Organisation.GetId(request.OrganisationId)) }, true); bool queueDeleted = true; try { _amazonSQS.DeleteQueue(new DeleteQueueRequest { QueueUrl = _configuration.GetReceiveQueueAddress(organisation.FriendlyId) }); } catch (Exception) { queueDeleted = false; } var emailInfo = new NonTemplatedEmailInfo { To = _configuration.AdministratorsEmail, Subject = "Errordite: Organisation Deleted", Body = "OrganisationId:{0}, QueueDeleted:={1}".FormatWith(organisation.Id, queueDeleted) }; Session.AddCommitAction(new SendMessageCommitAction(emailInfo, _configuration.GetNotificationsQueueAddress())); Session.AddCommitAction(new FlushOrganisationCacheCommitAction(_configuration, organisation)); Session.SynchroniseIndexes <UserOrganisationMappings, Indexing.Organisations>(); return(new DeleteOrganisationResponse(request.OrganisationId)); }
public ProcessIncomingExceptionResponse Invoke(ProcessIncomingExceptionRequest request) { TraceObject(request.Error); Application application; Organisation organisation; var status = TryGetApplication(request.Error.Token, out application, out organisation); string applicationId = null; string organisationId = null; switch (status) { case ApplicationStatus.Inactive: return(new ProcessIncomingExceptionResponse { ResponseMessage = "The application specified in the token is not currently active", ResponseCode = HttpStatusCode.NotAcceptable, }); case ApplicationStatus.NotFound: return(new ProcessIncomingExceptionResponse { ResponseMessage = "The application specified in the token could not be found", ResponseCode = HttpStatusCode.Unauthorized, }); case ApplicationStatus.Error: return(new ProcessIncomingExceptionResponse { ResponseCode = HttpStatusCode.InternalServerError, ResponseMessage = "An unhandled error occured while attempting to store this error" }); case ApplicationStatus.InvalidOrganisation: return(new ProcessIncomingExceptionResponse { ResponseMessage = "Failed to locate the organisation specified in your token", ResponseCode = HttpStatusCode.Unauthorized, }); case ApplicationStatus.InvalidToken: return(new ProcessIncomingExceptionResponse { ResponseMessage = "The token supplied is invalid, please check your token in the applications page in Errordite", ResponseCode = HttpStatusCode.BadRequest, }); case ApplicationStatus.Ok: { applicationId = application.Id; organisationId = application.OrganisationId; } break; } RateLimiterRule failedRule; if ((failedRule = _exceptionRateLimiter.Accept(applicationId)) != null) { Trace("Failed rate limiter rule named {0}", failedRule.Name); return(new ProcessIncomingExceptionResponse { ResponseMessage = "The error was not stored due to limits on the number of errors we can receive for you in a given time frame", SpecialResponseCode = 429, //too many requests http://tools.ietf.org/html/draft-nottingham-http-new-status-02 }); } var error = request.Error.GetError(application); if (_configuration.ServiceBusEnabled) { _sender.Send(new ReceiveErrorMessage { Error = error, ApplicationId = applicationId, OrganisationId = organisationId, Token = request.Error.Token, }, _configuration.GetReceiveQueueAddress(organisation.FriendlyId)); Session.AddCommitAction(new PollNowCommitAction(organisation)); } else { Trace("ServiceBus is disabled, invoking IReceiveErrorCommand"); _receiveErrorCommand.Invoke(new ReceiveErrorRequest { Error = error, ApplicationId = applicationId, Organisation = organisation, Token = request.Error.Token }); } return(new ProcessIncomingExceptionResponse()); }