Class VirtualPathXmlLocalizationProviderInitializer

Initializes a new FileXmlLocalizationProvider using the given virtual path to locate xml files.

Inheritance
System.Object
VirtualPathXmlLocalizationProviderInitializer
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Framework.Localization.XmlResources
Assembly: EPiServer.Framework.AspNet.dll
Version: 11.20.7
Syntax
public class VirtualPathXmlLocalizationProviderInitializer
Examples

Example of how a VirtualPathXmlLocalizationProviderInitializer can be used:

using System;
using System.Linq;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Framework.Localization;
using EPiServer.Framework.Localization.XmlResources;
using EPiServer.Web.Hosting;

namespace CodeSamples { [InitializableModule] //A dependency to EPiServer CMS initialization is needed to be able to use a VPP [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class CustomLanguageProviderInitializationWithVirtualPath : IInitializableModule { private const string ProviderName = "CustomProviderName";

public void Initialize(InitializationEngine context) { //Casts the current LocalizationService to a ProviderBasedLocalizationService to get access to the current list of providers ProviderBasedLocalizationService localizationService = context.Locate.Advanced.GetInstance<LocalizationService>() as ProviderBasedLocalizationService; if (localizationService != null) { VirtualPathXmlLocalizationProviderInitializer localizationProviderInitializer = new VirtualPathXmlLocalizationProviderInitializer(GenericHostingEnvironment.VirtualPathProvider); //a VPP with the path below must be registered in the sites configuration. string virtualPath = "~/MyCustomLanguageVPP/"; FileXmlLocalizationProvider localizationProvider = localizationProviderInitializer.GetInitializedProvider(virtualPath, ProviderName); //Inserts the provider first in the provider list so that it is prioritized over default providers. localizationService.Providers.Insert(0, localizationProvider); } }

public void Uninitialize(InitializationEngine context) { //Casts the current LocalizationService to a ProviderBasedLocalizationService to get access to the current list of providers ProviderBasedLocalizationService localizationService = context.Locate.Advanced.GetInstance<LocalizationService>() as ProviderBasedLocalizationService; if (localizationService != null) { //Gets any provider that has the same name as the one initialized. LocalizationProvider localizationProvider = localizationService.Providers.FirstOrDefault(p => p.Name.Equals(ProviderName, StringComparison.Ordinal)); if (localizationProvider != null) { //If found, remove it. localizationService.Providers.Remove(localizationProvider); } } }

public void Preload(string[] parameters) { } } }

Constructors

VirtualPathXmlLocalizationProviderInitializer(VirtualPathProvider)

Initializes a new instance of the VirtualPathXmlResourceProviderInitializer class.

Declaration
public VirtualPathXmlLocalizationProviderInitializer(VirtualPathProvider virtualPathProvider)
Parameters
Type Name Description
System.Web.Hosting.VirtualPathProvider virtualPathProvider

The virtual path provider used when creating the FileXmlLocalizationProvider to initialize.

Examples

Example of how a VirtualPathXmlLocalizationProviderInitializer can be used:

using System;
using System.Linq;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Framework.Localization;
using EPiServer.Framework.Localization.XmlResources;
using EPiServer.Web.Hosting;

namespace CodeSamples { [InitializableModule] //A dependency to EPiServer CMS initialization is needed to be able to use a VPP [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class CustomLanguageProviderInitializationWithVirtualPath : IInitializableModule { private const string ProviderName = "CustomProviderName";

public void Initialize(InitializationEngine context) { //Casts the current LocalizationService to a ProviderBasedLocalizationService to get access to the current list of providers ProviderBasedLocalizationService localizationService = context.Locate.Advanced.GetInstance<LocalizationService>() as ProviderBasedLocalizationService; if (localizationService != null) { VirtualPathXmlLocalizationProviderInitializer localizationProviderInitializer = new VirtualPathXmlLocalizationProviderInitializer(GenericHostingEnvironment.VirtualPathProvider); //a VPP with the path below must be registered in the sites configuration. string virtualPath = "~/MyCustomLanguageVPP/"; FileXmlLocalizationProvider localizationProvider = localizationProviderInitializer.GetInitializedProvider(virtualPath, ProviderName); //Inserts the provider first in the provider list so that it is prioritized over default providers. localizationService.Providers.Insert(0, localizationProvider); } }

public void Uninitialize(InitializationEngine context) { //Casts the current LocalizationService to a ProviderBasedLocalizationService to get access to the current list of providers ProviderBasedLocalizationService localizationService = context.Locate.Advanced.GetInstance<LocalizationService>() as ProviderBasedLocalizationService; if (localizationService != null) { //Gets any provider that has the same name as the one initialized. LocalizationProvider localizationProvider = localizationService.Providers.FirstOrDefault(p => p.Name.Equals(ProviderName, StringComparison.Ordinal)); if (localizationProvider != null) { //If found, remove it. localizationService.Providers.Remove(localizationProvider); } } }

public void Preload(string[] parameters) { } } }

Exceptions
Type Condition
System.ArgumentNullException

If virtualPathProvider is null.

Methods

GetInitializedProvider(String, String)

Creates and initalizes a new FileXmlLocalizationProvider.

Declaration
public FileXmlLocalizationProvider GetInitializedProvider(string virtualPathToLangFolder, string nameOfProvider)
Parameters
Type Name Description
System.String virtualPathToLangFolder

The virtual path to the folder where xml-lang files are located.

System.String nameOfProvider

A name for the provider.

Returns
Type Description
FileXmlLocalizationProvider

A new initialized provider.

Examples

Example of how a VirtualPathXmlLocalizationProviderInitializer can be used:

using System;
using System.Linq;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Framework.Localization;
using EPiServer.Framework.Localization.XmlResources;
using EPiServer.Web.Hosting;

namespace CodeSamples { [InitializableModule] //A dependency to EPiServer CMS initialization is needed to be able to use a VPP [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class CustomLanguageProviderInitializationWithVirtualPath : IInitializableModule { private const string ProviderName = "CustomProviderName";

public void Initialize(InitializationEngine context) { //Casts the current LocalizationService to a ProviderBasedLocalizationService to get access to the current list of providers ProviderBasedLocalizationService localizationService = context.Locate.Advanced.GetInstance<LocalizationService>() as ProviderBasedLocalizationService; if (localizationService != null) { VirtualPathXmlLocalizationProviderInitializer localizationProviderInitializer = new VirtualPathXmlLocalizationProviderInitializer(GenericHostingEnvironment.VirtualPathProvider); //a VPP with the path below must be registered in the sites configuration. string virtualPath = "~/MyCustomLanguageVPP/"; FileXmlLocalizationProvider localizationProvider = localizationProviderInitializer.GetInitializedProvider(virtualPath, ProviderName); //Inserts the provider first in the provider list so that it is prioritized over default providers. localizationService.Providers.Insert(0, localizationProvider); } }

public void Uninitialize(InitializationEngine context) { //Casts the current LocalizationService to a ProviderBasedLocalizationService to get access to the current list of providers ProviderBasedLocalizationService localizationService = context.Locate.Advanced.GetInstance<LocalizationService>() as ProviderBasedLocalizationService; if (localizationService != null) { //Gets any provider that has the same name as the one initialized. LocalizationProvider localizationProvider = localizationService.Providers.FirstOrDefault(p => p.Name.Equals(ProviderName, StringComparison.Ordinal)); if (localizationProvider != null) { //If found, remove it. localizationService.Providers.Remove(localizationProvider); } } }

public void Preload(string[] parameters) { } } }

Exceptions
Type Condition
System.ArgumentNullException

If any parameter is null.

Extension Methods