/// <summary> /// Creates a strongly typed resource class for a ResoureSet from the wwDbResourceManager. /// /// Note: Uses the default ResourceProvider settings as set in the wwDbResourceConfiguration.Current /// property for opening the database and otherwise setting values. /// </summary> /// <param name="ResourceSetName">The name of the resource set. Should be a GLOBAL resource</param> /// <param name="Namespace">The namespace for the generated class. Null or string.Empty to not generate a namespace</param> /// <param name="Classname">Name of the class to be generated</param> /// <param name="FileName">Output filename for the CSharp class. If null no file is generated and only the class is returned</param> /// <returns>string of the generated class</returns> public string CreateClassFromDatabaseResource(string ResourceSetName, string Namespace, string Classname, string FileName) { // *** Use the custom ResourceManage to retrieve a ResourceSet wwDbResourceManager Man = new wwDbResourceManager(ResourceSetName); ResourceSet ResourceSet = Man.GetResourceSet(CultureInfo.InvariantCulture, false, false); return(this.CreateClassFromResourceSet(ResourceSet, Namespace, Classname, FileName)); }
/// <summary> /// Generates a strongly typed assembly from the resources /// /// UNDER CONSTRUCTION. /// Doesn't work correctly for Web forms due to hard coded resource managers. /// </summary> /// <param name="ResourceSetName"></param> /// <param name="Namespace"></param> /// <param name="Classname"></param> /// <param name="FileName"></param> /// <returns></returns> public bool CreateStronglyTypedResource(string ResourceSetName, string Namespace, string Classname, string FileName) { try { //wwDbResourceDataManager Data = new wwDbResourceDataManager(); //IDictionary ResourceSet = Data.GetResourceSet("", ResourceSetName); // *** Use the custom ResourceManage to retrieve a ResourceSet wwDbResourceManager Man = new wwDbResourceManager(ResourceSetName); ResourceSet rs = Man.GetResourceSet(CultureInfo.InvariantCulture, false, false); IDictionaryEnumerator Enumerator = rs.GetEnumerator(); // *** We have to turn into a concret Dictionary Dictionary <string, object> Resources = new Dictionary <string, object>(); while (Enumerator.MoveNext()) { DictionaryEntry Item = (DictionaryEntry)Enumerator.Current; Resources.Add(Item.Key as string, Item.Value); } string[] UnmatchedElements; CodeDomProvider CodeProvider = null; string FileExtension = Path.GetExtension(FileName).TrimStart('.').ToLower(); if (FileExtension == "cs") { CodeProvider = new Microsoft.CSharp.CSharpCodeProvider(); } else if (FileExtension == "vb") { CodeProvider = new Microsoft.VisualBasic.VBCodeProvider(); } CodeCompileUnit Code = StronglyTypedResourceBuilder.Create(Resources, ResourceSetName, Namespace, CodeProvider, false, out UnmatchedElements); StreamWriter writer = new StreamWriter(FileName); CodeProvider.GenerateCodeFromCompileUnit(Code, writer, new CodeGeneratorOptions()); writer.Close(); } catch (Exception ex) { this.ErrorMessage = ex.Message; return(false); } return(true); }