/// <summary> /// To Get the user credentials from Customer Resource file /// </summary> /// Authour: Pradeep /// <param name="custType">Type of the customer</param> /// <returns>returns an array with UserName and Password</returns> /// Created Date: 22-Dec-2011 /// Modified Date: 22-Dec-2011 /// Modification Comments public static string[] GetCustomerCredentials(string custType) { try { Stream stream = new System.IO.FileStream(ResFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); var resFileData = new ResXResourceReader(stream); IDictionaryEnumerator resFileDataDict = resFileData.GetEnumerator(); var customerCreds = new string[2]; while (resFileDataDict.MoveNext()) { if (custType.ToString(CultureInfo.InvariantCulture) == resFileDataDict.Key.ToString()) { string temp = resFileDataDict.Value.ToString(); customerCreds = temp.Split(';'); break; } } resFileData.Close(); stream.Dispose(); return customerCreds; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return null; } }
public void SaveResxAsTypeScriptFile(string[] resxFiles, string outputTSFilePAth) { var sb = new StringBuilder(); sb.AppendLine("// This file is auto generated"); sb.AppendLine(""); sb.AppendLine("export class PortalResources"); sb.AppendLine("{"); foreach (var resxFile in resxFiles) { if (File.Exists(resxFile)) { ResXResourceReader rsxr = new ResXResourceReader(resxFile); foreach (DictionaryEntry d in rsxr) { sb.AppendLine(string.Format(" public static {0}: string = \"{0}\";", d.Key.ToString())); } //Close the reader. rsxr.Close(); } } sb.AppendLine("}"); using (System.IO.StreamWriter file = new System.IO.StreamWriter(outputTSFilePAth)) { file.WriteLine(sb.ToString()); } }
public static void InitResource() { string path = HttpContext.Current.Server.MapPath("/") + "Resource\\"; foreach (string lang in LangList) { ResXResourceReader reader = new ResXResourceReader(path + lang + ".resx"); try { foreach (DictionaryEntry d in reader) { dataCollection.Add(new KeyValuePair<string, string>(AssmbleKey(d.Key.ToString(), lang), d.Value.ToString())); } } catch (Exception ex) { throw ex; } finally { reader.Close(); } } }
public static void TestReader (string fileName) { ResXResourceReader r = new ResXResourceReader (fileName); Hashtable h = new Hashtable (); foreach (DictionaryEntry e in r) { h.Add (e.Key, e.Value); } r.Close (); Assert.AreEqual ("hola", (string) h ["String"], fileName + "#1"); Assert.AreEqual ("hello", (string) h ["String2"], fileName + "#2"); Assert.AreEqual (42, (int) h ["Int"], fileName + "#3"); Assert.AreEqual (PlatformID.Win32NT, (PlatformID) h ["Enum"], fileName + "#4"); Assert.AreEqual (43, ((Point) h ["Convertible"]).X, fileName + "#5"); Assert.AreEqual (2, (byte) ((ArrayList) h ["Serializable"]) [1], fileName + "#6"); Assert.AreEqual (13, ((byte []) h ["ByteArray"]) [1], fileName + "#7"); Assert.AreEqual (16, ((byte []) h ["ByteArray2"]) [1], fileName + "#8"); Assert.AreEqual (1013, ((int []) h ["IntArray"]) [1], fileName + "#9"); Assert.AreEqual ("world", ((string []) h ["StringArray"]) [1], fileName + "#10"); #if NET_2_0 Assert.IsNull (h ["InvalidMimeType"], "#11"); #else Assert.IsNotNull (h ["InvalidMimeType"], "#11a"); Assert.AreEqual ("AAEAAAD/////AQAAAAAAAAARAQAAAAIAAAAGAgAAAAVoZWxsbwYDAAAABXdvcmxkCw==", h ["InvalidMimeType"], "#11b"); #endif Assert.IsNotNull (h ["Image"], fileName + "#12"); Assert.AreEqual (typeof (Bitmap), h ["Image"].GetType (), fileName + "#13"); }
public static void getBMPFiles(string resxFile) { // Create a Resource Reader ResXResourceReader rsxr = new ResXResourceReader(resxFile); // Create a enumerator IDictionaryEnumerator id = rsxr.GetEnumerator(); int i = 0; foreach (DictionaryEntry d in rsxr) { Bitmap b = d.Value as Bitmap; if (b != null) { b.Save(resxFile + "__" + i.ToString() + ".bmp"); i++; } } //Close the reader. rsxr.Close(); }
public static void UpdateResourceFile(Hashtable data, string path, TranslatorForm form) { form.TextOutput = "Writing " + path + "..."; Hashtable resourceEntries = new Hashtable(); bool check = false; //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(); } //Modify resources here... foreach (String key in data.Keys) { if (!resourceEntries.ContainsKey(key)) { String value = data[key].ToString(); if (value == null) value = ""; resourceEntries.Add(key, value); } } //Write the combined resource file ResXResourceWriter resourceWriter = new ResXResourceWriter(path); foreach (String key in resourceEntries.Keys) { resourceWriter.AddResource(key, resourceEntries[key]); } resourceWriter.Generate(); resourceWriter.Close(); //Check if entered correctly reader = new ResXResourceReader(path); if (reader != null) { foreach (DictionaryEntry d in reader) foreach (String key in resourceEntries.Keys) { if ((string) d.Key == key && (string) d.Value == (string) resourceEntries[key]) check = true; } reader.Close(); } if (check) form.TextOutput = path + " written successfully"; else form.TextOutput = path + " not written !!"; }
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"); }
private void TranslateFile(string filename, string locale, string newDir) { string shortName = Path.GetFileName(filename); string nameWithoutExt = Path.GetFileNameWithoutExtension(filename); string newname = nameWithoutExt + "." + locale + ".resx"; newname = newDir + "\\" + newname; //if file already exists bool fileExists = File.Exists(newname); Dictionary<string, string> existing = new Dictionary<string, string>(); if (fileExists) { Console.WriteLine("File " + newname + " already exists. Existing resources in it will be preserved."); //get existing keys list ResXResourceReader readerNewFile = new ResXResourceReader(newname); foreach (DictionaryEntry d in readerNewFile) existing.Add(d.Key.ToString(), d.Value.ToString()); readerNewFile.Close(); } else { Console.WriteLine("Creating file " + newname); } Console.WriteLine("Translating file " + shortName + " to " + locale + "...."); Application.DoEvents(); //I know its bad but can't go multithreading, since I have to update UI ResXResourceReader reader = new ResXResourceReader(filename); ResXResourceWriter writer = new ResXResourceWriter(newname); foreach (DictionaryEntry d in reader) { //leave existing text intact (if its not empty) if (fileExists && existing.Keys.Contains(d.Key.ToString()) && !string.IsNullOrEmpty(existing[d.Key.ToString()])) { writer.AddResource(d.Key.ToString(), existing[d.Key.ToString()]); } else { string originalString = d.Value.ToString(); if (!string.IsNullOrEmpty(originalString.Trim())) { string langPair = "hu|" + LanguageNamesList[locale]; //string translatedString = GoogleTranslate.TranslateText(originalString, langPair); string translatedString = GoogleTranslate.TranslateGoogle(originalString, "hu", LanguageNamesList[locale]); Console.WriteLine("[" + originalString + " -> " + translatedString + "]"); writer.AddResource(d.Key.ToString(), translatedString); //Thread.Sleep(100); //to prevent spam detector at google } } } writer.Close(); reader.Close(); }
/// <summary> /// Loads resource file items into class hashtable /// </summary> /// <param name="resourceFilePath">Path to the resource file that we want to load</param> public void LoadResource(string resourceFilePath) { // delete all previous resource items ResourceItems.Clear(); // load the new resource into the hashtable var resourceReader = new ResXResourceReader(resourceFilePath); foreach (DictionaryEntry entry in resourceReader) { ResourceItems.Add(entry.Key.ToString(), entry.Value == null ? string.Empty : entry.Value.ToString()); } resourceReader.Close(); }
public ResXAggregator(string resxAggregatorFullPath) { _myFullPath = resxAggregatorFullPath; var directory = Path.GetDirectoryName(resxAggregatorFullPath); var myName = Path.GetFileNameWithoutExtension(resxAggregatorFullPath); _dictionary = new Dictionary<string, Dictionary<string, string>>(); IList<string> resxFileNames = FileSystemHelper.SearchFileNames(directory, "^{0}(.*).resx$".FormatWith(myName)).ToList(); resxFileNames = resxFileNames.Select(e => Path.Combine(directory, e)).ToList(); foreach (var fileName in resxFileNames) { var culture = Path.GetFileNameWithoutExtension(fileName); if (!culture.StartsWith(myName)) continue; culture = culture.Length > myName.Length ? culture.Substring(myName.Length + 1) : "default"; using (var fileStream = File.OpenRead(fileName)) { using (var resXReader = new ResXResourceReader(fileStream)) { foreach (DictionaryEntry d in resXReader) { var key = d.Key.ToString(); var value = d.Value.ToString(); if (Dictionary.ContainsKey(key)) { if (Dictionary[key].ContainsKey(culture)) { Dictionary[key][culture] = value; } else { Dictionary[key].Add(culture, value); } } else { Dictionary.Add(key, new Dictionary<string, string>() {{culture, value}}); } } resXReader.Close(); } fileStream.Close(); } } GenerateDataTableFromDictionary(); }
public void AddDoubleKey() { PanelViewModel panelViewModel = new PanelViewModel(_model.RootPanel) { RuDescription = "Комент", FieldInDb = "Key1" }; _model.RootPanel.Children.Add(panelViewModel); //Добавляем ключь, должны добавится в оба словаря _model.WriteResourses(); //Проверяем ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath); var dictionary = reader.Cast<DictionaryEntry>(); Assert.AreEqual(1, dictionary.Count()); reader.Close(); reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx")); dictionary = reader.Cast<DictionaryEntry>(); Assert.AreEqual(1, dictionary.Count()); reader.Close(); }
public void AddNewKeyTest() { PanelViewModel panelViewModel = new PanelViewModel(_model.RootPanel) { RuDescription = "Комент", FieldInDb = "Id1" }; _model.RootPanel.Children.Add(panelViewModel); //Добавляем ключь, должны добавится в оба словаря _model.WriteResourses(); //Проверяем ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath); var dictionary = reader.Cast<DictionaryEntry>(); Assert.AreEqual(2, dictionary.Count()); Assert.IsNotNull(dictionary.FirstOrDefault(i => (string) i.Key == "Id1")); reader.Close(); reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx")); dictionary = reader.Cast<DictionaryEntry>(); Assert.AreEqual(2, dictionary.Count()); Assert.IsNotNull(dictionary.FirstOrDefault(i => (string) i.Key == "Id1")); reader.Close(); }
public static void UpdateResourceFile(Hashtable data, String path) { Hashtable resourceEntries = new Hashtable(); //Add all changes... foreach (String key in data.Keys) { String value = data[key].ToString(); if (value == null) value = ""; resourceEntries.Add(key, value); } //Get existing resources ResXResourceReader reader = new ResXResourceReader(path); if (reader != null) { IDictionaryEnumerator id = reader.GetEnumerator(); foreach (DictionaryEntry d in reader) { if (!resourceEntries.ContainsKey(d.Key.ToString())) { if (d.Value == null) resourceEntries.Add(d.Key.ToString(), ""); else resourceEntries.Add(d.Key.ToString(), d.Value.ToString()); } } reader.Close(); } //Write the combined resource file ResXResourceWriter resourceWriter = new ResXResourceWriter(path); foreach (String key in resourceEntries.Keys) { resourceWriter.AddResource(key, resourceEntries[key]); } resourceWriter.Generate(); resourceWriter.Close(); }
public static void addResource(string resxFile, ICollection<LanguageInfo> langCollection, IDictionary<string, LanguageInfo> langDic, LanguageInfo.LANG lang) { var read = new ResXResourceReader(resxFile); IDictionaryEnumerator id = read.GetEnumerator(); foreach (DictionaryEntry d in read) { LanguageInfo li; string ki = d.Key.ToString(); if (!langDic.TryGetValue(ki, out li)) { li = new LanguageInfo(); langCollection.Add(li); langDic.Add(ki, li); } li.ID = ki; switch (lang) { case LanguageInfo.LANG.de: li.de = d.Value.ToString(); break; case LanguageInfo.LANG.en: li.en = d.Value.ToString(); break; case LanguageInfo.LANG.fr: li.fr = d.Value.ToString(); break; case LanguageInfo.LANG.es: li.es = d.Value.ToString(); break; case LanguageInfo.LANG.it: li.it = d.Value.ToString(); break; default: throw new ArgumentOutOfRangeException("lang"); } } read.Close(); }
public void Serializable_ITRSUsed () { serializable ser = new serializable ("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode ("test", ser); StringBuilder sb = new StringBuilder (); using (StringWriter sw = new StringWriter (sb)) { using (ResXResourceWriter writer = new ResXResourceWriter (sw)) { writer.AddResource (dn); } } using (StringReader sr = new StringReader (sb.ToString ())) { ResXResourceReader rr = new ResXResourceReader (sr, new ReturnSerializableSubClassITRS ()); IDictionaryEnumerator en = rr.GetEnumerator (); en.MoveNext (); object o = ((DictionaryEntry) en.Current).Value; Assert.IsNotNull (o, "#A1"); Assert.IsInstanceOfType (typeof (serializableSubClass), o,"#A2"); rr.Close (); } }
public void TypeConverter_ITRSUsed () { ResXDataNode dn = new ResXDataNode ("test", 34L); StringBuilder sb = new StringBuilder (); using (StringWriter sw = new StringWriter (sb)) { using (ResXResourceWriter writer = new ResXResourceWriter (sw)) { writer.AddResource (dn); } } using (StringReader sr = new StringReader (sb.ToString ())) { ResXResourceReader rr = new ResXResourceReader (sr, new ReturnIntITRS ()); IDictionaryEnumerator en = rr.GetEnumerator (); en.MoveNext (); object o = ((DictionaryEntry) en.Current).Value; Assert.IsNotNull (o, "#A1"); Assert.IsInstanceOfType (typeof (int), o,"#A2"); Assert.AreEqual (34, o,"#A3"); rr.Close (); } }
public void Close_Stream () { string fileName = Path.Combine (Path.Combine ("Test", "System.Resources"), "compat_1_1.resx"); if (!File.Exists (fileName)) fileName = String.Format ("..{0}System.Resources{0}compat_1_1.resx", Path.DirectorySeparatorChar); using (FileStream fs = File.OpenRead (fileName)) { ResXResourceReader r = new ResXResourceReader (fs); Assert.AreEqual (0, fs.Position, "#A1"); r.GetEnumerator (); Assert.IsFalse (fs.Position == 0, "#A2"); Assert.IsTrue (fs.CanRead, "#A3"); r.Close (); Assert.IsTrue (fs.CanRead, "#A4"); r.GetEnumerator ().MoveNext (); } using (FileStream fs = File.OpenRead (fileName)) { ResXResourceReader r = new ResXResourceReader (fs); r.Close (); Assert.AreEqual (0, fs.Position, "#B1"); r.GetEnumerator (); Assert.IsFalse (fs.Position == 0, "#B2"); } }
public void Close_Reader () { string fileName = Path.Combine (Path.Combine ("Test", "System.Resources"), "compat_1_1.resx"); if (!File.Exists (fileName)) fileName = String.Format ("..{0}System.Resources{0}compat_1_1.resx", Path.DirectorySeparatorChar); using (StreamReader sr = new StreamReader (fileName)) { ResXResourceReader r = new ResXResourceReader (sr); Assert.IsFalse (sr.Peek () == -1, "#A1"); r.GetEnumerator (); Assert.IsTrue (sr.Peek () == -1, "#A2"); r.Close (); try { sr.Peek (); Assert.Fail ("#A3"); } catch (ObjectDisposedException) { } r.GetEnumerator (); } using (StreamReader sr = new StreamReader (fileName)) { ResXResourceReader r = new ResXResourceReader (sr); r.Close (); try { sr.Peek (); Assert.Fail ("#B1"); } catch (ObjectDisposedException) { } try { r.GetEnumerator (); Assert.Fail ("#B2"); } catch (NullReferenceException) { // MS } catch (InvalidOperationException) { // Mono } } }
public void Close_FileName () { string fileName = Path.Combine (Path.Combine ("Test", "System.Resources"), "compat_1_1.resx"); if (!File.Exists (fileName)) fileName = String.Format ("..{0}System.Resources{0}compat_1_1.resx", Path.DirectorySeparatorChar); ResXResourceReader r1 = new ResXResourceReader (fileName); r1.GetEnumerator (); r1.Close (); r1.GetEnumerator (); ResXResourceReader r2 = new ResXResourceReader (fileName); r2.Close (); r2.GetEnumerator (); r2.Close (); }
private static Dictionary<string, string> getKeyValuePairsFromResxFile(string filePath) { var resourceFileDict = new Dictionary<string, string>(); // NOTE: here we're using ResXResourceReader from System.Windows.Forms var resourceReader = new ResXResourceReader(filePath); try { foreach (DictionaryEntry d in resourceReader) { var key = d.Key as string; if (key != null) { resourceFileDict.Add(key, d.Value.ToString()); } } } finally { resourceReader.Close(); } return resourceFileDict; }
/// <summary> /// Performs the Synchronization of the RESX files. /// </summary> /// <param name="backup">Specifies whether to backup the destination file before modifying it.</param> /// <param name="addOnly">Specifies whether to only add new keys, without removing deleted ones.</param> /// <param name="verbose">Specifies whether to print additional information.</param> /// <param name="added">The number of added keys.</param> /// <param name="removed">The number of removed keys.</param> public void SyncronizeResources(bool backup, bool addOnly, bool verbose, out int added, out int removed) { added = 0; removed = 0; if(backup) { string destDir = Path.GetDirectoryName(destinationFile); string file = Path.GetFileName(destinationFile); File.Copy(destinationFile, destDir + "\\Backup of " + file, true); } string tempFile = Path.GetDirectoryName(destinationFile) + "\\__TempOutput.resx"; // Load files in memory MemoryStream sourceStream = new MemoryStream(), destinationStream = new MemoryStream(); FileStream fs; int read; byte[] buffer = new byte[1024]; fs = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read); read = 0; do { read = fs.Read(buffer, 0, buffer.Length); sourceStream.Write(buffer, 0, read); } while(read > 0); fs.Close(); fs = new FileStream(destinationFile, FileMode.Open, FileAccess.Read, FileShare.Read); read = 0; do { read = fs.Read(buffer, 0, buffer.Length); destinationStream.Write(buffer, 0, read); } while(read > 0); fs.Close(); sourceStream.Position = 0; destinationStream.Position = 0; // Create resource readers ResXResourceReader source = new ResXResourceReader(sourceStream); ResXResourceReader destination = new ResXResourceReader(destinationStream); // Create resource writer if(File.Exists(tempFile)) File.Delete(tempFile); ResXResourceWriter writer = new ResXResourceWriter(tempFile); // Compare source and destination: // for each key in source, check if it is present in destination // if not, add to the output // for each key in destination, check if it is present in source // if so, add it to the output // Find new keys and add them to the output foreach(DictionaryEntry d in source) { bool found = false; foreach(DictionaryEntry dd in destination) { if(d.Key.ToString().Equals(dd.Key.ToString())) { // Found key found = true; break; } } if(!found) { // Add the key writer.AddResource(d.Key.ToString(), d.Value); added++; if(verbose) { Console.WriteLine("Added new key '" + d.Key.ToString() + "' with value '" + d.Value.ToString() + "'\n"); } } } if(addOnly) { foreach(DictionaryEntry d in destination) { writer.AddResource(d.Key.ToString(), d.Value); } } else { int tot = 0; int rem = 0; // Find un-modified keys and add them to the output foreach(DictionaryEntry d in destination) { bool found = false; tot++; foreach(DictionaryEntry dd in source) { if(d.Key.ToString().Equals(dd.Key.ToString())) { // Found key found = true; } } if(found) { writer.AddResource(d.Key.ToString(), d.Value); rem++; } else if(verbose) { Console.WriteLine("Removed deleted key '" + d.Key.ToString() + "' with value '" + d.Value.ToString() + "'\n"); } } removed = tot - rem; } source.Close(); destination.Close(); writer.Close(); // Copy tempFile into destinationFile File.Copy(tempFile, destinationFile, true); File.Delete(tempFile); }
public void LoadResource( ) { OpenFileDialog ofd = new OpenFileDialog( ); ofd.CheckFileExists = true; ofd.Filter = "resx files (*.resx)|*.resx|All files (*.*)|*.*"; if ( last_load_resx_directory != String.Empty ) if ( Directory.Exists( last_load_resx_directory ) ) ofd.InitialDirectory = last_load_resx_directory; if ( DialogResult.OK == ofd.ShowDialog( ) ) { ClearResources( ); resXResourceReader = new ResXResourceReader( ofd.FileName ); Text = Path.GetFileName( ofd.FileName ); fullFileName = ofd.FileName; last_load_resx_directory = Path.GetDirectoryName( ofd.FileName ); number_resources = resourceSelectionControl.LoadResource( resXResourceReader ); resXResourceReader.Close( ); UpdateStatusBar( ); } }
public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_TypeConverter () { ResXDataNode dn = new ResXDataNode ("test", 34L); string resXFile = GetResXFileWithNode (dn,"resx.resx"); ResXResourceReader rr = new ResXResourceReader (resXFile, new ReturnIntITRS ()); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator (); en.MoveNext (); ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode; Assert.IsNotNull (node, "#A1"); object o = node.GetValue ((AssemblyName []) null); Assert.IsInstanceOfType (typeof (long), o, "#A2"); Assert.AreEqual (34L, o, "#A3"); rr.Close (); }
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"); 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 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 void AddRecursiveKey() { PanelViewModel panel1 = new PanelViewModel(_model.RootPanel); panel1.FieldInDb = "fl1"; _model.RootPanel.Children.Add(panel1); PanelViewModel panel2 = new PanelViewModel(panel1); panel2.FieldInDb = "fl2"; panel1.Children.Add(panel2); PanelViewModel panel3 = new PanelViewModel(panel2); panel3.FieldInDb = "fl3"; panel2.Children.Add(panel3); //Добавляем ключь, должны добавится в оба словаря _model.WriteResourses(); //Проверяем ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath); var dictionary = reader.Cast<DictionaryEntry>(); Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl1")); Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl2")); Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl3")); Assert.AreEqual(4, dictionary.Count()); reader.Close(); reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx")); dictionary = reader.Cast<DictionaryEntry>(); Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl1")); Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl2")); Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl3")); Assert.AreEqual(4, dictionary.Count()); reader.Close(); }
public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_Serializable () { serializable ser = new serializable ("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode ("test", ser); string resXFile = GetResXFileWithNode (dn,"resx.resx"); ResXResourceReader rr = new ResXResourceReader (resXFile, new ReturnSerializableSubClassITRS ()); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator (); en.MoveNext (); ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode; Assert.IsNotNull (node, "#A1"); object o = node.GetValue ((AssemblyName []) null); Assert.IsNotInstanceOfType (typeof (serializableSubClass), o, "#A2"); Assert.IsInstanceOfType (typeof (serializable), o, "#A3"); rr.Close (); }
private static void CompileEmbeddedRes(PlgxPluginInfo plgx) { foreach(string strResSrc in plgx.EmbeddedResourceSources) { string strResFileName = plgx.BaseFileName + "." + UrlUtil.ConvertSeparators( UrlUtil.MakeRelativePath(plgx.CsprojFilePath, strResSrc), '.'); string strResFile = UrlUtil.GetFileDirectory(plgx.CsprojFilePath, true, true) + strResFileName; if(strResSrc.EndsWith(".resx", StrUtil.CaseIgnoreCmp)) { PrepareResXFile(strResSrc); string strRsrc = UrlUtil.StripExtension(strResFile) + ".resources"; ResXResourceReader r = new ResXResourceReader(strResSrc); ResourceWriter w = new ResourceWriter(strRsrc); r.BasePath = UrlUtil.GetFileDirectory(strResSrc, false, true); foreach(DictionaryEntry de in r) w.AddResource((string)de.Key, de.Value); w.Generate(); w.Close(); r.Close(); if(File.Exists(strRsrc)) { plgx.CompilerParameters.EmbeddedResources.Add(strRsrc); Program.TempFilesPool.Add(strRsrc); } } else { File.Copy(strResSrc, strResFile, true); plgx.CompilerParameters.EmbeddedResources.Add(strResFile); } } }
public void LoadFile(string filename, Stream stream) { resources.Clear(); metadata.Clear(); switch (Path.GetExtension(filename).ToLowerInvariant()) { case ".resx": ResXResourceReader rx = new ResXResourceReader(stream); rx.BasePath = Path.GetDirectoryName(filename); IDictionaryEnumerator n = rx.GetEnumerator(); while (n.MoveNext()) if (!resources.ContainsKey(n.Key.ToString())) resources.Add(n.Key.ToString(), new ResourceItem(n.Key.ToString(), n.Value)); n = rx.GetMetadataEnumerator(); while (n.MoveNext()) if (!metadata.ContainsKey(n.Key.ToString())) metadata.Add(n.Key.ToString(), new ResourceItem(n.Key.ToString(), n.Value)); rx.Close(); break; case ".resources": ResourceReader rr=null; try { rr = new ResourceReader(stream); foreach (DictionaryEntry entry in rr) { if (!resources.ContainsKey(entry.Key.ToString())) resources.Add(entry.Key.ToString(), new ResourceItem(entry.Key.ToString(), entry.Value)); } } finally { if (rr != null) { rr.Close(); } } break; } InitializeListView(); }
private void CompileResourceFile() { ResXResourceReader resxReader = new ResXResourceReader(ResourcesFilePath); IDictionaryEnumerator resxEnumerator = resxReader.GetEnumerator(); using (IResourceWriter writer = new ResourceWriter(CompiledResourcesFilePath)) { while (resxEnumerator.MoveNext()) { try { writer.AddResource(resxEnumerator.Key.ToString(), resxEnumerator.Value); } catch (Exception ex) { throw new FrameworkException(string.Format("Error while compiling resource file \"{0}\" on key \"{1}\".", ResourcesFileName, resxEnumerator.Key.ToString()), ex); } } writer.Generate(); writer.Close(); } resxReader.Close(); }