public List <ResxStringResource> ResxToResourceStringDictionary(TextReader resxFileContent) { try { var result = new List <ResxStringResource>(); // Reading comments: http://msdn.microsoft.com/en-us/library/system.resources.resxdatanode.aspx using (var reader = new ResXResourceReader(resxFileContent)) { reader.UseResXDataNodes = true; var dict = reader.GetEnumerator(); while (dict.MoveNext()) { var node = (ResXDataNode)dict.Value; result.Add(new ResxStringResource() { Name = node.Name, Value = (string)node.GetValue((ITypeResolutionService)null), Comment = node.Comment }); } } return(result); } catch (Exception ex) { Trace.TraceError(ex.ToString()); } return(null); }
public static void RemoveRole(string rolename) { var reader = new ResXResourceReader(path); var node = reader.GetEnumerator(); var writer = new ResXResourceWriter(path); bool roleIn = false; while (node.MoveNext()) { if (!node.Key.ToString().Equals(rolename)) { writer.AddResource(node.Key.ToString(), node.Value.ToString()); } else { roleIn = true; } } if (!roleIn) { Console.Write("Ne postoji role {0}, nije", rolename); } else { Console.Write("Uspesno"); } writer.Generate(); writer.Close(); }
public static void EnumResourceItems(string resxFile, bool useDataNodes) { using (ResXResourceReader reader = new ResXResourceReader(resxFile)) { reader.UseResXDataNodes = useDataNodes; // Enumerate using IEnumerable.GetEnumerator(). Console.WriteLine("\n Default enumerator:"); foreach (DictionaryEntry entry in reader) { ShowResourceItem(entry, useDataNodes); } // Enumerate using GetMetadataEnumerator() IDictionaryEnumerator metadataEnumerator = reader.GetMetadataEnumerator(); Console.WriteLine("\n MetadataEnumerator:"); while (metadataEnumerator.MoveNext()) { ShowResourceItem(metadataEnumerator.Entry, useDataNodes); } // Enumerate using GetEnumerator() IDictionaryEnumerator enumerator = reader.GetEnumerator(); Console.WriteLine("\n Enumerator:"); while (enumerator.MoveNext()) { ShowResourceItem(enumerator.Entry, useDataNodes); } } }
public static void AddRole(string rolename) { var reader = new ResXResourceReader(path); var node = reader.GetEnumerator(); var writer = new ResXResourceWriter(path); bool roleIn = false; while (node.MoveNext()) { if (node.Key.ToString().Equals(rolename)) { roleIn = true; } writer.AddResource(node.Key.ToString(), node.Value.ToString()); } if (roleIn) { Console.Write("Već postoji role {0}, nije", rolename); } else { var newNode = new ResXDataNode(rolename, ""); writer.AddResource(newNode); Console.Write("Uspešno dodata role {0},", rolename); } writer.Generate(); writer.Close(); }
public static void AddOrUpdateResource(string resourceFilepath, string newKey, string newValue) { string resourcesFile = resourceFilepath + @"\Resources.resx"; var reader = new ResXResourceReader(resourcesFile); //same fileName reader.BasePath = resourceFilepath; // this is very important var node = reader.GetEnumerator(); var writer = new ResXResourceWriter(resourcesFile);//same fileName(not new) while (node.MoveNext()) { string nodeKey = node.Key.ToString(); string nodeValue = node.Value.ToString(); if (nodeKey == "alter") { nodeValue += "\r\n" + newKey;//add new script name } writer.AddResource(nodeKey, nodeValue); } var newNode = new ResXDataNode(newKey, newValue); writer.AddResource(newNode); writer.Generate(); writer.Close(); }
public void DoesNotRequireResXFileToBeOpen_Serializable() { serializable ser = new serializable("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode("test", ser); string resXFile = GetResXFileWithNode(dn, "resx.resx"); ResXResourceReader rr = new ResXResourceReader(resXFile); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator(); en.MoveNext(); ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode; rr.Close(); File.Delete("resx.resx"); Assert.IsNotNull(node, "#A1"); serializable o = node.GetValue((AssemblyName [])null) as serializable; Assert.IsNotNull(o, "#A2"); }
public static void Main() { CreateXMLResourceFile(); // Read the resources in the XML resource file. ResXResourceReader resx = new ResXResourceReader("DogBreeds.resx"); Console.WriteLine("Default Base Path: '{0}'", resx.BasePath); resx.BasePath = @"C:\Data\"; Console.WriteLine("Current Base Path: '{0}'\n", resx.BasePath); resx.UseResXDataNodes = true; IDictionaryEnumerator dict = resx.GetEnumerator(); AssemblyName[] assemblyNames = { new AssemblyName(typeof(Bitmap).Assembly.FullName) }; while (dict.MoveNext()) { ResXDataNode node = (ResXDataNode)dict.Value; if (node.FileRef != null) { object image = node.GetValue(assemblyNames); Console.WriteLine("{0}: {1} from {2}", dict.Key, image.GetType().Name, node.FileRef.FileName); } else { Console.WriteLine("{0}: {1}", node.Name, node.GetValue((ITypeResolutionService)null)); } } }
public static bool AddImageToResources(string name, Image img) { try { var reader = new ResXResourceReader(RESOURCES_FILE_NAME); var writer = new ResXResourceWriter(RESOURCES_FILE_NAME); var node = reader.GetEnumerator(); var nodeKeys = new List <String>(); while (node.MoveNext()) { var nodeKey = node.Key.ToString(); nodeKeys.Add(nodeKey); writer.AddResource(nodeKey, (Bitmap)node.Value); } if (!nodeKeys.Contains(name)) { writer.AddResource(name, img); } writer.Generate(); writer.Close(); } catch { return(false); } return(true); }
public static List <Language> GetLists(String PhysicalApplicationPath, String langage = "langage") { List <Language> cmblanguages = new List <Language>(); string resourcespath = PhysicalApplicationPath + "App_GlobalResources/" + langage; DirectoryInfo dirInfo = new DirectoryInfo(resourcespath); foreach (FileInfo filInfo in dirInfo.GetFiles()) { string filename = filInfo.Name; if (!filename.ToUpper().EndsWith(".designer.cs".ToUpper())) { ResXResourceReader RrX = new ResXResourceReader(filInfo.Directory.FullName + "\\" + filInfo.Name); IDictionaryEnumerator RrEn = RrX.GetEnumerator(); Language language = new Language(); while (RrEn.MoveNext()) { if (RrEn.Key.ToString() == "code") { language.Code = RrEn.Value.ToString(); } if (RrEn.Key.ToString() == "Language") { language.Name = RrEn.Value.ToString(); } } cmblanguages.Add(language); RrX.Close(); } } return(cmblanguages); }
public static void RemoveAndAddNewResEntry(string resFileName, string key, string value) { bool isKeyExist = false; using (ResXResourceReader reader = new ResXResourceReader(resFileName)) { using (ResXResourceWriter writer = new ResXResourceWriter(resFileName)) { IDictionaryEnumerator de = reader.GetEnumerator(); while (de.MoveNext()) { if (!de.Entry.Key.ToString().Equals(key, StringComparison.InvariantCultureIgnoreCase)) { writer.AddResource(de.Entry.Key.ToString(), de.Entry.Value.ToString()); } else { isKeyExist = true; } } if (!isKeyExist) { writer.AddResource(key, value); } } } }
public void WriteRead1() { ResXResourceWriter rw = new ResXResourceWriter("resx.resx"); serializable ser = new serializable("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode("test", ser); dn.Comment = "comment"; rw.AddResource(dn); rw.Close(); bool found = false; ResXResourceReader rr = new ResXResourceReader("resx.resx"); IDictionaryEnumerator en = rr.GetEnumerator(); while (en.MoveNext()) { serializable o = ((DictionaryEntry)en.Current).Value as serializable; if (o != null) { found = true; Assert.AreEqual(ser, o, "#A1"); } } rr.Close(); Assert.IsTrue(found, "#A2 - Serialized object not found on resx"); }
void ReadLocalized() { if (!File.Exists(LocalizedFileName)) { return; } ResXResourceReader reader = new ResXResourceReader(LocalizedFileName); reader.UseResXDataNodes = true; System.Collections.IDictionaryEnumerator enumerator = reader.GetEnumerator(); // Run through the file looking for only true text related // properties and only those with values set. Others are saved in the nonStringNodes // so they can be written back later. foreach (System.Collections.DictionaryEntry dic in reader) { // Only consider this entry if the value is something. if (null != dic.Value) { ResXDataNode dataNode = (ResXDataNode)dic.Value; if (InterestingString(dataNode) && strings.ContainsKey(dataNode.Name)) { strings[dataNode.Name].Localized = (string)(dataNode.GetValue(noAssemblies)); } else { nonStringNodes.Add(dataNode); } } } }
private Stream ProvideResourceData(string resourceFullFilename) { // For non-.resx files just create a FileStream object to read the file as binary data if (!resourceFullFilename.EndsWith(".resx", StringComparison.OrdinalIgnoreCase)) { return(File.OpenRead(resourceFullFilename)); } var shortLivedBackingStream = new MemoryStream(); using (ResourceWriter resourceWriter = new ResourceWriter(shortLivedBackingStream)) { resourceWriter.TypeNameConverter = TypeNameConverter; using (var resourceReader = new ResXResourceReader(resourceFullFilename)) { resourceReader.BasePath = Path.GetDirectoryName(resourceFullFilename); var dictionaryEnumerator = resourceReader.GetEnumerator(); while (dictionaryEnumerator.MoveNext()) { if (dictionaryEnumerator.Key is string resourceKey) { resourceWriter.AddResource(resourceKey, dictionaryEnumerator.Value); } } } } return(new MemoryStream(shortLivedBackingStream.GetBuffer())); }
public bool Compile(string resx, ref string resources) { DictionaryEntry item; if (string.IsNullOrWhiteSpace(resources)) { resources = Path.GetTempFileName(); } try { using (var w = new ResourceWriter(resources)) { using (var r = new ResXResourceReader(resx)) { r.BasePath = Path.GetDirectoryName(resx); var e = r.GetEnumerator(); while (e.MoveNext()) { item = (DictionaryEntry)e.Current; w.AddResource(item.Key as string, item.Value); } } } } catch (Exception ex) { Log.Exception(ex); return(false); } return(true); }
public string ReadResFile(string key) { string resourceValue = string.Empty; string file = ""; switch (Employee.TheLanguageCode) { case "da-DK": file = "Message.da-DK.resx"; break; case "de-DE": file = "Message.de-DE.resx"; break; case "en-US": file = "Message.en-US.resx"; break; } ResXResourceReader r = new ResXResourceReader(file); IDictionaryEnumerator en = r.GetEnumerator(); while (en.MoveNext()) { if (en.Key.Equals(key)) { return(resourceValue = en.Value.ToString()); } } r.Close(); return(""); }
public static List <DictionaryEntry> ReadResourceFile(string path) { List <DictionaryEntry> resourceEntries = new List <DictionaryEntry>(); //Get existing resources ResXResourceReader reader = new ResXResourceReader(path); reader.UseResXDataNodes = true; System.ComponentModel.Design.ITypeResolutionService typeres = null; if (reader != null) { IDictionaryEnumerator id = reader.GetEnumerator(); DictionaryEntry emptyValue; emptyValue.Value = ""; foreach (DictionaryEntry d in reader) { //Read from file: if (d.Value == null) { emptyValue.Key = d.Key; resourceEntries.Add(emptyValue); } else { resourceEntries.Add(d); } } reader.Close(); } return(resourceEntries); }
public void WriteRead1() { serializable ser = new serializable("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode("test", ser); dn.Comment = "comment"; string resXFile = GetResXFileWithNode(dn, "resx.resx"); bool found = false; ResXResourceReader rr = new ResXResourceReader(resXFile); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator(); while (en.MoveNext()) { ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode; if (node == null) { break; } serializable o = node.GetValue((AssemblyName [])null) as serializable; if (o != null) { found = true; Assert.AreEqual(ser, o, "#A1"); Assert.AreEqual("comment", node.Comment, "#A3"); } } rr.Close(); Assert.IsTrue(found, "#A2 - Serialized object not found on resx"); }
public void TestRoundTrip() { var key = "Some.Key.Name"; var value = "Some.Key.Value"; using (var stream = new MemoryStream()) { using (var writer = new ResXResourceWriter(stream)) { writer.AddResource(key, value); } var buffer = stream.ToArray(); using (var reader = new ResXResourceReader(new MemoryStream(buffer))) { var dictionary = new Dictionary <object, object>(); IDictionaryEnumerator dictionaryEnumerator = reader.GetEnumerator(); while (dictionaryEnumerator.MoveNext()) { dictionary.Add(dictionaryEnumerator.Key, dictionaryEnumerator.Value); } KeyValuePair <object, object> pair = Assert.Single(dictionary); Assert.Equal(key, pair.Key); Assert.Equal(value, pair.Value); } } }
public static string GetHelpTooltipText(String path, string ResourceName) { Hashtable resourceEntries = new Hashtable(); //Get existing resources ResXResourceReader reader = new ResXResourceReader(path); if (reader != null) { IDictionaryEnumerator id = reader.GetEnumerator(); foreach (DictionaryEntry d in reader) { if (d.Value == null) { resourceEntries.Add(d.Key.ToString(), ""); } else { resourceEntries.Add(d.Key.ToString(), d.Value.ToString()); } } reader.Close(); } string value = ""; if (resourceEntries.ContainsKey(ResourceName)) { value = resourceEntries[ResourceName].ToString(); } return(value); }
static bool LoadStrings(List <Tuple <string, string, string> > resourcesStrings, List <string> files) { var keys = new Dictionary <string, string> (); foreach (var fileName in files) { if (!File.Exists(fileName)) { Console.Error.WriteLine($"Error reading resource file '{fileName}'"); return(false); } var rr = new ResXResourceReader(fileName); rr.UseResXDataNodes = true; var dict = rr.GetEnumerator(); while (dict.MoveNext()) { var node = (ResXDataNode)dict.Value; resourcesStrings.Add(Tuple.Create(node.Name, (string)node.GetValue((ITypeResolutionService)null), node.Comment)); } } return(true); }
public void Test() { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE"); ResXResourceWriter w = new ResXResourceWriter(fileName); w.AddResource("point", new Point(42, 43)); w.Generate(); w.Close(); int count = 0; ResXResourceReader r = new ResXResourceReader(fileName); IDictionaryEnumerator e = r.GetEnumerator(); while (e.MoveNext()) { if ((string)e.Key == "point") { Assert.AreEqual(typeof(Point), e.Value.GetType(), "#1"); Point p = (Point)e.Value; Assert.AreEqual(42, p.X, "#2"); Assert.AreEqual(43, p.Y, "#3"); count++; } } r.Close(); Assert.AreEqual(1, count, "#100"); }
public void SaveResxImages(string resxPath) { ResXResourceReader reader = new ResXResourceReader(resxPath); var node = reader.GetEnumerator(); HashSet <string> addedTags = new HashSet <string>(); using (ResXResourceWriter resx = new ResXResourceWriter(resxPath)) { while (node.MoveNext()) { resx.AddResource(node.Key.ToString(), node.Value); addedTags.Add(node.Key.ToString()); } foreach (C1TrueDBGrid grid in Grids.Values) { foreach (ResourceImage image in grid.Images.Values) { if (!addedTags.Contains(image.Name)) { resx.AddResource(image.Name, image.ImageData); } } } } }
protected void OnSaveClick(object sender, EventArgs e) { List <string> resourceNames = new List <string>(); ResXResourceReader resxReader = new ResXResourceReader(string.Format("{0}/App_Resources/Templates.resx", WebRootPath.Instance.ToString())); IDictionaryEnumerator resxEnumerator = resxReader.GetEnumerator(); while (resxEnumerator.MoveNext()) { resourceNames.Add(resxEnumerator.Key.ToString()); } resxReader.Close(); ResXResourceWriter resxWriter = new ResXResourceWriter(string.Format("{0}\\App_Resources/Templates.resx", WebRootPath.Instance.ToString())); try { foreach (string name in resourceNames) { string value = Request.Form[string.Format("{0}${1}$TxtValue", this.RepResources.UniqueID, name)]; resxWriter.AddResource(name, value); } resxWriter.Close(); } catch (Exception) { } }
public static Dictionary <string, object> ReadResxDictionary(string fileName) { try { var dict = new Dictionary <string, object>(); if (File.Exists(fileName)) { lock (m_LockObject) { using (var reader = new ResXResourceReader(fileName)) { var enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { var keystr = enumerator.Key.ToString(); var val = enumerator.Value.ToString(); dict.Add(keystr, enumerator.Value); } } } } return(dict); } catch (Exception e) { Dbg.Debug("error during resource reading. Resource {0}, error: {1}", fileName, e); return(null); } }
/// <summary> /// Updates resource file to contain "This month last year's" average daily hours of production. Only updates resource if new month. /// </summary> /// <param name="force">If forced, the resource file will be updated regardless of the last time it was updated.</param> public static void UpdateAvgs(bool force = false) { DateTime?LastUpdate = null; IDictionaryEnumerator dict = null; ResXResourceReader resx = new ResXResourceReader("Resource1.resx"); TryGetResx: try { dict = resx.GetEnumerator(); } catch { UpdateResourceFile(); } if (dict == null) { goto TryGetResx; } while (dict.MoveNext()) { if ((string)dict.Key == "ProdAvgLastUpdate") { LastUpdate = (DateTime?)dict.Value; } } if ((LastUpdate != null && LastUpdate.HasValue && (LastUpdate.Value.Month < DateTime.Now.Month || (LastUpdate.Value.Month == 1 && DateTime.Now.Month == 12))) || force) { UpdateResourceFile(); } }
/// <summary> /// Записать зничения в файл. /// </summary> private void SaveNewValue(ResXResourceReader targetResourceReader, ResXResourceWriter targetResourceWriter, Dictionary <string, string> keyValuePairs) { try { var node = targetResourceReader.GetEnumerator(); while (node.MoveNext()) { targetResourceWriter.AddResource(node.Key.ToString(), node.Value.ToString()); } foreach (var keyValuePair in keyValuePairs) { targetResourceWriter.AddResource(new ResXDataNode(keyValuePair.Key, keyValuePair.Value)); _logService.AddMessage($"Добавлен ключ: {keyValuePair.Key} со значением: {keyValuePair.Value}"); } targetResourceWriter.Generate(); targetResourceWriter.Close(); _logService.AddMessage($"Все значения записаны."); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
private static Dictionary <string, object> TryLoadDictionary(string resourceFileName) { if (string.IsNullOrWhiteSpace(resourceFileName)) { throw new ArgumentNullException(nameof(resourceFileName)); } try { var loadedDictionary = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase); using (var resourceStream = File.OpenRead(resourceFileName)) { using (var resourceReader = new ResXResourceReader(resourceStream)) { var enumerator = resourceReader.GetEnumerator(); while (enumerator.MoveNext()) { if (!loadedDictionary.ContainsKey(enumerator.Key.ToString())) { loadedDictionary.Add(enumerator.Key.ToString(), enumerator.Value); } } } } return(loadedDictionary); } catch { return(null); } }
public void LoadResourceFile(String FileName) { this.FileName = FileName; String x = Path.GetExtension(FileName); if ((String.Compare(x, ".xml", true) == 0) || (String.Compare(x, ".resX", true) == 0)) { ResXResourceReader r = new ResXResourceReader(FileName); IDictionaryEnumerator n = r.GetEnumerator(); while (n.MoveNext()) { if (!Resource.ContainsKey(n.Key)) { Resource.Add(n.Key, n.Value); } } r.Close(); Initialize(); } else { FileStream s = new FileStream(FileName, FileMode.Open); LoadResourceStream(s); s.Close(); } }
public static List <ResXEntry> Read(string filename, Option options = Option.None) { var result = new List <ResXEntry>(); using (var resx = new ResXResourceReader(filename)) { resx.UseResXDataNodes = true; var dict = resx.GetEnumerator(); while (dict.MoveNext()) { var node = dict.Value as ResXDataNode; var comment = options.HasFlag(Option.SkipComments) ? string.Empty : node.Comment.Replace("\r", string.Empty); result.Add(new ResXEntry() { Id = dict.Key as string, Value = (node.GetValue((ITypeResolutionService)null) as string).Replace("\r", string.Empty), Comment = comment }); } resx.Close(); } return(result); }
}//public static void ResourceAdd() ///<summary>ResourceList</summary> public static void ResourceList ( ref UtilityResourceArgument utilityResourceArgument, ref string exceptionMessage ) { HttpContext httpContext = HttpContext.Current; IDictionaryEnumerator iDictionaryEnumerator = null; ResXResourceReader resXResourceReader = null; try { foreach( string filenameCurrent in utilityResourceArgument.resourceFilename ) { // Create a ResXResourceReader for the file items.resx. resXResourceReader = new ResXResourceReader( filenameCurrent ); // Create an IDictionaryEnumerator to iterate through the resources. iDictionaryEnumerator = resXResourceReader.GetEnumerator(); // Iterate through the resources and display the contents to the console. foreach ( DictionaryEntry dictionaryEntry in resXResourceReader ) { System.Console.WriteLine ( dictionaryEntry.Key.ToString() + ":\t" + dictionaryEntry.Value.ToString() ); }//foreach ( DictionaryEntry dictionaryEntry in iDictionaryEnumerator ) //Close the reader. resXResourceReader.Close(); }//foreach( string filenameCurrent in utilityResourceArgument.resourceFilename ) }//try catch( Exception exception ) { exceptionMessage = "Exception: " + exception.Message; }//catch( Expression expression ) finally { if ( resXResourceReader != null ) { resXResourceReader.Close(); }//if ( resXResourceReader != null ) }//finally if ( exceptionMessage != null ) { if ( httpContext == null ) { System.Console.WriteLine( exceptionMessage ); }//if ( httpContext == null ) else { //httpContext.Response.Write( exceptionMessage ); }//else }//if ( exceptionMessage != null ) }//public static void ResourceList()
protected void cmbResources_SelectedIndexChanged(object sender, EventArgs e) { if (cmbResources.SelectedIndex != 0) { panelUpdate.Visible = false; string filename = Request.PhysicalApplicationPath + "App_GlobalResources\\" + cmbResources.SelectedItem.Text; Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); ResXResourceReader RrX = new ResXResourceReader(stream); IDictionaryEnumerator RrEn = RrX.GetEnumerator(); SortedList slist = new SortedList(); while (RrEn.MoveNext()) { slist.Add(RrEn.Key, RrEn.Value); } RrX.Close(); stream.Dispose(); gridView1.DataSource = slist; gridView1.DataBind(); } }
private void GetData(bool QueryReturn, int packageCount, bool reload) { if (reload) { this.gridView.PageIndex = 0; } if (this.DBAlias != "" && this.CommandText != "") { DataSet tempDs = new DataSet(); string where = ""; if (this.WhereItem != "") { where = this.WhereItem; } if (QueryReturn && this.QueryCondition.Trim() != "") { if (where != "") { where += " and " + this.QueryCondition; } else { where += this.QueryCondition; } } string strSql = this.CommandText; if (where != "") { strSql = CliUtils.InsertWhere(strSql, where); } if(!string.IsNullOrEmpty(this.TypeAhead) && this.TypeAhead.EndsWith("?")) { string ta = this.TypeAhead.Substring(0, this.TypeAhead.Length - 1); strSql = CliUtils.InsertWhere(strSql, string.Format("{0} like '{1}%'", this.ValueField, ta)); } int lastIndex = (packageCount - 1) * this.PacketRecords - 1; tempDs = CliUtils.ExecuteSql("GLModule", "cmdRefValUse", strSql, "", true, CliUtils.fCurrentProject, new object[] { this.PacketRecords, lastIndex }); if (this.ViewState["WebDataSet"] != null && lastIndex != -1 && PacketRecords != -1) { ((DataSet)this.ViewState["WebDataSet"]).Merge(tempDs); } else { this.ViewState["WebDataSet"] = tempDs; } } else { #region CreateWebDataSet XmlDocument xmlDoc = new XmlDocument(); string resourceName = this.Resx; ResXResourceReader reader = new ResXResourceReader(resourceName); IDictionaryEnumerator enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Key.ToString() == "WebDataSets") { string sXml = (string)enumerator.Value; xmlDoc.LoadXml(sXml); break; } } if (xmlDoc != null) { XmlNode nWDSs = xmlDoc.SelectSingleNode("WebDataSets"); if (nWDSs != null) { string webDataSetID = this.SourceDataSet; XmlNode nWDS = nWDSs.SelectSingleNode("WebDataSet[@Name='" + webDataSetID + "']"); if (nWDS != null) { string remoteName = ""; int packetRecords = 100; bool active = false; bool serverModify = false; XmlNode nRemoteName = nWDS.SelectSingleNode("RemoteName"); if (nRemoteName != null) remoteName = nRemoteName.InnerText; XmlNode nPacketRecords = nWDS.SelectSingleNode("PacketRecords"); if (nPacketRecords != null) packetRecords = nPacketRecords.InnerText.Length == 0 ? 100 : Convert.ToInt32(nPacketRecords.InnerText); XmlNode nActive = nWDS.SelectSingleNode("Active"); if (nActive != null) active = nActive.InnerText.Length == 0 ? false : Convert.ToBoolean(nActive.InnerText); XmlNode nServerModify = nWDS.SelectSingleNode("ServerModify"); if (nServerModify != null) serverModify = nServerModify.InnerText.Length == 0 ? false : Convert.ToBoolean(nServerModify.InnerText); wds.RemoteName = remoteName; if (remoteName.IndexOf('.') != -1) { this.PackageName = remoteName.Split('.')[0]; this.InfoCommandName = remoteName.Split('.')[1]; } wds.PacketRecords = packetRecords; wds.ServerModify = serverModify; this.PacketRecords = packetRecords; string where = ""; if (QueryReturn && this.QueryCondition.Trim() != "") { if (this.WhereItem != "") where = this.WhereItem + " and " + this.QueryCondition; else where = this.QueryCondition; } else { if (this.WhereItem != "") where = this.WhereItem; } if (!string.IsNullOrEmpty(this.TypeAhead) && this.TypeAhead.EndsWith("?")) { string ta = this.TypeAhead.Substring(0, this.TypeAhead.Length - 1); if (where != "") { where += string.Format(" and {0} like '{1}%'", this.ValueField, ta); } else { where = string.Format(" {0} like '{1}%'", this.ValueField, ta); ; } } if (where != "") { wds.SetWhere(where); } wds.Active = true; if (packageCount > 1) { for (int i = 1; i < packageCount; i++) { if (!wds.GetNextPacket()) { break; } } } this.ViewState["WebDataSet"] = wds.RealDataSet; } } } #endregion } if (this.Columns == "") { this.gridView.AutoGenerateColumns = true; } else { this.gridView.AutoGenerateColumns = false; if ((this.gridView.Columns[0] is TemplateField && this.gridView.Columns.Count == 1) || this.gridView.Columns.Count == 0) { List<string> colName = new List<string>(); List<string> headText = new List<string>(); List<int> width = new List<int>(); string[] columns = this.Columns.Split(';'); int i = columns.Length; for (int j = 0; j < i; j++) { string[] colparams = columns[j].Split(','); if (colparams.Length > 3) { colName.Add(colparams[0]); headText.Add(colparams[1]); width.Add(Convert.ToInt32(colparams[2])); } } int m = colName.Count; for (int n = 0; n < m; n++) { BoundField field = new BoundField(); field.DataField = colName[n]; field.HeaderText = headText[n]; field.HeaderStyle.Width = width[n]; this.gridView.Columns.Add(field); } } } this.gridView.DataSource = (DataSet)this.ViewState["WebDataSet"]; this.gridView.DataMember = ((DataSet)this.ViewState["WebDataSet"]).Tables[0].TableName; this.gridView.DataBind(); // get dd... string CaptionNum = "CAPTION"; if (string.Compare(MultiLan, "true", true) == 0)//IgnoreCase { switch (CliUtils.fClientLang) { case SYS_LANGUAGE.ENG: CaptionNum = "CAPTION1"; break; case SYS_LANGUAGE.TRA: CaptionNum = "CAPTION2"; break; case SYS_LANGUAGE.SIM: CaptionNum = "CAPTION3"; break; case SYS_LANGUAGE.HKG: CaptionNum = "CAPTION4"; break; case SYS_LANGUAGE.JPN: CaptionNum = "CAPTION5"; break; case SYS_LANGUAGE.LAN1: CaptionNum = "CAPTION6"; break; case SYS_LANGUAGE.LAN2: CaptionNum = "CAPTION7"; break; case SYS_LANGUAGE.LAN3: CaptionNum = "CAPTION8"; break; } } DataSet ds = GetDD(); if (ds.Tables.Count != 0 && this.gridView.HeaderRow != null) { foreach (TableCell cell in this.gridView.HeaderRow.Cells) { if (cell.Text != null && cell.Text != "") { int x = ds.Tables[0].Rows.Count; for (int y = 0; y < x; y++) { if (string.Compare(ds.Tables[0].Rows[y]["FIELD_NAME"].ToString(), cell.Text, true) == 0//IgnoreCase && ds.Tables[0].Rows[y][CaptionNum].ToString() != "") { cell.Text = ds.Tables[0].Rows[y][CaptionNum].ToString(); } } } } } //Save HeadTexts HeadTexts = ""; foreach (DataColumn field in ((DataSet)this.ViewState["WebDataSet"]).Tables[0].Columns) { bool ddFound = false; foreach (DataRow row in ds.Tables[0].Rows) { if (string.Compare(field.ColumnName, row["FIELD_NAME"].ToString(), true) == 0//IgnoreCase && row[CaptionNum] != null && row[CaptionNum].ToString() != "") { HeadTexts += row[CaptionNum].ToString() + ";"; ddFound = true; break; } } if (!ddFound) { HeadTexts += field.ColumnName + ";"; } } }
private string GetRemoteName(string filePath, string webDataSetID) { string Rem = ""; XmlDocument xmlDoc = new XmlDocument(); string resxFile = string.IsNullOrEmpty(Resx) ? GetResxFile(filePath) : Resx; ResXResourceReader reader = new ResXResourceReader(resxFile); IDictionaryEnumerator enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Key.ToString() == "WebDataSets") { string sXml = (string)enumerator.Value; xmlDoc.LoadXml(sXml); break; } } if (xmlDoc != null) { XmlNode nWDSs = xmlDoc.SelectSingleNode("WebDataSets"); if (nWDSs != null) { XmlNode nWDS = nWDSs.SelectSingleNode("WebDataSet[@Name='" + webDataSetID + "']"); if (nWDS != null) { XmlNode nRemoteName = nWDS.SelectSingleNode("RemoteName"); if (nRemoteName != null) Rem = nRemoteName.InnerText; } } } return Rem; }
/// <remarks> /// Builds ResAsm files out of resource files /// </remarks> static void Disassemble(string pattern) { string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), pattern); foreach (string file in files) { Hashtable resources = new Hashtable(); int length = 0; // read resource files into the hashtable switch (Path.GetExtension(file).ToUpper()) { case ".RESX": ResXResourceReader rx = new ResXResourceReader(file); IDictionaryEnumerator n = rx.GetEnumerator(); while (n.MoveNext()) if (!resources.ContainsKey(n.Key)) { length = Math.Max(length, n.Key.ToString().Length); resources.Add(n.Key, n.Value); } rx.Close(); break; case ".RESOURCES": ResourceReader rr = new ResourceReader(file); foreach (DictionaryEntry entry in rr) { if (!resources.ContainsKey(entry.Key)) { length = Math.Max(length, entry.Key.ToString().Length); resources.Add(entry.Key, entry.Value); } } rr.Close(); break; } // write the hashtable to the resource file string fname = Path.GetFileNameWithoutExtension(file); string path = fname + "-data"; StreamWriter writer = File.CreateText(fname + ".res"); writer.Write("# this file was automatically generated by ResAsm\r\n\r\n"); foreach (DictionaryEntry entry in resources) { // strings are put directly into the resasm format if (entry.Value is string) { writer.Write(entry.Key.ToString() + "=\"" + ConvertIllegalChars(entry.Value.ToString()) + "\"\r\n"); } else { // all other files are referenced as a file and the filename // is saved in the resasm format, the files need to be generated. string extension = ""; string outputname = path + '\\' + entry.Key.ToString(); if (entry.Value is Icon) { extension = ".ico"; if (!Directory.Exists(path)) Directory.CreateDirectory(path); ((Icon)entry.Value).Save(File.Create(outputname + extension)); } else if (entry.Value is Image) { // all bitmaps are saved in the png format extension = ".png"; if (!Directory.Exists(path)) Directory.CreateDirectory(path); ((Image)entry.Value).Save(outputname + extension, ImageFormat.Png); } else { Console.WriteLine("can't save " + entry.Key + " unknown format."); continue; } writer.Write(entry.Key.ToString().PadRight(length) + " = " + outputname + extension + "\r\n"); } } writer.Close(); } }
private void CreatDataSet(string[] datasetid) { int datasetnum = 0; foreach (string strdsid in datasetid) { if (strdsid != string.Empty) { datasetnum++; } } if (datasetnum > 0) { refValDateSet = new WebDataSet[datasetnum]; refValDateSource = new WebDataSource[datasetnum]; int intcount = 0; for (int i = 0; i < datasetid.Length; i++) { if (datasetid[i] != string.Empty && (!lstDataSetID.Contains(datasetid[i]))) { #region Create WebDataSet & WebDataSource XmlDocument xmlDoc = new XmlDocument(); string resourceName = psyPath + ".vi-VN.resx"; ResXResourceReader reader = new ResXResourceReader(resourceName); IDictionaryEnumerator enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Key.ToString() == "WebDataSets") { string sXml = (string)enumerator.Value; xmlDoc.LoadXml(sXml); break; } } if (xmlDoc != null) { XmlNode nWDSs = xmlDoc.SelectSingleNode("WebDataSets"); if (nWDSs != null) { XmlNode nWDS = nWDSs.SelectSingleNode("WebDataSet[@Name='" + datasetid[i] + "']"); if (nWDS != null) { string remoteName = ""; int packetRecords = 100; bool active = false; bool serverModify = false; XmlNode nRemoteName = nWDS.SelectSingleNode("RemoteName"); if (nRemoteName != null) remoteName = nRemoteName.InnerText; XmlNode nPacketRecords = nWDS.SelectSingleNode("PacketRecords"); if (nPacketRecords != null) packetRecords = nPacketRecords.InnerText.Length == 0 ? 100 : Convert.ToInt32(nPacketRecords.InnerText); XmlNode nActive = nWDS.SelectSingleNode("Active"); if (nActive != null) active = nActive.InnerText.Length == 0 ? false : Convert.ToBoolean(nActive.InnerText); XmlNode nServerModify = nWDS.SelectSingleNode("ServerModify"); if (nServerModify != null) serverModify = nServerModify.InnerText.Length == 0 ? false : Convert.ToBoolean(nServerModify.InnerText); WebDataSet wds = new WebDataSet(); wds.RemoteName = remoteName; wds.PacketRecords = packetRecords; wds.ServerModify = serverModify; wds.Active = true; refValDateSet[intcount] = wds; refValDateSource[intcount] = new WebDataSource(); refValDateSource[intcount].DataSource = refValDateSet[intcount]; refValDateSource[intcount].DataMember = arrRefValDM[i]; refValDateSource[intcount].ID = "refvalds" + intcount.ToString(); ; this.Form.Controls.Add(refValDateSource[intcount]); intcount++; lstDataSetID.Add(datasetid[i]); } } } #endregion } } } }
private void CreatDataSet(object datasetid) { XmlDocument xmlDoc = new XmlDocument(); string resourceName = psyPath + ".vi-VN.resx"; ResXResourceReader reader = new ResXResourceReader(resourceName); IDictionaryEnumerator enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Key.ToString() == "WebDataSets") { string sXml = (string)enumerator.Value; xmlDoc.LoadXml(sXml); break; } } if (xmlDoc != null) { XmlNode nWDSs = xmlDoc.SelectSingleNode("WebDataSets"); if (nWDSs != null) { XmlNode nWDS = nWDSs.SelectSingleNode("WebDataSet[@Name='" + datasetid + "']"); if (nWDS != null) { string remoteName = ""; int packetRecords = 100; bool active = false; bool serverModify = false; XmlNode nRemoteName = nWDS.SelectSingleNode("RemoteName"); if (nRemoteName != null) remoteName = nRemoteName.InnerText; XmlNode nPacketRecords = nWDS.SelectSingleNode("PacketRecords"); if (nPacketRecords != null) packetRecords = nPacketRecords.InnerText.Length == 0 ? 100 : Convert.ToInt32(nPacketRecords.InnerText); XmlNode nActive = nWDS.SelectSingleNode("Active"); if (nActive != null) active = nActive.InnerText.Length == 0 ? false : Convert.ToBoolean(nActive.InnerText); XmlNode nServerModify = nWDS.SelectSingleNode("ServerModify"); if (nServerModify != null) serverModify = nServerModify.InnerText.Length == 0 ? false : Convert.ToBoolean(nServerModify.InnerText); WebDataSet wds = new WebDataSet(); wds.RemoteName = remoteName; wds.PacketRecords = packetRecords; wds.ServerModify = serverModify; wds.Active = true; wdsDay = wds; if (strWhere != string.Empty) { wdsDay.SetWhere(strWhere); } } } } }
private void GetData(string filter) { #region CreateWebDataSet XmlDocument xmlDoc = new XmlDocument(); string resourceName = this.ViewState["ResxPath"].ToString(); ResXResourceReader reader = new ResXResourceReader(resourceName); IDictionaryEnumerator enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Key.ToString() == "WebDataSets") { string sXml = (string)enumerator.Value; xmlDoc.LoadXml(sXml); break; } } if (xmlDoc != null) { XmlNode nWDSs = xmlDoc.SelectSingleNode("WebDataSets"); if (nWDSs != null) { string webDataSetID = this.ViewState["DataSet"].ToString(); XmlNode nWDS = nWDSs.SelectSingleNode("WebDataSet[@Name='" + webDataSetID + "']"); if (nWDS != null) { string remoteName = ""; bool active = false; bool serverModify = false; XmlNode nRemoteName = nWDS.SelectSingleNode("RemoteName"); if (nRemoteName != null) remoteName = nRemoteName.InnerText; XmlNode nActive = nWDS.SelectSingleNode("Active"); if (nActive != null) active = nActive.InnerText.Length == 0 ? false : Convert.ToBoolean(nActive.InnerText); XmlNode nServerModify = nWDS.SelectSingleNode("ServerModify"); if (nServerModify != null) serverModify = nServerModify.InnerText.Length == 0 ? false : Convert.ToBoolean(nServerModify.InnerText); wds.RemoteName = remoteName; this.ViewState["RemoteName"] = remoteName; wds.PacketRecords = -1; wds.ServerModify = serverModify; if (Request.QueryString["WhereStr"] != null) { wds.WhereStr = Request.QueryString["WhereStr"]; } if (!string.IsNullOrEmpty(filter)) { if (string.IsNullOrEmpty(wds.WhereStr)) { wds.WhereStr = filter; } else { wds.WhereStr += string.Format(" and {0}", filter); } } wds.Active = true; this.ViewState["WebDataSet"] = wds.RealDataSet; //绑定list this.ListBox1.DataSource = (DataSet)this.ViewState["WebDataSet"]; this.ListBox1.DataMember = ((DataSet)this.ViewState["WebDataSet"]).Tables[0].TableName; this.ListBox1.DataTextField = this.ViewState["TextField"].ToString(); this.ListBox1.DataValueField = this.ViewState["ValueField"].ToString(); this.ListBox1.DataBind(); if (this.ViewState["Value"] != null && this.ViewState["Value"].ToString() != "" && this.ViewState["Separator"] != null && this.ViewState["Separator"].ToString() != "") { string value = this.ViewState["Value"].ToString(); char sepa = this.ViewState["Separator"].ToString()[0]; string[] lstValues = value.Split(sepa); List<ListItem> selItem = new List<ListItem>(); foreach (string val in lstValues) { ListItem item = this.ListBox1.Items.FindByValue(val); if (item != null) { selItem.Add(item); this.ListBox1.Items.Remove(item); } } foreach (ListItem item in selItem) { this.ListBox2.Items.Add(item); } } } else { string sql = this.ViewState["SelectCommand"].ToString(); if (!string.IsNullOrEmpty(filter)) { sql = CliUtils.InsertWhere(sql, filter); } DataSet temp = CliUtils.ExecuteSql("GLModule", "cmdRefValUse", sql, true, CliUtils.fCurrentProject); this.ListBox1.DataSource = temp; this.ListBox1.DataMember = temp.Tables[0].TableName; this.ListBox1.DataTextField = this.ViewState["TextField"].ToString(); this.ListBox1.DataValueField = this.ViewState["ValueField"].ToString(); this.ListBox1.DataBind(); if (this.ViewState["Value"] != null && this.ViewState["Value"].ToString() != "" && this.ViewState["Separator"] != null && this.ViewState["Separator"].ToString() != "") { string value = this.ViewState["Value"].ToString(); char sepa = this.ViewState["Separator"].ToString()[0]; string[] lstValues = value.Split(sepa); List<ListItem> selItem = new List<ListItem>(); foreach (string val in lstValues) { ListItem item = this.ListBox1.Items.FindByValue(val); if (item != null) { selItem.Add(item); this.ListBox1.Items.Remove(item); } } foreach (ListItem item in selItem) { this.ListBox2.Items.Add(item); } } } } } #endregion }
private void CreatDataSet(String datasetid) { wdAnyQuery = new WebDataSet(); wdsAnyQuery = new WebDataSource(); if (datasetid != string.Empty && (!lstDataSetID.Contains(datasetid))) { #region Create WebDataSet & WebDataSource XmlDocument xmlDoc = new XmlDocument(); string resourceName = psyPagePath + ".vi-VN.resx"; ResXResourceReader reader = new ResXResourceReader(resourceName); IDictionaryEnumerator enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Key.ToString() == "WebDataSets") { string sXml = (string)enumerator.Value; xmlDoc.LoadXml(sXml); break; } } if (xmlDoc != null) { XmlNode nWDSs = xmlDoc.SelectSingleNode("WebDataSets"); if (nWDSs != null) { XmlNode nWDS = nWDSs.SelectSingleNode("WebDataSet[@Name='" + datasetid + "']"); if (nWDS != null) { string remoteName = ""; int packetRecords = 100; bool active = false; bool serverModify = false; XmlNode nRemoteName = nWDS.SelectSingleNode("RemoteName"); if (nRemoteName != null) remoteName = nRemoteName.InnerText; XmlNode nPacketRecords = nWDS.SelectSingleNode("PacketRecords"); if (nPacketRecords != null) packetRecords = nPacketRecords.InnerText.Length == 0 ? 100 : Convert.ToInt32(nPacketRecords.InnerText); XmlNode nActive = nWDS.SelectSingleNode("Active"); if (nActive != null) active = nActive.InnerText.Length == 0 ? false : Convert.ToBoolean(nActive.InnerText); XmlNode nServerModify = nWDS.SelectSingleNode("ServerModify"); if (nServerModify != null) serverModify = nServerModify.InnerText.Length == 0 ? false : Convert.ToBoolean(nServerModify.InnerText); wdAnyQuery.RemoteName = remoteName; wdAnyQuery.PacketRecords = packetRecords; wdAnyQuery.ServerModify = serverModify; wdAnyQuery.Active = true; wdsAnyQuery = new WebDataSource(); wdsAnyQuery.ID = "webanyqueryds"; wdsAnyQuery.DesignDataSet = wdAnyQuery.RealDataSet; wdsAnyQuery.DataMember = dataMember; this.Form.Controls.Add(wdsAnyQuery); //lstDataSetID.Add(datasetid); } } } #endregion } }
static bool LoadStrings (List<Tuple<string, string, string>> resourcesStrings, List<string> files) { var keys = new Dictionary<string, string> (); foreach (var fileName in files) { if (!File.Exists (fileName)) { Console.Error.WriteLine ($"Error reading resource file '{fileName}'"); return false; } var rr = new ResXResourceReader (fileName); rr.UseResXDataNodes = true; var dict = rr.GetEnumerator (); while (dict.MoveNext ()) { var node = (ResXDataNode)dict.Value; resourcesStrings.Add (Tuple.Create (node.Name, (string) node.GetValue ((ITypeResolutionService)null), node.Comment)); } } return true; }
private void CreatDataSet(string datasetid) { XmlDocument xmlDoc = new XmlDocument(); string resourceName = psyPath + ".vi-VN.resx"; ResXResourceReader reader = new ResXResourceReader(resourceName); IDictionaryEnumerator enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Key.ToString() == "WebDataSets") { string sXml = (string)enumerator.Value; xmlDoc.LoadXml(sXml); break; } } if (xmlDoc != null) { XmlNode nWDSs = xmlDoc.SelectSingleNode("WebDataSets"); if (nWDSs != null) { XmlNode nWDS = nWDSs.SelectSingleNode("WebDataSet[@Name='" + datasetid + "']"); if (nWDS != null) { string remoteName = ""; int packetRecords = 100; bool active = false; bool serverModify = false; XmlNode nRemoteName = nWDS.SelectSingleNode("RemoteName"); if (nRemoteName != null) remoteName = nRemoteName.InnerText; XmlNode nPacketRecords = nWDS.SelectSingleNode("PacketRecords"); if (nPacketRecords != null) packetRecords = nPacketRecords.InnerText.Length == 0 ? 100 : Convert.ToInt32(nPacketRecords.InnerText); XmlNode nActive = nWDS.SelectSingleNode("Active"); if (nActive != null) active = nActive.InnerText.Length == 0 ? false : Convert.ToBoolean(nActive.InnerText); XmlNode nServerModify = nWDS.SelectSingleNode("ServerModify"); if (nServerModify != null) serverModify = nServerModify.InnerText.Length == 0 ? false : Convert.ToBoolean(nServerModify.InnerText); WebDataSet wds = new WebDataSet(); wds.RemoteName = remoteName; wds.PacketRecords = packetRecords; wds.ServerModify = serverModify; wds.Active = true; dt = wds.RealDataSet.Tables[dataMember]; int rowcount = dt.Rows.Count; lstnode = new ListItem[rowcount]; for (int i = 0; i < rowcount; i++) { lstnode[i] = new ListItem(); lstnode[i].Text = dt.Rows[i][strTextField].ToString(); lstnode[i].Value = dt.Rows[i][strKeyField].ToString(); lstkey.Add(dt.Rows[i][strKeyField]); } } } } }