本文整理汇总了C#中Newtonsoft.Json.JsonSerializerSettings.AddModelConverters方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializerSettings.AddModelConverters方法的具体用法?C# JsonSerializerSettings.AddModelConverters怎么用?C# JsonSerializerSettings.AddModelConverters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonSerializerSettings
的用法示例。
在下文中一共展示了JsonSerializerSettings.AddModelConverters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseEvents
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;
}
示例2: RegisterServices
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>();
}
示例3: RegisterServices
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
//.........这里部分代码省略.........