/// <summary> /// Imports an individual ResX Resource file into the database /// </summary> /// <param name="FileName">Full path to the the ResX file</param> /// <param name="ResourceSetName">Name of the file or for local resources the app relative path plus filename (admin/default.aspx or default.aspx)</param> /// <param name="LocaleId">Locale Id of the file to import. Use "" for Invariant</param> /// <returns></returns> public bool ImportResourceFile(string FileName, string ResourceSetName, string LocaleId) { string FilePath = Path.GetDirectoryName(FileName) + "\\"; wwDbResourceDataManager Data = new wwDbResourceDataManager(); XmlDocument Dom = new XmlDocument(); try { Dom.Load(FileName); } catch (Exception ex) { this.ErrorMessage = ex.Message; return(false); } XmlNodeList nodes = Dom.DocumentElement.SelectNodes("data"); foreach (XmlNode Node in nodes) { string Value = Node.ChildNodes[0].InnerText; string Name = Node.Attributes["name"].Value; string Type = null; if (Node.Attributes["type"] != null) { Type = Node.Attributes["type"].Value; } if (string.IsNullOrEmpty(Type)) { Data.UpdateOrAdd(Name, Value, LocaleId, ResourceSetName); } else { // *** File based resources are formatted: filename;full type name string[] tokens = Value.Split(';'); if (tokens.Length > 0) { string ResFileName = FilePath + tokens[0]; if (File.Exists(ResFileName)) { // *** DataManager knows about file resources and can figure type info Data.UpdateOrAdd(Name, ResFileName, LocaleId, ResourceSetName, true); } } } } return(true); }
/// <summary> /// The main method to retrieve a specific resource key. The provider /// internally handles resource fallback based on the ResourceSet implementation. /// </summary> /// <param name="ResourceKey"></param> /// <param name="culture"></param> /// <returns></returns> object IResourceProvider.GetObject(string ResourceKey, CultureInfo culture) { object value = this.ResourceManager.GetObject(ResourceKey, culture); // *** If the value is still null and we're at the invariant culture // *** let's add a marker that the value is missing // *** this also allows the pre-compiler to work and never return null if (value == null && (culture == null || culture == CultureInfo.InvariantCulture)) { // *** No entry there value = ""; if (wwDbResourceConfiguration.Current.AddMissingResources) { // *** Add invariant resource wwDbResourceDataManager Data = new wwDbResourceDataManager(); if (!Data.ResourceExists(ResourceKey, "", this._className)) { Data.UpdateOrAdd(ResourceKey, "*** Missing", "", this._className); } } } return(value); }
private static void AddResourceToStore(string key, object value, string resourceSet, IServiceProvider serviceProvider) { // *** Use custom data manager to write the values into the database wwDbResourceDataManager Manager = new wwDbResourceDataManager(); if (Manager.UpdateOrAdd(key, value, "", resourceSet) == -1) { throw new InvalidOperationException("Resource update error: " + Manager.ErrorMessage); } }