public void PostNewIssueInCacheAndDelete() { var issue = GetIssue(); var postTask = new HttpClient().PostAsJsonAsync("{0}/api/1/issue".FormatWith(RavenInstance.Master().ServicesBaseUrl), issue); postTask.Wait(); Assert.That(postTask.Result.StatusCode == HttpStatusCode.Created); var task = new HttpClient().GetAsync( "{0}/api/1/issue/{1}?applicationId={2}".FormatWith(RavenInstance.Master().ServicesBaseUrl, issue.FriendlyId, issue.ApplicationId)); task.Wait(); Assert.That(task.Result.StatusCode == HttpStatusCode.OK); string id = "{0}|{1}".FormatWith(issue.FriendlyId, IdHelper.GetFriendlyId(issue.ApplicationId)); var deleteTask = new HttpClient().DeleteAsync("{0}/api/1/issue/{1}".FormatWith(RavenInstance.Master().ServicesBaseUrl, id)); deleteTask.Wait(); Assert.That(deleteTask.Result.StatusCode == HttpStatusCode.NoContent); var getTask = new HttpClient().GetAsync( "{0}/api/1/issue/{1}?applicationId={2}".FormatWith(RavenInstance.Master().ServicesBaseUrl, issue.Id, issue.ApplicationId)); getTask.Wait(); Assert.That(getTask.Result.StatusCode == HttpStatusCode.NotFound); }
public GetOrganisationResponse Invoke(GetOrganisationRequest request) { Trace("Starting..."); var organisationId = Organisation.GetId(request.OrganisationId); var organisation = Session.MasterRaven .Include <Organisation>(o => o.PaymentPlanId) .Include <Organisation>(o => o.RavenInstanceId) .Load <Organisation>(organisationId); if (organisation != null) { if (organisation.PaymentPlanId != null) { organisation.PaymentPlan = MasterLoad <PaymentPlan>(organisation.PaymentPlanId); } organisation.RavenInstance = MasterLoad <RavenInstance>(organisation.RavenInstanceId); if (organisation.RavenInstance == null && organisation.RavenInstanceId == RavenInstance.Master().Id) { var ravenInstance = RavenInstance.Master(); MasterStore(ravenInstance); organisation.RavenInstance = ravenInstance; } } return(new GetOrganisationResponse { Organisation = organisation }); }
public IDocumentStore Create(RavenInstance instance) { if (!_documentStores.ContainsKey(instance.Id)) { lock (_syncLock) { if (!_documentStores.ContainsKey(instance.Id)) { var store = new DocumentStore { Conventions = { CustomizeJsonSerializer = ser => ser.TypeNameHandling = TypeNameHandling.All, }, ResourceManagerId = _resourceManagerId, EnlistInDistributedTransactions = false, }; if (instance.IsMaster) { store.ConnectionStringName = "RavenDB"; } else { store.Url = instance.RavenUrl; } store.Initialize(); _documentStores.Add(instance.Id, store); } } } return(_documentStores[instance.Id]); }
public void PostNewIssueInCache() { var issue = GetIssue(); var postTask = new HttpClient().PostJsonAsync("{0}/api/1/issue".FormatWith(RavenInstance.Master().ServicesBaseUrl), issue); postTask.Wait(); Console.Write(postTask.Result.StatusCode); Assert.That(postTask.Result.StatusCode == HttpStatusCode.Created); var task = new HttpClient().GetAsync( "{0}/api/1/issue/{1}?applicationId={2}".FormatWith(RavenInstance.Master().ServicesBaseUrl, issue.FriendlyId, issue.ApplicationId)); task.Wait(); Console.Write(task.Result.StatusCode); Assert.That(task.Result.StatusCode == HttpStatusCode.OK); }
public void PutNewIssueInCache() { var issue = GetIssue(); var postTask = new HttpClient().PostJsonAsync("{0}/api/1/issue".FormatWith(RavenInstance.Master().ServicesBaseUrl), issue); postTask.Wait(); if (postTask.Result.StatusCode != HttpStatusCode.Created) { var read = postTask.Result.Content.ReadAsStringAsync(); read.Wait(); Console.Write(read.Result); } Assert.That(postTask.Result.StatusCode == HttpStatusCode.Created); issue.LastErrorUtc = DateTime.UtcNow; //now update var putTask = new HttpClient().PutJsonAsync("{0}/api/1/issue".FormatWith(RavenInstance.Master().ServicesBaseUrl), new[] { issue }); putTask.Wait(); Assert.That(putTask.Result.StatusCode == HttpStatusCode.NoContent); var task = new HttpClient().GetAsync( "{0}/api/1/issue/{1}?applicationId={2}".FormatWith( RavenInstance.Master().ServicesBaseUrl, issue.FriendlyId, issue.ApplicationId)); task.Wait(); var readResponseTask = task.Result.Content.ReadAsStringAsync(); readResponseTask.Wait(); var retrievedIssue = JsonConvert.DeserializeObject <Issue>(readResponseTask.Result); Assert.That(retrievedIssue.LastErrorUtc == issue.LastErrorUtc); Assert.That(task.Result.StatusCode == HttpStatusCode.OK); }
public ActionResult SyncIndexes() { Server.ScriptTimeout = 7200; //timeout in 2 hours var masterDocumentStore = _storeFactory.Create(RavenInstance.Master()); IndexCreation.CreateIndexes(new CompositionContainer( new AssemblyCatalog(typeof(Issues).Assembly), new ExportProvider[0]), masterDocumentStore.DatabaseCommands.ForDatabase(CoreConstants.ErrorditeMasterDatabaseName), masterDocumentStore.Conventions); foreach (var organisation in Core.Session.MasterRaven.Query <Organisation>().GetAllItemsAsList(100)) { organisation.RavenInstance = Core.Session.MasterRaven.Load <RavenInstance>(organisation.RavenInstanceId); using (_session.SwitchOrg(organisation)) { _session.BootstrapOrganisation(organisation); } } ConfirmationNotification("All indexes for all organisations have been updated"); return(RedirectToAction("index")); }
public void Start(string ravenInstanceId) { Trace("Starting Errordite service {0} for raven instance:={1}", _serviceConfiguration.Service, ravenInstanceId); //receive service runs a thread per organisation, polling every org's queue //other services just have a single thread processing the queue if (_serviceConfiguration.Service == Service.Receive) { IEnumerable<Organisation> organisations; using (ObjectFactory.Container.Kernel.BeginScope()) { using (var session = ObjectFactory.GetObject<IAppSession>()) { organisations = session.MasterRaven .Query<OrganisationDocument, Organisations>() .Where(o => o.RavenInstanceId == RavenInstance.GetId(ravenInstanceId)) .As<Organisation>() .ToList(); } } foreach (var organisation in organisations) { AddProcessor(organisation.FriendlyId, null); } } else { for (int i = 0; i < _serviceConfiguration.ServiceProcessorCount; i++) { AddProcessor(null, ravenInstanceId); } } Trace("Started Errordite service {0} for raven instance:={1}", _serviceConfiguration.Service, ravenInstanceId); }
public CreateOrganisationResponse Invoke(CreateOrganisationRequest request) { Trace("Starting..."); var existingOrganisation = Session.MasterRaven .Query <Organisation, Indexing.Organisations>() .FirstOrDefault(o => o.Name == request.OrganisationName); if (existingOrganisation != null) { return(new CreateOrganisationResponse { Status = CreateOrganisationStatus.OrganisationExists }); } var freeTrialPlan = _getAvailablePaymentPlansQuery.Invoke(new GetAvailablePaymentPlansRequest()).Plans.FirstOrDefault(p => p.IsFreeTier); var timezone = request.TimezoneId ?? "UTC"; var date = DateTime.UtcNow.ToDateTimeOffset(timezone); var organisation = new Organisation { Name = request.OrganisationName, Status = OrganisationStatus.Active, PaymentPlanId = freeTrialPlan?.Id, CreatedOnUtc = DateTime.UtcNow, TimezoneId = timezone, PaymentPlan = freeTrialPlan, ApiKeySalt = Membership.GeneratePassword(8, 1), Subscription = new Subscription { Status = SubscriptionStatus.Trial, StartDate = date, CurrentPeriodEndDate = date.AddMonths(1), LastModified = date }, CallbackUrl = request.CallbackUrl, }; var ravenInstance = _getRavenInstancesQuery.Invoke(new GetRavenInstancesRequest()) .RavenInstances .FirstOrDefault(r => r.Active) ?? RavenInstance.Master(); organisation.RavenInstance = ravenInstance; organisation.RavenInstanceId = ravenInstance.Id; MasterStore(organisation); var existingUserOrgMap = Session.MasterRaven .Query <UserOrganisationMapping, UserOrganisationMappings>() .FirstOrDefault(u => u.EmailAddress == request.Email); if (existingUserOrgMap != null) { existingUserOrgMap.Organisations.Add(organisation.Id); } else { MasterStore(new UserOrganisationMapping { EmailAddress = request.Email, Organisations = new List <string> { organisation.Id }, Password = request.Password.Hash(), PasswordToken = Guid.Empty, Status = UserStatus.Active, SsoUser = request.SpecialUser.IsIn(SpecialUser.AppHarbor), }); } organisation.ApiKey = Convert.ToBase64String( Encoding.UTF8.GetBytes( _encryptor.Encrypt("{0}|{1}".FormatWith(organisation.FriendlyId, organisation.ApiKeySalt)))); Session.SetOrganisation(organisation); Session.BootstrapOrganisation(organisation); var group = new Group { Name = request.OrganisationName, OrganisationId = organisation.Id }; Store(group); var user = new User { Email = request.Email, FirstName = request.FirstName, LastName = request.LastName, Role = UserRole.Administrator, GroupIds = new List <string> { group.Id }, ActiveOrganisation = organisation, OrganisationId = organisation.Id, SpecialUser = request.SpecialUser, }; Store(user); //update the organisation with the primary user organisation.PrimaryUserId = user.Id; var addApplicationResponse = _addApplicationCommand.Invoke(new AddApplicationRequest { CurrentUser = user, IsActive = true, MatchRuleFactoryId = new MethodAndTypeMatchRuleFactory().Id, Name = request.OrganisationName, NotificationGroups = new List <string> { group.Id }, UserId = user.Id, IsSignUp = true, }); //TODO: sync indexes Session.SynchroniseIndexes <Indexing.Organisations, Indexing.Users>(); return(new CreateOrganisationResponse(request.Email) { OrganisationId = organisation.Id, UserId = user.Id, ApplicationId = addApplicationResponse.ApplicationId, }); }
public void SendErrorsForProcessing() { var postTask = new HttpClient().PostJsonAsync("{0}/api/1/ReprocessIssueErrors".FormatWith(RavenInstance.Master().ServicesBaseUrl), new ReprocessIssueErrorsRequest { IssueId = "issues/1", OrganisationId = "organisations/1" }); postTask.Wait(); Assert.That(postTask.Result.StatusCode == HttpStatusCode.OK); var read = postTask.Result.Content.ReadAsStringAsync(); read.Wait(); var response = JsonConvert.DeserializeObject <ReprocessIssueErrorsResponse>(read.Result); Assert.That(response.Status == ReprocessIssueErrorsStatus.Ok); }