public virtual string Serialize(object model, string[] exclusions = null, int maxDepth = 10, bool continueOnSerializationError = true) { if (model == null) { return(null); } JsonSerializer serializer = JsonSerializer.Create(_serializerSettings); if (maxDepth < 1) { maxDepth = Int32.MaxValue; } using (var sw = new StringWriter()) { using (var jw = new JsonTextWriterWithDepth(sw)) { jw.Formatting = Formatting.None; Func <JsonProperty, object, bool> include = (property, value) => ShouldSerialize(jw, property, value, maxDepth, exclusions); var resolver = new ExceptionlessContractResolver(include); serializer.ContractResolver = resolver; if (continueOnSerializationError) { serializer.Error += (sender, args) => { args.ErrorContext.Handled = true; } } ; serializer.Serialize(jw, model); } return(sw.ToString()); } }
public virtual string Serialize(object model, string[] exclusions = null, int maxDepth = 5, bool continueOnSerializationError = true) { if (model == null) return null; JsonSerializer serializer = JsonSerializer.Create(_serializerSettings); if (maxDepth < 1) maxDepth = Int32.MaxValue; using (var sw = new StringWriter()) { using (var jw = new JsonTextWriterWithDepth(sw)) { jw.Formatting = Formatting.None; Func<JsonProperty, object, bool> include = (property, value) => ShouldSerialize(jw, property, value, maxDepth, exclusions); var resolver = new ExceptionlessContractResolver(include); serializer.ContractResolver = resolver; if (continueOnSerializationError) serializer.Error += (sender, args) => { args.ErrorContext.Handled = true; }; serializer.Serialize(jw, model); } return sw.ToString(); } }
public void RegisterServices(Container container) { // Foundation service provider ServiceProvider.Current = container; container.RegisterSingle<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.RegisterSingle<IContractResolver>(() => contractResolver); container.RegisterSingle<JsonSerializerSettings>(settings); container.RegisterSingle<JsonSerializer>(JsonSerializer.Create(settings)); container.RegisterSingle<ISerializer>(() => new JsonNetSerializer(settings)); var metricsClient = new InMemoryMetricsClient(); metricsClient.StartDisplayingStats(); container.RegisterSingle<IMetricsClient>(metricsClient); container.RegisterSingle<IElasticClient>(() => container.GetInstance<ElasticSearchConfiguration>().GetClient(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<IQueue<StatusMessage>>(() => new InMemoryQueue<StatusMessage>()); var workItemHandlers = new WorkItemHandlers(); workItemHandlers.Register<ReindexWorkItem, ReindexWorkItemHandler>(); container.RegisterSingle<WorkItemHandlers>(workItemHandlers); container.RegisterSingle<IQueue<WorkItemData>>(() => new InMemoryQueue<WorkItemData>(statName: MetricNames.WorkItemQueueSize, metrics: container.GetInstance<IMetricsClient>(), workItemTimeout: TimeSpan.FromHours(1))); 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.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>(); }
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(); }); }