public void FallbackTranslationTests() { ConfigurationContext.Setup(_ => { // try "sv" -> "no" -> "en" _.FallbackCultures .Try(new CultureInfo("sv")) .Then(new CultureInfo("no")) .Then(new CultureInfo("en")); // for rare cases - configure language specific fallback _.FallbackCultures .When(new CultureInfo("fr-BE")) .Try(new CultureInfo("fr")) .Then(new CultureInfo("en")); _.TypeFactory.ForQuery <GetTranslation.Query>().SetHandler(() => new FallbacksTestsTranslationHandler(_.FallbackList)); }); var sut = new LocalizationProvider(); Assert.Equal("Some Swedish translation", sut.GetString("Resource.With.Swedish.Translation", new CultureInfo("sv"))); Assert.Equal("Some English translation", sut.GetString("Resource.With.English.Translation", new CultureInfo("sv"))); Assert.Equal("Some Norwegian translation", sut.GetString("Resource.With.Norwegian.Translation", new CultureInfo("sv"))); Assert.Equal("Some Norwegian translation", sut.GetString("Resource.With.Norwegian.And.English.Translation", new CultureInfo("sv"))); }
public void Initialize(InitializationEngine context) { //Add custom view engine allowing partials to be placed in additional locations //Note that we add it first in the list to optimize view resolving when using DisplayFor/PropertyFor ViewEngines.Engines.Insert(0, new SiteViewEngine()); context.Locate.TemplateResolver() .TemplateResolved += TemplateCoordinator.OnTemplateResolved; ConfigurationContext.Setup(ctx => { ctx.RowSupportEnabled = true; ctx.AutoAddRow = false; ctx.DisableBuiltinDisplayOptions = false; ctx.CustomDisplayOptions .Add <DisplayModeFallback.None>() .Add <One12thDisplayOption>() .Add <One6thDisplayOption>() .Add(new DisplayModeFallback { Name = "Full width (1/1)", Tag = ContentAreaTags.FullWidth, LargeScreenWidth = 12, MediumScreenWidth = 12, SmallScreenWidth = 12, ExtraSmallScreenWidth = 12, Icon = "epi-icon__layout--full" }); }); }
public void Initialize(InitializationEngine context) { ConfigurationContext.Setup(ctx => { ctx.RowSupportEnabled = false; ctx.AutoAddRow = false; ctx.DisableBuiltinDisplayOptions = false; ctx.CustomDisplayOptions.AddRange(new[] { new DisplayModeFallback { Name = "One 12th (1/12)", Tag = "displaymode-one-twelfth", LargeScreenWidth = 1, MediumScreenWidth = 1, SmallScreenWidth = 1, ExtraSmallScreenWidth = 1 }, new DisplayModeFallback { Name = "One 6th (1/6)", Tag = "displaymode-one-sixth", LargeScreenWidth = 2, MediumScreenWidth = 2, SmallScreenWidth = 2, ExtraSmallScreenWidth = 2 } }); }); }
public void Initialize(InitializationEngine context) { ConfigurationContext.Setup(_ => { _.DiagnosticsEnabled = true; _.ModelMetadataProviders.EnableLegacyMode = () => true; _.CustomAttributes = new[] { new CustomAttributeDescriptor(typeof(HelpTextAttribute), false) }; _.ForeignResources.Add(typeof(VersionStatus)); _.EnableInvariantCultureFallback = true; _.DefaultResourceCulture = CultureInfo.InvariantCulture; _.CacheManager.OnRemove += CacheManagerOnOnRemove; _.PopulateCacheOnStartup = false; }); UiConfigurationContext.Setup(_ => { //_.DefaultView = ResourceListView.Tree; _.TreeViewExpandedByDefault = true; _.ShowInvariantCulture = true; //_.AuthorizedAdminRoles.Clear(); _.AuthorizedAdminRoles.Add("SomeFancyAdminRole"); //_.AuthorizedEditorRoles.Clear(); _.AuthorizedEditorRoles.Add("SomeFancyEditorRole"); //_.DisableView(ResourceListView.Table); }); }
public void Initialize(InitializationEngine context) { ConfigurationContext.Setup(ctx => { ctx.Export.Providers.Add(new Exporter()); ctx.Import.Providers.Add(new FormatParser()); }); }
public RefactoredResourceTests() { ConfigurationContext.Setup(cfg => { cfg.TypeFactory.ForQuery <DetermineDefaultCulture.Query>().SetHandler <DetermineDefaultCulture.Handler>(); cfg.CustomAttributes.Add <AdditionalDataAttribute>(); }); }
public void Initialize(InitializationEngine context) { ConfigurationContext.Setup(ctx => { ctx.Connection = "EPiServerDB"; }); foreach (ConnectionStringSettings connectionStringSettings in ConfigurationManager.ConnectionStrings) { if (connectionStringSettings.Name == ConfigurationContext.Current.Connection) { ConfigurationContext.Current.DbContextConnectionString = ConfigurationManager.ConnectionStrings[ConfigurationContext.Current.Connection].ConnectionString; } } }
public void ConfigureContainer(ServiceConfigurationContext context) { ConfigurationContext.Setup(ctx => { ctx.Connection = EPiServerDataStoreSection.Instance.DataSettings.ConnectionStringName; }); foreach (ConnectionStringSettings connectionStringSettings in ConfigurationManager.ConnectionStrings) { if (string.Equals(connectionStringSettings.Name, ConfigurationContext.Current.Connection, StringComparison.InvariantCultureIgnoreCase)) { ConfigurationContext.Current.DbContextConnectionString = ConfigurationManager.ConnectionStrings[ConfigurationContext.Current.Connection].ConnectionString; } } }
public void Initialize(InitializationEngine context) { ConfigurationContext.Setup(cfg => { cfg.DiagnosticsEnabled = true; cfg.ModelMetadataProviders.EnableLegacyMode = () => true; cfg.CustomAttributes = new[] { new CustomAttributeDescriptor(typeof(HelpTextAttribute), false) }; cfg.ForeignResources.Add(typeof(VersionStatus)); }); }
public void Initialize(InitializationEngine context) { //Add custom view engine allowing partials to be placed in additional locations //Note that we add it first in the list to optimize view resolving when using DisplayFor/PropertyFor ViewEngines.Engines.Insert(0, new SiteViewEngine()); context.Locate.TemplateResolver() .TemplateResolved += TemplateCoordinator.OnTemplateResolved; ConfigurationContext.Setup(ctx => { ctx.RowSupportEnabled = false; ctx.AutoAddRow = false; }); }
public void ConfigureContainer(ServiceConfigurationContext context) { ConfigurationContext.Setup(_ => { _.EnableLegacyMode = () => true; _.EnableInvariantCultureFallback = true; var connectionString = ConfigurationManager .ConnectionStrings[EPiServerDataStoreSection.Instance.DataSettings.ConnectionStringName] .ConnectionString; _.UseSqlServer(connectionString); }); var sync = new Synchronizer(); sync.UpdateStorageSchema(); }
public void ConfigureContainer(ServiceConfigurationContext context) { ConfigurationContext.Setup(_ => { _.EnableLegacyMode = () => true; _.EnableInvariantCultureFallback = true; var connectionString = ConfigurationManager .ConnectionStrings[EPiServerDataStoreSection.Instance.DataSettings.ConnectionStringName] .ConnectionString; _.UseSqlServer(connectionString); }); // trying out to sync db schema once again (after this has been already done in init pipeline) var sync = new Synchronizer(); sync.UpdateStorageSchema(); }
public void Initialize(InitializationEngine context) { ConfigurationContext.Setup(cfg => { cfg.DiagnosticsEnabled = true; cfg.ModelMetadataProviders.EnableLegacyMode = () => true; cfg.CustomAttributes = new[] { new CustomAttributeDescriptor(typeof(HelpTextAttribute), false) }; cfg.ForeignResources.Add(typeof(VersionStatus)); cfg.CacheManager.OnRemove += CacheManagerOnOnRemove; }); UiConfigurationContext.Setup(cfg => { cfg.DefaultView = ResourceListView.Tree; cfg.TreeViewExpandedByDefault = true; }); }
public void Language_ShouldFollowLanguageBranchSpecs() { ConfigurationContext.Setup(_ => { // try "sv" -> "no" -> "en" _.FallbackCultures .Try(new CultureInfo("sv")) .Then(new CultureInfo("no")) .Then(new CultureInfo("en")); // for rare cases - configure language specific fallback _.FallbackCultures .When(new CultureInfo("fr-BE")) .Try(new CultureInfo("fr")) .Then(new CultureInfo("en")); _.TypeFactory.ForQuery <GetTranslation.Query>().SetHandler(() => new FallbacksTestsTranslationHandler(_.FallbackList)); }); var sut = new LocalizationProvider(); Assert.Equal("Some French translation", sut.GetString("Resource.With.FrenchFallback.Translation", new CultureInfo("fr-BE"))); Assert.Equal("Some English translation", sut.GetString("Resource.InFrench.With.EnglishFallback.Translation", new CultureInfo("fr-BE"))); }
public void Initialize(InitializationEngine context) { ConfigurationContext.Setup(_ => { _.DiagnosticsEnabled = true; _.EnableLegacyMode = () => true; _.CustomAttributes = new[] { new CustomAttributeDescriptor(typeof(HelpTextAttribute), false) }; _.ForeignResources.Add(typeof(VersionStatus)); _.EnableInvariantCultureFallback = true; _.DefaultResourceCulture = CultureInfo.InvariantCulture; _.CacheManager.OnRemove += CacheManagerOnOnRemove; _.PopulateCacheOnStartup = false; _.FallbackCultures.When(new CultureInfo("en-ZA")) .Try(new CultureInfo("no")); // manually register some resources _.ManualResourceProvider = new SomeManualResources(); }); UiConfigurationContext.Setup(_ => { //_.DefaultView = ResourceListView.Tree; _.TreeViewExpandedByDefault = true; _.ShowInvariantCulture = true; //_.AuthorizedAdminRoles.Clear(); _.AuthorizedAdminRoles.Add("SomeFancyAdminRole"); //_.AuthorizedEditorRoles.Clear(); _.AuthorizedEditorRoles.Add("SomeFancyEditorRole"); //_.DisableView(ResourceListView.Table); _.DisableRemoveTranslationButton = false; _.Events.OnNewResourceCreated += OnNewResourceCreated; _.HideDeleteButton = false; }); }
public CategoriesTests() { ConfigurationContext.Setup(cfg => cfg.TypeFactory.ForQuery <DetermineDefaultCulture.Query>().SetHandler <DetermineDefaultCulture.Handler>()); }
private void DiscoverAndRegister(object sender, EventArgs eventArgs) { ConfigurationContext.Setup(ctx => { ctx.ConnectionName = "EPiServerDB"; ctx.CacheManager = new EPiServerCacheManager(); ctx.TypeFactory.ForQuery <AvailableLanguages.Query>().SetHandler <EPiServerAvailableLanguages.Handler>(); ctx.TypeFactory.ForQuery <GetTranslation.Query>().SetHandler <EPiServerGetTranslation.Handler>(); ctx.TypeFactory.ForQuery <GetAllResources.Query>().SetHandler <GetAllResources.Handler>(); ctx.TypeFactory.ForQuery <GetAllTranslations.Query>().SetHandler <GetAllTranslations.Handler>(); ctx.TypeFactory.ForCommand <CreateNewResource.Command>().SetHandler <CreateNewResource.Handler>(); ctx.TypeFactory.ForCommand <DeleteResource.Command>().SetHandler <DeleteResource.Handler>(); ctx.TypeFactory.ForCommand <CreateOrUpdateTranslation.Command>().SetHandler <CreateOrUpdateTranslation.Handler>(); ctx.TypeFactory.ForCommand <ClearCache.Command>().SetHandler <ClearCache.Handler>(); }); var synchronizer = new EPiServerResourceSync(); synchronizer.DiscoverAndRegister(); if (!ConfigurationContext.Current.ModelMetadataProviders.ReplaceProviders) { return; } var currentProvider = _container.TryGetInstance <ModelMetadataProvider>(); if (currentProvider == null) { // set current provider if (ConfigurationContext.Current.ModelMetadataProviders.UseCachedProviders) { _container.Configure(ctx => ctx.For <ModelMetadataProvider>().Use <CachedLocalizedMetadataProvider>()); } else { _container.Configure(ctx => ctx.For <ModelMetadataProvider>().Use <LocalizedMetadataProvider>()); } } else { // decorate existing provider if (ConfigurationContext.Current.ModelMetadataProviders.UseCachedProviders) { _container.Configure(ctx => ctx.For <ModelMetadataProvider>(Lifecycles.Singleton) .Use(() => new CompositeModelMetadataProvider <CachedLocalizedMetadataProvider>(currentProvider))); } else { _container.Configure(ctx => ctx.For <ModelMetadataProvider>(Lifecycles.Singleton) .Use(() => new CompositeModelMetadataProvider <LocalizedMetadataProvider>(currentProvider))); } } for (var i = 0; i < ModelValidatorProviders.Providers.Count; i++) { var provider = ModelValidatorProviders.Providers[i]; if (!(provider is DataAnnotationsModelValidatorProvider)) { continue; } ModelValidatorProviders.Providers.RemoveAt(i); ModelValidatorProviders.Providers.Insert(i, new LocalizedModelValidatorProvider()); break; } }
/// <summary> /// This si the method you are likely to call if you want to use LocalizationProvider in your ASP.NET MVC application. /// </summary> /// <param name="builder">AppBuilder instance</param> /// <param name="setup">Your custom setup lambda</param> /// <returns>The same app builder instance to support chaining</returns> public static IAppBuilder UseDbLocalizationProvider(this IAppBuilder builder, Action <ConfigurationContext> setup = null) { var sw = new Stopwatch(); sw.Start(); var ctx = ConfigurationContext.Current; // setup default implementations ctx.TypeFactory.ForQuery <AvailableLanguages.Query>().SetHandler <DefaultAvailableLanguagesHandler>(); ctx.TypeFactory.ForQuery <GetAllResources.Query>().DecorateWith <CachedGetAllResourcesHandler>(); ctx.TypeFactory.ForQuery <GetAllTranslations.Query>().SetHandler <GetAllTranslationsHandler>(); ctx.TypeFactory.ForQuery <DetermineDefaultCulture.Query>().SetHandler <DetermineDefaultCulture.Handler>(); ctx.TypeFactory.ForCommand <ClearCache.Command>().SetHandler <ClearCacheHandler>(); ctx.CacheManager = new HttpCacheManager(); // custom callback invoke here (before rest of the config is finished) if (setup != null) { ConfigurationContext.Setup(setup); } // also we need to make sure that invariant culture is last in the list if fallback to invariant is true if (ctx.EnableInvariantCultureFallback) { foreach (var fallback in ConfigurationContext.Current.FallbackList) { fallback.Value.Add(CultureInfo.InvariantCulture); } } // if we need to sync - then it's good time to do it now var sync = new Synchronizer(); sync.SyncResources(ctx.DiscoverAndRegisterResources); if (ctx.ManualResourceProvider != null) { sync.RegisterManually(ctx.ManualResourceProvider.GetResources()); } // set model metadata providers if (ctx.ModelMetadataProviders.ReplaceProviders) { if (ctx.ModelMetadataProviders.SetupCallback != null) { ctx.ModelMetadataProviders.SetupCallback(); } else { // set current provider if (ModelMetadataProviders.Current == null) { if (ctx.ModelMetadataProviders.UseCachedProviders) { ModelMetadataProviders.Current = new CachedLocalizedMetadataProvider(); } else { ModelMetadataProviders.Current = new LocalizedMetadataProvider(); } } else { if (ctx.ModelMetadataProviders.UseCachedProviders) { ModelMetadataProviders.Current = new CompositeModelMetadataProvider <CachedLocalizedMetadataProvider>(ModelMetadataProviders.Current); } else { ModelMetadataProviders.Current = new CompositeModelMetadataProvider <LocalizedMetadataProvider>(ModelMetadataProviders.Current); } } for (var i = 0; i < ModelValidatorProviders.Providers.Count; i++) { var provider = ModelValidatorProviders.Providers[i]; if (!(provider is DataAnnotationsModelValidatorProvider)) { continue; } ModelValidatorProviders.Providers.RemoveAt(i); ModelValidatorProviders.Providers.Insert(i, new LocalizedModelValidatorProvider()); break; } } } sw.Stop(); ctx.Logger?.Debug($"DbLocalizationProvider overall initialization took: {sw.ElapsedMilliseconds}ms"); return(builder); }
private void DiscoverAndRegister(object sender, EventArgs eventArgs) { ConfigurationContext.Setup(ctx => { ctx.CacheManager = new EPiServerCacheManager(); ctx.TypeScanners.Insert(0, new LocalizedCategoryScanner()); ctx.TypeFactory.ForQuery <AvailableLanguages.Query>().SetHandler <EPiServerAvailableLanguages.Handler>(); ctx.TypeFactory.ForQuery <DetermineDefaultCulture.Query>().SetHandler <EPiServerDetermineDefaultCulture.Handler>(); ctx.TypeFactory.ForQuery <GetTranslation.Query>().SetHandler <EPiServerGetTranslation.Handler>(); ctx.TypeFactory.ForQuery <GetAllResources.Query>().SetHandler <GetAllResourcesHandler>(); ctx.TypeFactory.ForQuery <GetAllResources.Query>().DecorateWith <CachedGetAllResourcesHandler>(); ctx.TypeFactory.ForQuery <GetResource.Query>().SetHandler <GetResourceHandler>(); ctx.TypeFactory.ForQuery <GetAllTranslations.Query>().SetHandler <GetAllTranslationsHandler>(); ctx.TypeFactory.ForQuery <DetermineDefaultCulture.Query>().SetHandler <EPiServerDetermineDefaultCulture.Handler>(); ctx.TypeFactory.ForCommand <CreateNewResource.Command>().SetHandler <CreateNewResourceHandler>(); ctx.TypeFactory.ForCommand <DeleteResource.Command>().SetHandler <DeleteResourceHandler>(); ctx.TypeFactory.ForCommand <RemoveTranslation.Command>().SetHandler <RemoveTranslationHandler>(); ctx.TypeFactory.ForCommand <CreateOrUpdateTranslation.Command>().SetHandler <CreateOrUpdateTranslationHandler>(); ctx.TypeFactory.ForCommand <ClearCache.Command>().SetHandler <ClearCacheHandler>(); }); ConfigurationContext.Current.DbContextConnectionString = ConfigurationManager.ConnectionStrings[ConfigurationContext.Current.Connection].ConnectionString; // we have to run resource sync *only* if database is not set in read-only mode // information about database mood at this current moment will give us IDatabaseMode var dbMode = _engine.Locate.Advanced.GetInstance <IDatabaseMode>().DatabaseMode; if (dbMode != DatabaseMode.ReadOnly) { try { // let's try to sync and fail softly var synchronizer = new ResourceSynchronizer(); synchronizer.DiscoverAndRegister(); } catch (Exception e) { _logger.Error("An error occurred while synchronizing resources.", e); } } else { _logger.Information("Skipped resource synchronization due to database being in low mood (ReadOnly)."); } if (ConfigurationContext.Current.ModelMetadataProviders.ReplaceProviders) { if (!_context.Services.Contains(typeof(ModelMetadataProvider))) { // set new provider if (ConfigurationContext.Current.ModelMetadataProviders.UseCachedProviders) { _context.Services.AddSingleton <ModelMetadataProvider, CachedLocalizedMetadataProvider>(); } else { _context.Services.AddSingleton <ModelMetadataProvider, LocalizedMetadataProvider>(); } } else { var currentProvider = ServiceLocator.Current.GetInstance <ModelMetadataProvider>(); // decorate existing provider if (ConfigurationContext.Current.ModelMetadataProviders.UseCachedProviders) { _context.Services.AddSingleton <ModelMetadataProvider>( new CompositeModelMetadataProvider <CachedLocalizedMetadataProvider>(currentProvider)); } else { _context.Services.AddSingleton <ModelMetadataProvider>( new CompositeModelMetadataProvider <LocalizedMetadataProvider>(currentProvider)); } } for (var i = 0; i < ModelValidatorProviders.Providers.Count; i++) { var provider = ModelValidatorProviders.Providers[i]; if (!(provider is DataAnnotationsModelValidatorProvider)) { continue; } ModelValidatorProviders.Providers.RemoveAt(i); ModelValidatorProviders.Providers.Insert(i, new LocalizedModelValidatorProvider()); break; } } // in cases when there has been already a call to LocalizationProvider.Current (some static weird things) // and only then setup configuration is ran - here we need to reset instance once again with new settings LocalizationProvider.Initialize(); _context.Services.AddSingleton(LocalizationProvider.Current); }
private void DiscoverAndRegister(object sender, EventArgs eventArgs) { ConfigurationContext.Setup(ctx => { ctx.CacheManager = new EPiServerCacheManager(); ctx.TypeScanners.Insert(0, new LocalizedCategoryScanner()); ctx.TypeFactory.ForQuery <AvailableLanguages.Query>().SetHandler <EPiServerAvailableLanguages.Handler>(); ctx.TypeFactory.ForQuery <GetTranslation.Query>().SetHandler <EPiServerGetTranslation.Handler>(); ctx.TypeFactory.ForQuery <GetAllResources.Query>().SetHandler <GetAllResourcesHandler>(); ctx.TypeFactory.ForQuery <GetAllTranslations.Query>().SetHandler <GetAllTranslationsHandler>(); ctx.TypeFactory.ForQuery <DetermineDefaultCulture.Query>().SetHandler <EPiServerDetermineDefaultCulture.Handler>(); ctx.TypeFactory.ForCommand <CreateNewResource.Command>().SetHandler <CreateNewResourceHandler>(); ctx.TypeFactory.ForCommand <DeleteResource.Command>().SetHandler <DeleteResourceHandler>(); ctx.TypeFactory.ForCommand <CreateOrUpdateTranslation.Command>().SetHandler <CreateOrUpdateTranslationHandler>(); ctx.TypeFactory.ForCommand <ClearCache.Command>().SetHandler <ClearCacheHandler>(); }); ConfigurationContext.Current.DbContextConnectionString = ConfigurationManager.ConnectionStrings[ConfigurationContext.Current.Connection].ConnectionString; var synchronizer = new ResourceSynchronizer(); synchronizer.DiscoverAndRegister(); if (ConfigurationContext.Current.ModelMetadataProviders.ReplaceProviders) { if (!_context.Services.Contains(typeof(ModelMetadataProvider))) { // set new provider if (ConfigurationContext.Current.ModelMetadataProviders.UseCachedProviders) { _context.Services.AddSingleton <ModelMetadataProvider, CachedLocalizedMetadataProvider>(); } else { _context.Services.AddSingleton <ModelMetadataProvider, LocalizedMetadataProvider>(); } } else { var currentProvider = ServiceLocator.Current.GetInstance <ModelMetadataProvider>(); // decorate existing provider if (ConfigurationContext.Current.ModelMetadataProviders.UseCachedProviders) { _context.Services.AddSingleton <ModelMetadataProvider>( new CompositeModelMetadataProvider <CachedLocalizedMetadataProvider>(currentProvider)); } else { _context.Services.AddSingleton <ModelMetadataProvider>( new CompositeModelMetadataProvider <LocalizedMetadataProvider>(currentProvider)); } } for (var i = 0; i < ModelValidatorProviders.Providers.Count; i++) { var provider = ModelValidatorProviders.Providers[i]; if (!(provider is DataAnnotationsModelValidatorProvider)) { continue; } ModelValidatorProviders.Providers.RemoveAt(i); ModelValidatorProviders.Providers.Insert(i, new LocalizedModelValidatorProvider()); break; } } // in cases when there has been already a call to LocalizationProvider.Current (some static weird things) // and only then setup configuration is ran - here we need to reset instance once again with new settings LocalizationProvider.Initialize(); _context.Services.AddSingleton(LocalizationProvider.Current); }