public void RegisterServices(Container container) { JsonConvert.DefaultSettings = () => new JsonSerializerSettings { DateParseHandling = DateParseHandling.DateTimeOffset }; var contractResolver = new ExceptionlessContractResolver(); contractResolver.UseDefaultResolverFor(typeof(Connection).Assembly); contractResolver.UseDefaultResolverFor(typeof(DataDictionary), typeof(SettingsDictionary), typeof(VersionOne.VersionOneWebHookStack), typeof(VersionOne.VersionOneWebHookEvent)); var settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, DateParseHandling = DateParseHandling.DateTimeOffset, ContractResolver = contractResolver }; settings.AddModelConverters(); container.RegisterSingle <IContractResolver>(() => contractResolver); container.RegisterSingle <JsonSerializerSettings>(settings); container.RegisterSingle <JsonSerializer>(JsonSerializer.Create(settings)); container.RegisterSingle <ISerializer>(() => new JsonNetSerializer(settings)); container.RegisterSingle <IUserIdProvider, PrincipalUserIdProvider>(); container.RegisterSingle <MessageBusHub>(); container.Register <OverageHandler>(); container.Register <ThrottlingHandler>(() => new ThrottlingHandler(container.GetInstance <ICacheClient>(), userIdentifier => Settings.Current.ApiThrottleLimit, TimeSpan.FromMinutes(15))); }
public List <PersistentEvent> ParseEvents(string input, int apiVersion, string userAgent) { if (apiVersion < 2) { return(null); } var events = new List <PersistentEvent>(); var serializerSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, ContractResolver = new ExceptionlessContractResolver() }; serializerSettings.AddModelConverters(); switch (input.GetJsonType()) { case JsonType.Object: { PersistentEvent ev; if (input.TryFromJson(out ev, serializerSettings)) { events.Add(ev); } break; } case JsonType.Array: { PersistentEvent[] parsedEvents; if (input.TryFromJson(out parsedEvents, serializerSettings)) { events.AddRange(parsedEvents); } break; } } return(events.Count > 0 ? events : null); }
protected override async Task <JobResult> RunInternalAsync(CancellationToken token) { OutputPublicIp(); QueueEntry <EventMigrationBatch> queueEntry = null; try { queueEntry = _queue.Dequeue(); } catch (Exception ex) { if (!(ex is TimeoutException)) { Log.Error().Exception(ex).Message("Error trying to dequeue message: {0}", ex.Message).Write(); return(JobResult.FromException(ex)); } } if (queueEntry == null) { return(JobResult.Success); } Log.Info().Message("Processing event migration jobs for date range: {0}-{1}", new DateTimeOffset(queueEntry.Value.StartTicks, TimeSpan.Zero).ToString("O"), new DateTimeOffset(queueEntry.Value.EndTicks, TimeSpan.Zero).ToString("O")).Write(); int total = 0; var stopwatch = new Stopwatch(); stopwatch.Start(); var errorCollection = GetErrorCollection(); var knownStackIds = new List <string>(); var serializerSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore }; serializerSettings.AddModelConverters(); var query = Query.And(Query.GTE(ErrorFieldNames.OccurrenceDate_UTC, queueEntry.Value.StartTicks), Query.LT(ErrorFieldNames.OccurrenceDate_UTC, queueEntry.Value.EndTicks)); var errors = errorCollection.Find(query).SetSortOrder(SortBy.Ascending(ErrorFieldNames.OccurrenceDate_UTC)).SetLimit(_batchSize).ToList(); while (errors.Count > 0) { Log.Info().Message("Migrating events {0}-{1} {2:N0} total {3:N0}/s...", errors.First().Id, errors.Last().Id, total, total > 0 ? total / stopwatch.Elapsed.TotalSeconds : 0).Write(); var upgradedErrors = JArray.FromObject(errors); var ctx = new EventUpgraderContext(upgradedErrors, new Version(1, 5), true); _eventUpgraderPluginManager.Upgrade(ctx); var upgradedEvents = upgradedErrors.FromJson <PersistentEvent>(serializerSettings); var stackIdsToCheck = upgradedEvents.Where(e => !knownStackIds.Contains(e.StackId)).Select(e => e.StackId).Distinct().ToArray(); if (stackIdsToCheck.Length > 0) { knownStackIds.AddRange(_eventRepository.ExistsByStackIds(stackIdsToCheck)); } upgradedEvents.ForEach(e => { if (e.Date.UtcDateTime > DateTimeOffset.UtcNow.AddHours(1)) { e.Date = DateTimeOffset.Now; } e.CreatedUtc = e.Date.ToUniversalTime().DateTime; if (!knownStackIds.Contains(e.StackId)) { // We haven't processed this stack id yet in this run. Check to see if this stack has already been imported.. e.IsFirstOccurrence = true; knownStackIds.Add(e.StackId); } var request = e.GetRequestInfo(); if (request != null) { e.AddRequestInfo(request.ApplyDataExclusions(RequestInfoPlugin.DefaultExclusions, RequestInfoPlugin.MAX_VALUE_LENGTH)); } foreach (var ip in GetIpAddresses(e, request)) { var location = _geoIpResolver.ResolveIp(ip); if (location == null || !location.IsValid()) { continue; } e.Geo = location.ToString(); break; } if (e.Type == Event.KnownTypes.NotFound && request != null) { if (String.IsNullOrWhiteSpace(e.Source)) { e.Message = null; e.Source = request.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false); } return; } var error = e.GetError(); if (error == null) { Debugger.Break(); Log.Error().Project(e.ProjectId).Message("Unable to get parse error model: {0}", e.Id).Write(); return; } var stackingTarget = error.GetStackingTarget(); if (stackingTarget != null && stackingTarget.Method != null && !String.IsNullOrEmpty(stackingTarget.Method.GetDeclaringTypeFullName())) { e.Source = stackingTarget.Method.GetDeclaringTypeFullName().Truncate(2000); } var signature = new ErrorSignature(error); if (signature.SignatureInfo.Count <= 0) { return; } var targetInfo = new SettingsDictionary(signature.SignatureInfo); if (stackingTarget != null && stackingTarget.Error != null && !targetInfo.ContainsKey("Message")) { targetInfo["Message"] = error.GetStackingTarget().Error.Message; } error.Data[Error.KnownDataKeys.TargetInfo] = targetInfo; }); try { _eventRepository.Add(upgradedEvents, sendNotification: false); } catch (Exception) { foreach (var persistentEvent in upgradedEvents) { try { _eventRepository.Add(persistentEvent, sendNotification: false); } catch (Exception ex) { //Debugger.Break(); Log.Error().Exception(ex).Message("An error occurred while migrating event '{0}': {1}", persistentEvent.Id, ex.Message).Write(); } } } total += upgradedEvents.Count; var lastId = upgradedEvents.Last().Id; _cache.Set("migration-errorid", lastId); errors = errorCollection.Find(Query.And(Query.GT(ErrorFieldNames.Id, ObjectId.Parse(lastId)), Query.LT(ErrorFieldNames.OccurrenceDate_UTC, queueEntry.Value.EndTicks))) .SetSortOrder(SortBy.Ascending(ErrorFieldNames.OccurrenceDate_UTC)) .SetLimit(_batchSize).ToList(); } _cache.Set("migration-completedday", queueEntry.Value.EndTicks); queueEntry.Complete(); return(JobResult.Success); }
public static void RegisterServices(Container container, ILoggerFactory loggerFactory, CancellationToken shutdownCancellationToken) { var logger = loggerFactory.CreateLogger <Bootstrapper>(); container.RegisterLogger(loggerFactory); container.RegisterSingleton <IDependencyResolver>(() => new SimpleInjectorDependencyResolver(container)); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { DateParseHandling = DateParseHandling.DateTimeOffset }; var resolver = new DynamicTypeContractResolver(new LowerCaseUnderscorePropertyNamesContractResolver()); resolver.UseDefaultResolverFor(typeof(DataDictionary), typeof(SettingsDictionary), typeof(VersionOne.VersionOneWebHookStack), typeof(VersionOne.VersionOneWebHookEvent)); var settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, DateParseHandling = DateParseHandling.DateTimeOffset, ContractResolver = resolver }; settings.AddModelConverters(loggerFactory.CreateLogger(nameof(Bootstrapper))); container.RegisterSingleton <IContractResolver>(() => resolver); container.RegisterSingleton <JsonSerializerSettings>(settings); container.RegisterSingleton <JsonSerializer>(JsonSerializer.Create(settings)); container.RegisterSingleton <ISerializer>(() => new JsonNetSerializer(settings)); container.RegisterSingleton <IMetricsClient>(() => new InMemoryMetricsClient(loggerFactory: loggerFactory)); container.RegisterSingleton <ExceptionlessElasticConfiguration>(); if (!Settings.Current.DisableIndexConfiguration) { container.AddStartupAction(() => container.GetInstance <ExceptionlessElasticConfiguration>().ConfigureIndexesAsync(beginReindexingOutdated: false)); } container.RegisterSingleton <ICacheClient, InMemoryCacheClient>(); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventPost> > >(() => new[] { new MetricsQueueBehavior <EventPost>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventUserDescription> > >(() => new[] { new MetricsQueueBehavior <EventUserDescription>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventNotificationWorkItem> > >(() => new[] { new MetricsQueueBehavior <EventNotificationWorkItem>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <WebHookNotification> > >(() => new[] { new MetricsQueueBehavior <WebHookNotification>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <MailMessage> > >(() => new[] { new MetricsQueueBehavior <MailMessage>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <WorkItemData> > >(() => new[] { new MetricsQueueBehavior <WorkItemData>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IQueue <EventPost> >(() => new InMemoryQueue <EventPost>(behaviors: container.GetAllInstances <IQueueBehavior <EventPost> >(), loggerFactory: loggerFactory)); container.RegisterSingleton <IQueue <EventUserDescription> >(() => new InMemoryQueue <EventUserDescription>(behaviors: container.GetAllInstances <IQueueBehavior <EventUserDescription> >(), loggerFactory: loggerFactory)); container.RegisterSingleton <IQueue <EventNotificationWorkItem> >(() => new InMemoryQueue <EventNotificationWorkItem>(behaviors: container.GetAllInstances <IQueueBehavior <EventNotificationWorkItem> >(), loggerFactory: loggerFactory)); container.RegisterSingleton <IQueue <WebHookNotification> >(() => new InMemoryQueue <WebHookNotification>(behaviors: container.GetAllInstances <IQueueBehavior <WebHookNotification> >(), loggerFactory: loggerFactory)); container.RegisterSingleton <IQueue <MailMessage> >(() => new InMemoryQueue <MailMessage>(behaviors: container.GetAllInstances <IQueueBehavior <MailMessage> >(), loggerFactory: loggerFactory)); var workItemHandlers = new WorkItemHandlers(); workItemHandlers.Register <ReindexWorkItem>(container.GetInstance <ReindexWorkItemHandler>); workItemHandlers.Register <RemoveOrganizationWorkItem>(container.GetInstance <RemoveOrganizationWorkItemHandler>); workItemHandlers.Register <RemoveProjectWorkItem>(container.GetInstance <RemoveProjectWorkItemHandler>); workItemHandlers.Register <SetLocationFromGeoWorkItem>(container.GetInstance <SetLocationFromGeoWorkItemHandler>); workItemHandlers.Register <SetProjectIsConfiguredWorkItem>(container.GetInstance <SetProjectIsConfiguredWorkItemHandler>); workItemHandlers.Register <StackWorkItem>(container.GetInstance <StackWorkItemHandler>); workItemHandlers.Register <ThrottleBotsWorkItem>(container.GetInstance <ThrottleBotsWorkItemHandler>); workItemHandlers.Register <OrganizationMaintenanceWorkItem>(container.GetInstance <OrganizationMaintenanceWorkItemHandler>); workItemHandlers.Register <OrganizationNotificationWorkItem>(container.GetInstance <OrganizationNotificationWorkItemHandler>); workItemHandlers.Register <ProjectMaintenanceWorkItem>(container.GetInstance <ProjectMaintenanceWorkItemHandler>); workItemHandlers.Register <UserMaintenanceWorkItem>(container.GetInstance <UserMaintenanceWorkItemHandler>); container.RegisterSingleton <WorkItemHandlers>(workItemHandlers); container.RegisterSingleton <IQueue <WorkItemData> >(() => new InMemoryQueue <WorkItemData>(behaviors: container.GetAllInstances <IQueueBehavior <WorkItemData> >(), workItemTimeout: TimeSpan.FromHours(1), loggerFactory: loggerFactory)); container.RegisterSingleton <IMessageBus, InMemoryMessageBus>(); container.RegisterSingleton <IMessagePublisher>(container.GetInstance <IMessageBus>); container.RegisterSingleton <IMessageSubscriber>(container.GetInstance <IMessageBus>); if (!String.IsNullOrEmpty(Settings.Current.StorageFolder)) { container.RegisterSingleton <IFileStorage>(new FolderFileStorage(Settings.Current.StorageFolder)); } else { container.RegisterSingleton <IFileStorage>(new InMemoryFileStorage()); } container.RegisterSingleton <IStackRepository, StackRepository>(); container.RegisterSingleton <IEventRepository, EventRepository>(); container.RegisterSingleton <IOrganizationRepository, OrganizationRepository>(); container.RegisterSingleton <IProjectRepository, ProjectRepository>(); container.RegisterSingleton <IUserRepository, UserRepository>(); container.RegisterSingleton <IWebHookRepository, WebHookRepository>(); container.RegisterSingleton <ITokenRepository, TokenRepository>(); container.RegisterSingleton <IGeoIpService, MaxMindGeoIpService>(); container.RegisterSingleton <IGeocodeService, NullGeocodeService>(); container.RegisterSingleton <IQueryParser>(() => new ElasticQueryParser()); container.Register(typeof(IValidator <>), new[] { typeof(Bootstrapper).Assembly }, Lifestyle.Singleton); container.RegisterSingleton <IEmailGenerator>(() => new RazorEmailGenerator(@"Mail\Templates")); container.RegisterSingleton <IMailer, Mailer>(); if (Settings.Current.WebsiteMode != WebsiteMode.Dev) { container.RegisterSingleton <IMailSender, SmtpMailSender>(); } else { container.RegisterSingleton <IMailSender>(() => new InMemoryMailSender()); logger.Warn("Emails will NOT be sent in Dev mode."); } container.RegisterSingleton <ILockProvider, CacheLockProvider>(); container.Register <StripeEventHandler>(); container.RegisterSingleton <BillingManager>(); container.RegisterSingleton <SampleDataService>(); container.RegisterSingleton <EventPipeline>(); container.RegisterSingleton <EventPluginManager>(); container.RegisterSingleton <FormattingPluginManager>(); container.RegisterSingleton <UserAgentParser>(); container.RegisterSingleton <SystemHealthChecker>(); container.RegisterSingleton <ICoreLastReferenceIdManager, NullCoreLastReferenceIdManager>(); container.Register <IDomainLoginProvider, ActiveDirectoryLoginProvider>(); container.AppendToCollection(typeof(Profile), typeof(CoreMappings)); container.RegisterSingleton <IMapper>(() => { var profiles = container.GetAllInstances <Profile>(); var config = new MapperConfiguration(cfg => { cfg.ConstructServicesUsing(container.GetInstance); foreach (var profile in profiles) { cfg.AddProfile(profile); } }); return(config.CreateMapper()); }); }
public static void RegisterServices(IServiceCollection container) { container.ConfigureOptions <ConfigureAppOptions>(); container.ConfigureOptions <ConfigureAuthOptions>(); container.ConfigureOptions <ConfigureCacheOptions>(); container.ConfigureOptions <ConfigureElasticsearchOptions>(); container.ConfigureOptions <ConfigureEmailOptions>(); container.ConfigureOptions <ConfigureIntercomOptions>(); container.ConfigureOptions <ConfigureMessageBusOptions>(); container.ConfigureOptions <ConfigureMetricOptions>(); container.ConfigureOptions <ConfigureQueueOptions>(); container.ConfigureOptions <ConfigureSlackOptions>(); container.ConfigureOptions <ConfigureStorageOptions>(); container.ConfigureOptions <ConfigureStripeOptions>(); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { DateParseHandling = DateParseHandling.DateTimeOffset }; container.AddSingleton <IContractResolver>(s => GetJsonContractResolver()); container.AddSingleton <JsonSerializerSettings>(s => { var settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, DateParseHandling = DateParseHandling.DateTimeOffset, ContractResolver = s.GetRequiredService <IContractResolver>() }; settings.AddModelConverters(s.GetRequiredService <ILogger <Bootstrapper> >()); return(settings); }); container.AddSingleton <JsonSerializer>(s => JsonSerializer.Create(s.GetRequiredService <JsonSerializerSettings>())); container.AddSingleton <ISerializer>(s => new JsonNetSerializer(s.GetRequiredService <JsonSerializerSettings>())); container.AddSingleton <ITextSerializer>(s => new JsonNetSerializer(s.GetRequiredService <JsonSerializerSettings>())); container.AddSingleton <ICacheClient>(s => new InMemoryCacheClient(new InMemoryCacheClientOptions { LoggerFactory = s.GetRequiredService <ILoggerFactory>() })); container.AddSingleton <IMetricsClient>(s => new InMemoryMetricsClient(new InMemoryMetricsClientOptions { LoggerFactory = s.GetRequiredService <ILoggerFactory>() })); container.AddSingleton <ExceptionlessElasticConfiguration>(); container.AddSingleton <IElasticConfiguration>(s => s.GetRequiredService <ExceptionlessElasticConfiguration>()); container.AddStartupAction <ExceptionlessElasticConfiguration>(); container.AddStartupAction(CreateSampleDataAsync); container.AddSingleton <IQueueBehavior <EventPost> >(s => new MetricsQueueBehavior <EventPost>(s.GetRequiredService <IMetricsClient>())); container.AddSingleton <IQueueBehavior <EventUserDescription> >(s => new MetricsQueueBehavior <EventUserDescription>(s.GetRequiredService <IMetricsClient>())); container.AddSingleton <IQueueBehavior <EventNotificationWorkItem> >(s => new MetricsQueueBehavior <EventNotificationWorkItem>(s.GetRequiredService <IMetricsClient>())); container.AddSingleton <IQueueBehavior <WebHookNotification> >(s => new MetricsQueueBehavior <WebHookNotification>(s.GetRequiredService <IMetricsClient>())); container.AddSingleton <IQueueBehavior <MailMessage> >(s => new MetricsQueueBehavior <MailMessage>(s.GetRequiredService <IMetricsClient>())); container.AddSingleton <IQueueBehavior <WorkItemData> >(s => new MetricsQueueBehavior <WorkItemData>(s.GetRequiredService <IMetricsClient>())); container.AddSingleton(typeof(IWorkItemHandler), typeof(Bootstrapper).Assembly); container.AddSingleton <WorkItemHandlers>(s => { var handlers = new WorkItemHandlers(); handlers.Register <ReindexWorkItem>(s.GetRequiredService <ReindexWorkItemHandler>); handlers.Register <RemoveOrganizationWorkItem>(s.GetRequiredService <RemoveOrganizationWorkItemHandler>); handlers.Register <RemoveProjectWorkItem>(s.GetRequiredService <RemoveProjectWorkItemHandler>); handlers.Register <SetLocationFromGeoWorkItem>(s.GetRequiredService <SetLocationFromGeoWorkItemHandler>); handlers.Register <SetProjectIsConfiguredWorkItem>(s.GetRequiredService <SetProjectIsConfiguredWorkItemHandler>); handlers.Register <StackWorkItem>(s.GetRequiredService <StackWorkItemHandler>); handlers.Register <ThrottleBotsWorkItem>(s.GetRequiredService <ThrottleBotsWorkItemHandler>); handlers.Register <OrganizationMaintenanceWorkItem>(s.GetRequiredService <OrganizationMaintenanceWorkItemHandler>); handlers.Register <OrganizationNotificationWorkItem>(s.GetRequiredService <OrganizationNotificationWorkItemHandler>); handlers.Register <ProjectMaintenanceWorkItem>(s.GetRequiredService <ProjectMaintenanceWorkItemHandler>); handlers.Register <UserMaintenanceWorkItem>(s.GetRequiredService <UserMaintenanceWorkItemHandler>); return(handlers); }); container.AddSingleton(s => CreateQueue <EventPost>(s)); container.AddSingleton(s => CreateQueue <EventUserDescription>(s)); container.AddSingleton(s => CreateQueue <EventNotificationWorkItem>(s)); container.AddSingleton(s => CreateQueue <WebHookNotification>(s)); container.AddSingleton(s => CreateQueue <MailMessage>(s)); container.AddSingleton(s => CreateQueue <WorkItemData>(s, TimeSpan.FromHours(1))); container.AddSingleton <IConnectionMapping, ConnectionMapping>(); container.AddSingleton <MessageService>(); container.AddStartupAction <MessageService>(); container.AddSingleton <IMessageBus>(s => new InMemoryMessageBus(new InMemoryMessageBusOptions { LoggerFactory = s.GetRequiredService <ILoggerFactory>() })); container.AddSingleton <IMessagePublisher>(s => s.GetRequiredService <IMessageBus>()); container.AddSingleton <IMessageSubscriber>(s => s.GetRequiredService <IMessageBus>()); container.AddSingleton <IFileStorage>(s => new InMemoryFileStorage(new InMemoryFileStorageOptions { Serializer = s.GetRequiredService <ITextSerializer>(), LoggerFactory = s.GetRequiredService <ILoggerFactory>() })); container.AddSingleton <IStackRepository, StackRepository>(); container.AddSingleton <IEventRepository, EventRepository>(); container.AddSingleton <IOrganizationRepository, OrganizationRepository>(); container.AddSingleton <IProjectRepository, ProjectRepository>(); container.AddSingleton <IUserRepository, UserRepository>(); container.AddSingleton <IWebHookRepository, WebHookRepository>(); container.AddSingleton <ITokenRepository, TokenRepository>(); container.AddSingleton <IGeoIpService, MaxMindGeoIpService>(); container.AddSingleton <IGeocodeService, NullGeocodeService>(); container.AddSingleton <IQueryParser>(s => new ElasticQueryParser()); container.AddSingleton <IQueryValidator, QueryValidator>(); container.AddSingleton <PersistentEventQueryValidator>(); container.AddSingleton <StackQueryValidator>(); container.AddSingleton(typeof(IValidator <>), typeof(Bootstrapper).Assembly); container.AddSingleton(typeof(IPipelineAction <EventContext>), typeof(Bootstrapper).Assembly); container.AddSingleton(typeof(IPlugin), typeof(Bootstrapper).Assembly); container.AddSingleton <EventParserPluginManager>(); container.AddSingleton <EventPluginManager>(); container.AddSingleton <EventUpgraderPluginManager>(); container.AddSingleton <FormattingPluginManager>(); container.AddSingleton <WebHookDataPluginManager>(); container.AddSingleton(typeof(IJob), typeof(Bootstrapper).Assembly); container.AddSingleton <WorkItemJob>(); container.AddSingleton <MaintainIndexesJob>(); container.AddSingleton <IMailer, Mailer>(); container.AddSingleton <IMailSender>(s => new InMemoryMailSender()); container.AddSingleton <CacheLockProvider>(s => new CacheLockProvider(s.GetRequiredService <ICacheClient>(), s.GetRequiredService <IMessageBus>(), s.GetRequiredService <ILoggerFactory>())); container.AddSingleton <ILockProvider>(s => s.GetRequiredService <CacheLockProvider>()); container.AddTransient <StripeEventHandler>(); container.AddSingleton <BillingManager>(); container.AddSingleton <BillingPlans>(); container.AddSingleton <EventPostService>(); container.AddSingleton <SampleDataService>(); container.AddSingleton <SemanticVersionParser>(); container.AddSingleton <EventParserPluginManager>(); container.AddSingleton <EventPipeline>(); container.AddSingleton <EventPluginManager>(); container.AddSingleton <FormattingPluginManager>(); container.AddSingleton <WebHookDataPluginManager>(); container.AddSingleton <UserAgentParser>(); container.AddSingleton <SystemHealthChecker>(); container.AddSingleton <ICoreLastReferenceIdManager, NullCoreLastReferenceIdManager>(); container.AddSingleton <UsageService>(); container.AddSingleton <SlackService>(); container.AddSingleton <StackService>(); container.AddTransient <IDomainLoginProvider, ActiveDirectoryLoginProvider>(); container.AddTransient <AutoMapper.Profile, CoreMappings>(); container.AddSingleton <IMapper>(s => { var profiles = s.GetServices <AutoMapper.Profile>(); var c = new MapperConfiguration(cfg => { cfg.AddCollectionMappers(); cfg.ConstructServicesUsing(s.GetRequiredService); foreach (var profile in profiles) { cfg.AddProfile(profile); } }); return(c.CreateMapper()); }); }
public static void RegisterServices(Container container, ILoggerFactory loggerFactory) { container.RegisterLogger(loggerFactory); container.RegisterSingleton <IDependencyResolver>(() => new SimpleInjectorDependencyResolver(container)); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { DateParseHandling = DateParseHandling.DateTimeOffset }; var contractResolver = new ExceptionlessContractResolver(); contractResolver.UseDefaultResolverFor(typeof(DataDictionary), typeof(SettingsDictionary), typeof(VersionOne.VersionOneWebHookStack), typeof(VersionOne.VersionOneWebHookEvent)); var settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, DateParseHandling = DateParseHandling.DateTimeOffset, ContractResolver = contractResolver }; settings.AddModelConverters(loggerFactory.CreateLogger(nameof(Bootstrapper))); container.RegisterSingleton <IContractResolver>(() => contractResolver); container.RegisterSingleton <JsonSerializerSettings>(settings); container.RegisterSingleton <JsonSerializer>(JsonSerializer.Create(settings)); container.RegisterSingleton <ISerializer>(() => new JsonNetSerializer(settings)); container.RegisterSingleton <IMetricsClient>(() => new InMemoryMetricsClient(loggerFactory: loggerFactory)); container.RegisterSingleton <QueryBuilderRegistry>(() => { var builder = new QueryBuilderRegistry(); builder.RegisterDefaults(); builder.Register(new OrganizationIdQueryBuilder()); builder.Register(new ProjectIdQueryBuilder()); builder.Register(new StackIdQueryBuilder()); return(builder); }); container.RegisterSingleton <ElasticConfigurationBase, ElasticConfiguration>(); container.RegisterSingleton <IElasticClient>(() => container.GetInstance <ElasticConfigurationBase>().GetClient(Settings.Current.ElasticSearchConnectionString.Split(',').Select(url => new Uri(url)))); container.RegisterSingleton <EventIndex, EventIndex>(); container.RegisterSingleton <OrganizationIndex, OrganizationIndex>(); container.RegisterSingleton <StackIndex, StackIndex>(); container.RegisterSingleton <ICacheClient, InMemoryCacheClient>(); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventPost> > >(() => new[] { new MetricsQueueBehavior <EventPost>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventUserDescription> > >(() => new[] { new MetricsQueueBehavior <EventUserDescription>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventNotificationWorkItem> > >(() => new[] { new MetricsQueueBehavior <EventNotificationWorkItem>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <WebHookNotification> > >(() => new[] { new MetricsQueueBehavior <WebHookNotification>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <MailMessage> > >(() => new[] { new MetricsQueueBehavior <MailMessage>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <WorkItemData> > >(() => new[] { new MetricsQueueBehavior <WorkItemData>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IQueue <EventPost> >(() => new InMemoryQueue <EventPost>(behaviors: container.GetAllInstances <IQueueBehavior <EventPost> >())); container.RegisterSingleton <IQueue <EventUserDescription> >(() => new InMemoryQueue <EventUserDescription>(behaviors: container.GetAllInstances <IQueueBehavior <EventUserDescription> >())); container.RegisterSingleton <IQueue <EventNotificationWorkItem> >(() => new InMemoryQueue <EventNotificationWorkItem>(behaviors: container.GetAllInstances <IQueueBehavior <EventNotificationWorkItem> >())); container.RegisterSingleton <IQueue <WebHookNotification> >(() => new InMemoryQueue <WebHookNotification>(behaviors: container.GetAllInstances <IQueueBehavior <WebHookNotification> >())); container.RegisterSingleton <IQueue <MailMessage> >(() => new InMemoryQueue <MailMessage>(behaviors: container.GetAllInstances <IQueueBehavior <MailMessage> >())); var workItemHandlers = new WorkItemHandlers(); workItemHandlers.Register <ReindexWorkItem>(container.GetInstance <ReindexWorkItemHandler>); workItemHandlers.Register <RemoveOrganizationWorkItem>(container.GetInstance <RemoveOrganizationWorkItemHandler>); workItemHandlers.Register <RemoveProjectWorkItem>(container.GetInstance <RemoveProjectWorkItemHandler>); workItemHandlers.Register <SetLocationFromGeoWorkItem>(container.GetInstance <SetLocationFromGeoWorkItemHandler>); workItemHandlers.Register <SetProjectIsConfiguredWorkItem>(container.GetInstance <SetProjectIsConfiguredWorkItemHandler>); workItemHandlers.Register <StackWorkItem>(container.GetInstance <StackWorkItemHandler>); workItemHandlers.Register <ThrottleBotsWorkItem>(container.GetInstance <ThrottleBotsWorkItemHandler>); workItemHandlers.Register <OrganizationMaintenanceWorkItem>(container.GetInstance <OrganizationMaintenanceWorkItemHandler>); workItemHandlers.Register <OrganizationNotificationWorkItem>(container.GetInstance <OrganizationNotificationWorkItemHandler>); workItemHandlers.Register <ProjectMaintenanceWorkItem>(container.GetInstance <ProjectMaintenanceWorkItemHandler>); container.RegisterSingleton <WorkItemHandlers>(workItemHandlers); container.RegisterSingleton <IQueue <WorkItemData> >(() => new InMemoryQueue <WorkItemData>(behaviors: container.GetAllInstances <IQueueBehavior <WorkItemData> >(), workItemTimeout: TimeSpan.FromHours(1))); container.RegisterSingleton <IMessageBus, InMemoryMessageBus>(); container.RegisterSingleton <IMessagePublisher>(container.GetInstance <IMessageBus>); container.RegisterSingleton <IMessageSubscriber>(container.GetInstance <IMessageBus>); if (!String.IsNullOrEmpty(Settings.Current.StorageFolder)) { container.RegisterSingleton <IFileStorage>(new FolderFileStorage(Settings.Current.StorageFolder)); } else { container.RegisterSingleton <IFileStorage>(new InMemoryFileStorage()); } container.RegisterSingleton <IStackRepository, StackRepository>(); container.RegisterSingleton <IEventRepository, EventRepository>(); container.RegisterSingleton <IOrganizationRepository, OrganizationRepository>(); container.RegisterSingleton <IProjectRepository, ProjectRepository>(); container.RegisterSingleton <IUserRepository, UserRepository>(); container.RegisterSingleton <IWebHookRepository, WebHookRepository>(); container.RegisterSingleton <ITokenRepository, TokenRepository>(); container.RegisterSingleton <IApplicationRepository, ApplicationRepository>(); container.RegisterSingleton <IGeoIpService, MaxMindGeoIpService>(); container.RegisterSingleton <IGeocodeService, NullGeocodeService>(); container.Register(typeof(IValidator <>), new[] { typeof(Bootstrapper).Assembly }, Lifestyle.Singleton); container.Register(typeof(ElasticRepositoryContext <>), typeof(ElasticRepositoryContext <>), Lifestyle.Singleton); container.RegisterSingleton <IEmailGenerator>(() => new RazorEmailGenerator(@"Mail\Templates")); container.RegisterSingleton <IMailer, Mailer>(); if (Settings.Current.WebsiteMode != WebsiteMode.Dev) { container.RegisterSingleton <IMailSender, SmtpMailSender>(); } else { container.RegisterSingleton <IMailSender>(() => new InMemoryMailSender()); } container.RegisterSingleton <ILockProvider, CacheLockProvider>(); container.Register <StripeEventHandler>(); container.RegisterSingleton <BillingManager>(); container.RegisterSingleton <SampleDataService>(); container.RegisterSingleton <EventStats>(); container.RegisterSingleton <EventPipeline>(); container.RegisterSingleton <EventPluginManager>(); container.RegisterSingleton <FormattingPluginManager>(); container.RegisterSingleton <UserAgentParser>(); container.RegisterSingleton <SystemHealthChecker>(); container.RegisterSingleton <ICoreLastReferenceIdManager, NullCoreLastReferenceIdManager>(); container.RegisterSingleton <IMapper>(() => { var profiles = container.GetAllInstances <Profile>(); var config = new MapperConfiguration(cfg => { cfg.ConstructServicesUsing(container.GetInstance); foreach (var profile in profiles) { cfg.AddProfile(profile); } }); return(config.CreateMapper()); }); }
public void RegisterServices(Container container) { container.RegisterSingle <IDependencyResolver>(() => new SimpleInjectorCoreDependencyResolver(container)); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { DateParseHandling = DateParseHandling.DateTimeOffset }; var settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, DateParseHandling = DateParseHandling.DateTimeOffset, ContractResolver = new ExceptionlessContractResolver() }; settings.AddModelConverters(); container.RegisterSingle <JsonSerializerSettings>(settings); container.RegisterSingle <ISerializer>(() => new JsonNetSerializer(settings)); var metricsClient = new InMemoryMetricsClient(); metricsClient.StartDisplayingStats(); container.RegisterSingle <IMetricsClient>(metricsClient); container.RegisterSingle <MongoDatabase>(() => { if (String.IsNullOrEmpty(Settings.Current.MongoConnectionString)) { throw new ConfigurationErrorsException("MongoConnectionString was not found in the Web.config."); } MongoDefaults.MaxConnectionIdleTime = TimeSpan.FromMinutes(1); var url = new MongoUrl(Settings.Current.MongoConnectionString); string databaseName = url.DatabaseName; if (Settings.Current.AppendMachineNameToDatabase) { databaseName += String.Concat("-", Environment.MachineName.ToLower()); } MongoServer server = new MongoClient(url).GetServer(); return(server.GetDatabase(databaseName)); }); container.RegisterSingle <IElasticClient>(() => ElasticSearchConfiguration.GetElasticClient(Settings.Current.ElasticSearchConnectionString.Split(',').Select(url => new Uri(url)))); container.RegisterSingle <ICacheClient, InMemoryCacheClient>(); container.RegisterSingle <IQueue <EventPost> >(() => new InMemoryQueue <EventPost>(statName: MetricNames.PostsQueueSize, metrics: container.GetInstance <IMetricsClient>())); container.RegisterSingle <IQueue <EventUserDescription> >(() => new InMemoryQueue <EventUserDescription>(statName: MetricNames.EventsUserDescriptionQueueSize, metrics: container.GetInstance <IMetricsClient>())); container.RegisterSingle <IQueue <EventNotificationWorkItem> >(() => new InMemoryQueue <EventNotificationWorkItem>(statName: MetricNames.EventNotificationQueueSize, metrics: container.GetInstance <IMetricsClient>())); container.RegisterSingle <IQueue <WebHookNotification> >(() => new InMemoryQueue <WebHookNotification>(statName: MetricNames.WebHookQueueSize, metrics: container.GetInstance <IMetricsClient>())); container.RegisterSingle <IQueue <MailMessage> >(() => new InMemoryQueue <MailMessage>(statName: MetricNames.EmailsQueueSize, metrics: container.GetInstance <IMetricsClient>())); container.RegisterSingle <IMessageBus, InMemoryMessageBus>(); container.RegisterSingle <IMessagePublisher>(container.GetInstance <IMessageBus>); container.RegisterSingle <IMessageSubscriber>(container.GetInstance <IMessageBus>); if (!String.IsNullOrEmpty(Settings.Current.StorageFolder)) { container.RegisterSingle <IFileStorage>(new FolderFileStorage(Settings.Current.StorageFolder)); } else { container.RegisterSingle <IFileStorage>(new InMemoryFileStorage()); } container.RegisterSingle <IStackRepository, StackRepository>(); container.RegisterSingle <IEventRepository, EventRepository>(); container.RegisterSingle <IOrganizationRepository, OrganizationRepository>(); container.RegisterSingle <IProjectRepository, ProjectRepository>(); container.RegisterSingle <IUserRepository, UserRepository>(); container.RegisterSingle <IWebHookRepository, WebHookRepository>(); container.RegisterSingle <ITokenRepository, TokenRepository>(); container.RegisterSingle <IApplicationRepository, ApplicationRepository>(); container.RegisterSingle <IGeoIPResolver, MindMaxGeoIPResolver>(); container.RegisterSingle <IValidator <Application>, ApplicationValidator>(); container.RegisterSingle <IValidator <Organization>, OrganizationValidator>(); container.RegisterSingle <IValidator <PersistentEvent>, PersistentEventValidator>(); container.RegisterSingle <IValidator <Project>, ProjectValidator>(); container.RegisterSingle <IValidator <Stack>, StackValidator>(); container.RegisterSingle <IValidator <Models.Admin.Token>, TokenValidator>(); container.RegisterSingle <IValidator <UserDescription>, UserDescriptionValidator>(); container.RegisterSingle <IValidator <User>, UserValidator>(); container.RegisterSingle <IValidator <WebHook>, WebHookValidator>(); container.RegisterSingle <IEmailGenerator>(() => new RazorEmailGenerator(@"Mail\Templates")); container.RegisterSingle <IMailer, Mailer>(); if (Settings.Current.WebsiteMode != WebsiteMode.Dev) { container.RegisterSingle <IMailSender, SmtpMailSender>(); } else { container.RegisterSingle <IMailSender>(() => new InMemoryMailSender()); } container.Register <ILockProvider, CacheLockProvider>(); container.Register <StripeEventHandler>(); container.RegisterSingle <BillingManager>(); container.RegisterSingle <DataHelper>(); container.RegisterSingle <EventStats>(); container.RegisterSingle <EventPipeline>(); container.RegisterSingle <EventPluginManager>(); container.RegisterSingle <FormattingPluginManager>(); container.RegisterSingle <ICoreLastReferenceIdManager, NullCoreLastReferenceIdManager>(); }
private static int Main(string[] args) { OutputHeader(); // TODO: Hook up nlog to write to the console. Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); try { var ca = new ConsoleArguments(); if (Parser.ParseHelp(args)) { OutputUsageHelp(); PauseIfDebug(); return(0); } if (!Parser.ParseArguments(args, ca, Console.Error.WriteLine)) { OutputUsageHelp(); PauseIfDebug(); return(1); } Console.Clear(); OutputHeader(); const int BatchSize = 25; var container = CreateContainer(); var searchclient = container.GetInstance <IElasticClient>(); if (ca.DeleteExistingIndexes) { searchclient.DeleteIndex(i => i.AllIndices()); } var serializerSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore }; serializerSettings.AddModelConverters(); ISearchResponse <Stack> mostRecentStack = null; if (ca.Resume) { mostRecentStack = searchclient.Search <Stack>(d => d.AllIndices().Type(typeof(Stack)).SortDescending("_uid").Source(s => s.Include(e => e.Id)).Size(1)); } ISearchResponse <PersistentEvent> mostRecentEvent = null; if (ca.Resume) { mostRecentEvent = searchclient.Search <PersistentEvent>(d => d.AllIndices().Type(typeof(PersistentEvent)).SortDescending("_uid").Source(s => s.Include(e => e.Id)).Size(1)); } int total = 0; var stopwatch = new Stopwatch(); if (!ca.SkipStacks) { stopwatch.Start(); var errorStackCollection = GetErrorStackCollection(container); var query = mostRecentStack != null && mostRecentStack.Total > 0 ? Query.GT(ErrorStackFieldNames.Id, ObjectId.Parse(mostRecentStack.Hits.First().Id)) : Query.Null; var stacks = errorStackCollection.Find(query).SetSortOrder(SortBy.Ascending(ErrorStackFieldNames.Id)).SetLimit(BatchSize).ToList(); while (stacks.Count > 0) { stacks.ForEach(s => { s.Type = s.SignatureInfo != null && s.SignatureInfo.ContainsKey("HttpMethod") && s.SignatureInfo.ContainsKey("Path") ? "404" : "error"; if (s.Tags != null) { s.Tags.RemoveWhere(t => String.IsNullOrEmpty(t) || t.Length > 255); } if (s.Title != null && s.Title.Length > 1000) { s.Title = s.Title.Truncate(1000); } }); Console.SetCursorPosition(0, 4); Console.WriteLine("Migrating stacks {0:N0} total {1:N0}/s...", total, total > 0 ? total / stopwatch.Elapsed.TotalSeconds : 0); var response = searchclient.IndexMany(stacks, type: "stacks", index: ElasticSearchRepository <Stack> .StacksIndexName); if (!response.IsValid) { Debugger.Break(); } var lastId = stacks.Last().Id; stacks = errorStackCollection.Find(Query.GT(ErrorStackFieldNames.Id, ObjectId.Parse(lastId))).SetSortOrder(SortBy.Ascending(ErrorStackFieldNames.Id)).SetLimit(BatchSize).ToList(); total += stacks.Count; } } total = 0; stopwatch.Reset(); if (!ca.SkipErrors) { stopwatch.Start(); var eventUpgraderPluginManager = container.GetInstance <EventUpgraderPluginManager>(); var eventRepository = container.GetInstance <IEventRepository>(); var errorCollection = GetErrorCollection(container); //var json1 = JsonExtensions.ToJson(errorCollection.FindOneById(ObjectId.Parse("80000000e2cc694bd029a952")), Formatting.Indented); //var json2 = JsonExtensions.ToJson(errorCollection.FindOneById(ObjectId.Parse("80000000e2cc694bd029a953")), Formatting.Indented); //var ctx2 = new EventUpgraderContext("[" + json1 + "," + json2 + "]", new Version(1, 5), true); //eventUpgraderPluginManager.Upgrade(ctx2); //var ev2 = ctx2.Documents.ToObject<List<PersistentEvent>>(); //eventRepository.Add(ev2.First()); //eventRepository.Add(ev2.Last()); var query = mostRecentEvent != null && mostRecentEvent.Total > 0 ? Query.GT(ErrorFieldNames.Id, ObjectId.Parse(mostRecentEvent.Hits.First().Id)) : Query.Null; var errors = errorCollection.Find(query).SetSortOrder(SortBy.Ascending(ErrorFieldNames.Id)).SetLimit(BatchSize).ToList(); // TODO: When resuming, we need to get a list of existing stack ids from the events. var knownStackIds = new List <string>(); while (errors.Count > 0) { Console.SetCursorPosition(0, 5); Console.WriteLine("Migrating events {0}-{1} {2:N0} total {3:N0}/s...", errors.First().Id, errors.Last().Id, total, total > 0 ? total / stopwatch.Elapsed.TotalSeconds : 0); var events = JArray.FromObject(errors); var ctx = new EventUpgraderContext(events, new Version(1, 5), true); eventUpgraderPluginManager.Upgrade(ctx); var ev = events.FromJson <PersistentEvent>(serializerSettings); ev.ForEach(e => { if (e.Date.UtcDateTime > DateTimeOffset.UtcNow.AddHours(1)) { e.Date = DateTimeOffset.Now; } if (e.Type != Event.KnownTypes.Error) { return; } if (!knownStackIds.Contains(e.StackId)) { e.IsFirstOccurrence = true; knownStackIds.Add(e.StackId); } var request = e.GetRequestInfo(); if (request != null) { e.AddRequestInfo(request.ApplyDataExclusions(RequestInfoPlugin.DefaultExclusions, RequestInfoPlugin.MAX_VALUE_LENGTH)); } var stacking = e.GetStackingTarget(); if (stacking != null && stacking.Method != null && !String.IsNullOrEmpty(stacking.Method.DeclaringTypeFullName)) { e.Source = stacking.Method.DeclaringTypeFullName.Truncate(2000); } }); try { eventRepository.Add(ev); } catch (Exception ex) { Debugger.Break(); } var lastId = ev.Last().Id; errors = errorCollection.Find(Query.GT(ErrorFieldNames.Id, ObjectId.Parse(lastId))).SetSortOrder(SortBy.Ascending(ErrorFieldNames.Id)).SetLimit(BatchSize).ToList(); total += events.Count; } } PauseIfDebug(); } catch (FileNotFoundException e) { Console.Error.WriteLine("{0} ({1})", e.Message, e.FileName); PauseIfDebug(); return(1); } catch (Exception e) { Console.Error.WriteLine(e.ToString()); PauseIfDebug(); return(1); } return(0); }
public JsonEventParserPlugin() { _settings.AddModelConverters(); }
public void RegisterServices(Container container) { // Foundation service provider ServiceProvider.Current = container; container.RegisterSingleton <IDependencyResolver>(() => new SimpleInjectorCoreDependencyResolver(container)); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { DateParseHandling = DateParseHandling.DateTimeOffset }; var contractResolver = new ExceptionlessContractResolver(); contractResolver.UseDefaultResolverFor(typeof(DataDictionary), typeof(SettingsDictionary), typeof(VersionOne.VersionOneWebHookStack), typeof(VersionOne.VersionOneWebHookEvent)); var settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, DateParseHandling = DateParseHandling.DateTimeOffset, ContractResolver = contractResolver }; settings.AddModelConverters(); container.RegisterSingleton <IContractResolver>(() => contractResolver); container.RegisterSingleton <JsonSerializerSettings>(settings); container.RegisterSingleton <JsonSerializer>(JsonSerializer.Create(settings)); container.RegisterSingleton <ISerializer>(() => new JsonNetSerializer(settings)); container.RegisterSingleton <IMetricsClient, InMemoryMetricsClient>(); container.RegisterSingleton <IElasticClient>(() => container.GetInstance <ElasticSearchConfiguration>().GetClient(Settings.Current.ElasticSearchConnectionString.Split(',').Select(url => new Uri(url)))); container.RegisterSingleton <EventIndex, EventIndex>(); container.RegisterSingleton <OrganizationIndex, OrganizationIndex>(); container.RegisterSingleton <StackIndex, StackIndex>(); container.RegisterSingleton <ICacheClient, InMemoryCacheClient>(); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventPost> > >(() => new[] { new MetricsQueueBehavior <EventPost>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventUserDescription> > >(() => new[] { new MetricsQueueBehavior <EventUserDescription>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <EventNotificationWorkItem> > >(() => new[] { new MetricsQueueBehavior <EventNotificationWorkItem>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <WebHookNotification> > >(() => new[] { new MetricsQueueBehavior <WebHookNotification>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <MailMessage> > >(() => new[] { new MetricsQueueBehavior <MailMessage>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IEnumerable <IQueueBehavior <WorkItemData> > >(() => new[] { new MetricsQueueBehavior <WorkItemData>(container.GetInstance <IMetricsClient>()) }); container.RegisterSingleton <IQueue <EventPost> >(() => new InMemoryQueue <EventPost>(behaviors: container.GetAllInstances <IQueueBehavior <EventPost> >())); container.RegisterSingleton <IQueue <EventUserDescription> >(() => new InMemoryQueue <EventUserDescription>(behaviors: container.GetAllInstances <IQueueBehavior <EventUserDescription> >())); container.RegisterSingleton <IQueue <EventNotificationWorkItem> >(() => new InMemoryQueue <EventNotificationWorkItem>(behaviors: container.GetAllInstances <IQueueBehavior <EventNotificationWorkItem> >())); container.RegisterSingleton <IQueue <WebHookNotification> >(() => new InMemoryQueue <WebHookNotification>(behaviors: container.GetAllInstances <IQueueBehavior <WebHookNotification> >())); container.RegisterSingleton <IQueue <MailMessage> >(() => new InMemoryQueue <MailMessage>(behaviors: container.GetAllInstances <IQueueBehavior <MailMessage> >())); container.RegisterSingleton <IQueue <StatusMessage> >(() => new InMemoryQueue <StatusMessage>()); var workItemHandlers = new WorkItemHandlers(); workItemHandlers.Register <ReindexWorkItem, ReindexWorkItemHandler>(); workItemHandlers.Register <RemoveOrganizationWorkItem, RemoveOrganizationWorkItemHandler>(); workItemHandlers.Register <RemoveProjectWorkItem, RemoveProjectWorkItemHandler>(); workItemHandlers.Register <SetProjectIsConfiguredWorkItem, SetProjectIsConfiguredWorkItemHandler>(); workItemHandlers.Register <StackWorkItem, StackWorkItemHandler>(); workItemHandlers.Register <ThrottleBotsWorkItem, ThrottleBotsWorkItemHandler>(); container.RegisterSingleton <WorkItemHandlers>(workItemHandlers); container.RegisterSingleton <IQueue <WorkItemData> >(() => new InMemoryQueue <WorkItemData>(behaviors: container.GetAllInstances <IQueueBehavior <WorkItemData> >(), workItemTimeout: TimeSpan.FromHours(1))); container.RegisterSingleton <IMessageBus, InMemoryMessageBus>(); container.RegisterSingleton <IMessagePublisher>(container.GetInstance <IMessageBus>); container.RegisterSingleton <IMessageSubscriber>(container.GetInstance <IMessageBus>); if (!String.IsNullOrEmpty(Settings.Current.StorageFolder)) { container.RegisterSingleton <IFileStorage>(new FolderFileStorage(Settings.Current.StorageFolder)); } else { container.RegisterSingleton <IFileStorage>(new InMemoryFileStorage()); } container.RegisterSingleton <IStackRepository, StackRepository>(); container.RegisterSingleton <IEventRepository, EventRepository>(); container.RegisterSingleton <IOrganizationRepository, OrganizationRepository>(); container.RegisterSingleton <IProjectRepository, ProjectRepository>(); container.RegisterSingleton <IUserRepository, UserRepository>(); container.RegisterSingleton <IWebHookRepository, WebHookRepository>(); container.RegisterSingleton <ITokenRepository, TokenRepository>(); container.RegisterSingleton <IApplicationRepository, ApplicationRepository>(); container.RegisterSingleton <IGeoIPResolver, MindMaxGeoIPResolver>(); container.RegisterSingleton <IValidator <Application>, ApplicationValidator>(); container.RegisterSingleton <IValidator <Organization>, OrganizationValidator>(); container.RegisterSingleton <IValidator <PersistentEvent>, PersistentEventValidator>(); container.RegisterSingleton <IValidator <Project>, ProjectValidator>(); container.RegisterSingleton <IValidator <Stack>, StackValidator>(); container.RegisterSingleton <IValidator <Models.Token>, TokenValidator>(); container.RegisterSingleton <IValidator <UserDescription>, UserDescriptionValidator>(); container.RegisterSingleton <IValidator <User>, UserValidator>(); container.RegisterSingleton <IValidator <WebHook>, WebHookValidator>(); container.RegisterSingleton <IEmailGenerator>(() => new RazorEmailGenerator(@"Mail\Templates")); container.RegisterSingleton <IMailer, Mailer>(); if (Settings.Current.WebsiteMode != WebsiteMode.Dev) { container.RegisterSingleton <IMailSender, SmtpMailSender>(); } else { container.RegisterSingleton <IMailSender>(() => new InMemoryMailSender()); } container.RegisterSingleton <ILockProvider, CacheLockProvider>(); container.Register <StripeEventHandler>(); container.RegisterSingleton <BillingManager>(); container.RegisterSingleton <DataHelper>(); container.RegisterSingleton <EventStats>(); container.RegisterSingleton <EventPipeline>(); container.RegisterSingleton <EventPluginManager>(); container.RegisterSingleton <FormattingPluginManager>(); container.RegisterSingleton <ICoreLastReferenceIdManager, NullCoreLastReferenceIdManager>(); }