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 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(); } } }
protected override IResourceReader GetResourceReader(Stream inputStream) { ResXResourceReader reader = new ResXResourceReader(inputStream); string path = HostingEnvironment.MapPath(base.VirtualPath); reader.BasePath = Path.GetDirectoryName(path); return reader; }
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 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 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 override bool Execute() { try { _resourcesName = "FxResources." + AssemblyName; using (_resxReader = new ResXResourceReader(ResxFilePath)) { using (_targetStream = File.CreateText(OutputSourceFilePath)) { if (String.Equals(Path.GetExtension(OutputSourceFilePath), ".vb", StringComparison.OrdinalIgnoreCase)) { _targetLanguage = TargetLanguage.VB; } _keys = new Dictionary<string, int>(); WriteClassHeader(); RunOnResFile(); WriteDebugCode(); WriteGetTypeProperty(); WriteClassEnd(); WriteResourceTypeClass(); } } } catch (Exception e) { Log.LogError("Failed to generate the resource code with error:\n" + e.Message); return false; // fail the task } return true; }
/// <summary> /// Build .resx file to .resource /// </summary> /// <param name="input"></param> /// <param name="output"></param> public static void Build(string input) { var resxs = Directory.GetFiles(input, "*.resx"); foreach (var resxFile in resxs) { var binFile = Path.GetDirectoryName(resxFile) +"\\"+ Path.GetFileNameWithoutExtension(resxFile) + ".resources"; if (File.Exists(binFile)) { var resxFileInfo = new FileInfo(resxFile); var binFileInfo = new FileInfo(binFile); if (resxFileInfo.LastWriteTime > binFileInfo.LastWriteTime) File.Delete(binFile); //Re-complied } if (!File.Exists(binFile)) { using (var reader = new ResXResourceReader(resxFile)) { using (var writer = new ResourceWriter(binFile)) { foreach (DictionaryEntry d in reader) { writer.AddResource(d.Key.ToString(), d.Value); } } } } } }
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 ResourceHandler(string fileName) { Resources = new List<ResXDataNode> (); using (var reader = new ResXResourceReader (fileName) { UseResXDataNodes = true }) { LoadResources (reader); } }
void LoadResources(ResXResourceReader resxReader) { IDictionaryEnumerator enumerator = resxReader.GetEnumerator (); while (enumerator.MoveNext ()) { Resources.Add (enumerator.Value as ResXDataNode); } }
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 Init_ResourceCache() { string resourceFolder = HttpContext.Current.Server.MapPath("~/App_GlobalResources"); var dir = new DirectoryInfo(resourceFolder); var files = dir.GetFiles(); for (int i = 0; i < files.Length; i++) { var file = files[i]; string extension = Path.GetExtension(file.FullName).ToLower(); if (extension == C_ResourceFileExtension) { string dicKey = file.Name.ToLower(); Dictionary<string,string> resourceItems =new Dictionary<string, string>(); using (var reader = new ResXResourceReader(file.FullName)) { foreach (DictionaryEntry item in reader) { var val = item.Value == null ? string.Empty : item.Value.ToString(); resourceItems.Add(item.Key.ToString(), val); } } cacheLangResources.Add(dicKey, resourceItems); } } }
/// <include file='doc\ResXResourceReader.uex' path='docs/doc[@for="ResXResourceReader.FromFileContents1"]/*' /> /// <internalonly/> /// <devdoc> /// Creates a reader with the specified file contents. /// </devdoc> public static ResXResourceReader FromFileContents(string fileContents, AssemblyName[] assemblyNames) { ResXResourceReader result = new ResXResourceReader(assemblyNames); result.fileContents = fileContents; return(result); }
public void UpdateResxWithChanges(string newResxPath) { var newFile = new FileInfo(newResxPath); if (newFile.Exists) newFile.Delete(); var addedKeys = _resourcesAdded.Select(pair => pair.Key); var removedKeys = _resourcesRemoved.Select(pair => pair.Key); using(var reader = new ResXResourceReader(_sourceResxPath)) using(var writer = new ResXResourceWriter(newResxPath)) { foreach (DictionaryEntry resourceEntry in reader) { string currentKey = (string)resourceEntry.Key; if (addedKeys.Contains(currentKey)) continue; if (removedKeys.Contains(currentKey)) continue; var modifiedResource = _resourcesModified.FirstOrDefault(mod => mod.ResourceName == currentKey); if (modifiedResource != null) writer.AddResource(currentKey, modifiedResource.NewValue); else writer.AddResource(currentKey, resourceEntry.Value); } _resourcesAdded.ForEach(res => writer.AddResource(res.Key, res.Value)); } }
/// <include file='doc\ResXResourceReader.uex' path='docs/doc[@for="ResXResourceReader.FromFileContents1"]/*' /> /// <internalonly/> /// <devdoc> /// Creates a reader with the specified file contents. /// </devdoc> public static ResXResourceReader FromFileContents(string fileContents, ITypeResolutionService typeResolver) { ResXResourceReader result = new ResXResourceReader(typeResolver); result.fileContents = fileContents; return(result); }
/// <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 ResXViewForm(string fileName) { const int BASEWIDTH = 1000; const int BASEHEIGHT = 250; ClientSize = new Size((BASEWIDTH + 20), BASEHEIGHT + 100); resxFile = new FileInfo(fileName); using (var resxSet = new ResXResourceSet(resxFile.FullName)) { Text = resxSet.GetString("FormTitle"); Icon = (Icon)resxSet.GetObject("ShieldIcon"); } const int margin = 10; var resList = new ListView { Bounds = new Rectangle(new Point(margin, margin), new Size(BASEWIDTH, BASEHEIGHT)), View = View.Details, GridLines = true, }; var columnWidth = (resList.ClientSize.Width / 3); resList.Columns.Add("Resource Name", columnWidth); resList.Columns.Add("Type", columnWidth); resList.Columns.Add("Value", columnWidth); using (var resxReader = new ResXResourceReader(resxFile.FullName)) { foreach (DictionaryEntry entry in resxReader) { var resItem = new ListViewItem((string)entry.Key); resItem.SubItems.Add(entry.Value.GetType().FullName); resItem.SubItems.Add(entry.Value.ToString()); resList.Items.Add(resItem); } } var resxButton = new Button { Text = "Show ResX", Location = new Point(resList.Bounds.Left, resList.Bounds.Bottom + margin) }; resxButton.Click += (sender, args) => Process.Start("Notepad.exe", resxFile.FullName); var exitButton = new Button { Text = "Exit" }; exitButton.Location = new Point(resList.Bounds.Right - exitButton.Width, resList.Bounds.Bottom + margin); exitButton.Click += (sender, args) => Application.Exit(); FormBorderStyle = FormBorderStyle.Sizable; MaximizeBox = true; MinimizeBox = false; StartPosition = FormStartPosition.CenterScreen; Controls.Add(resList); Controls.Add(resxButton); Controls.Add(exitButton); InitializeComponent(); }
public override IEnumerable<ILocalizationUnit> Parse () { foreach (var path in resx_paths) { var reader = new ResXResourceReader(path) { UseResXDataNodes = true }; foreach (DictionaryEntry item in reader) { var name = (string)item.Key; var node = (ResXDataNode)item.Value; var localized_string = new LocalizedString { Name = name, DeveloperComments = node.Comment, UntranslatedSingularValue = name, TranslatedValues = new string [] {(string)node.GetValue(null as ITypeResolutionService) } }; for (int i = 0; i < localized_string.TranslatedValues.Length; i++) { var s = localized_string.TranslatedValues [i]; s = s.Replace ("\r", ""); localized_string.TranslatedValues[i] = s; } yield return localized_string; } } yield break; }
public LocalizationMessageProvider(string pluginName) { string path = ""; //NOTE: Modified by [email protected] original is at revision 1668 try { path = HttpContext.Current.Server.MapPath("/").Replace("IUDICO.LMS", "IUDICO." + pluginName); } catch(Exception exception) { path = Assembly.GetExecutingAssembly().CodeBase; path = Path.GetDirectoryName(path); path = Path.GetDirectoryName(path); path = Path.GetDirectoryName(path); path = Path.GetDirectoryName(path); path = Path.Combine(path, "IUDICO.LMS"); path=path.Replace("IUDICO.LMS", "IUDICO." + pluginName); path = path.Remove(0, 6); path += @"\"; } //NOTE: End of modifiation from revision 1668 foreach (var culture in cultures) { var rsxr = new ResXResourceReader(path + "Resource." + culture + ".resx"); Dictionary<string, string> temp = new Dictionary<string, string>(); foreach (DictionaryEntry d in rsxr) { temp.Add(d.Key.ToString(), d.Value.ToString()); } resource.Add(culture, temp); } }
/// <summary> /// get all the values from the resource file /// </summary> /// <param name="path"></param> /// <param name="moduleName"></param> /// <returns></returns> public static List<ResourceData> GetResourceData(string path, string moduleName) { List<ResourceData> resourceData = new List<ResourceData>(); string defaultLanguagePath = GetResourceFilePath(moduleName, "en-IN"); if (File.Exists(path)) { ResXResourceReader reader = new ResXResourceReader(path); if (reader != null) { IDictionaryEnumerator id = reader.GetEnumerator(); foreach (DictionaryEntry d in reader) { resourceData.Add(new ResourceData { Key = d.Key.ToString(), Value = GetResourceDataByKey(defaultLanguagePath, d.Key.ToString()).Value, NewValue = d.Value.ToString(), ModuleName = moduleName }); } reader.Close(); } } return resourceData; }
protected void LoadResource(string pluginName) { string path; try { path = HttpContext.Current.Server.MapPath("/").Replace("IUDICO.LMS", pluginName); } catch (Exception) { path = Path.Combine(Assembly.GetExecutingAssembly().CodeBase.Remove(0, 8) + @"\..\..\..\..\", pluginName) + @"\"; } this.resource.Add(pluginName, new Dictionary<string, Dictionary<string, string>>()); foreach (var culture in Cultures) { try { var resourceReader = new ResXResourceReader(path + "Resource." + culture + ".resx"); var resourceEntries = resourceReader.Cast<DictionaryEntry>().ToDictionary(d => d.Key.ToString(), d => d.Value.ToString()); this.resource[pluginName].Add(culture, resourceEntries); } catch (Exception) { } } }
public void TestWriter01() { List<ILocanRow> expectedValues = new List<ILocanRow> { new LocanRow(id:"Key01",translatedString:"Value01"), new LocanRow(id:"Key02",translatedString:"Value02"), new LocanRow(id:"Key03",translatedString:"Value03"), }; string filepath = this.GetTempFilename(true, ".resx"); using (ResxFileLocanWriter writer = new ResxFileLocanWriter(filepath)) { writer.WriteRows(expectedValues); } // now we need to read that file using (ResXResourceReader reader = new ResXResourceReader(filepath)) { int currentIndex = 0; foreach (DictionaryEntry de in reader) { string expectedKey = expectedValues[currentIndex].Id; string expectedValue = expectedValues[currentIndex].TranslatedString; Assert.AreEqual(expectedKey, de.Key); Assert.AreEqual(expectedValue, de.Value); currentIndex++; } } }
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"); }
/// <summary> /// 加载配置数据.如果加载失败,将抛异常 /// </summary> public void LoadConfig() { SecurityOpr secOpr = new SecurityOpr(GlobalVar.Instanse.SecurityKey); string Datas = secOpr.ReadFromFile(m_StrPath); StringReader reader = new StringReader(Datas); using (m_Reader = new ResXResourceReader(reader)) { try { foreach (DictionaryEntry item in m_Reader) m_cfgDatas[item.Key.ToString()] = item.Value; } catch (FileNotFoundException) { } catch (Exception ex) { throw ex; } } //finally //{ // if (m_Reader != null) // m_Reader.Close(); //} }
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(); }
public ResXConfigHandler(string filePath) { // Create a ResXResourceReader for the file items.resx. rsxr = new ResXResourceReader(filePath); // Create an IDictionaryEnumerator to iterate through the resources. rsxr.GetEnumerator(); }
public IEnumerable<ILocanRow> GetRowsTranslated() { this.ResxReader = new ResXResourceReader(this.Filepath); foreach (DictionaryEntry entry in this.ResxReader) { // conver the entry into an ILocanRow ILocanRow row = new LocanRow(Convert.ToString(entry.Key), null, Convert.ToString(entry.Value)); yield return row; } }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { /*context.GenerateCodeDomAsync(item, context.GetOutputFileName(item, ".Designer"), delegate { return GenerateCodeDom(); });*/ string inputFilePath = item.FileName; // Ensure that the generated code will not conflict with an // existing class. if (context.Project != null) { IProjectContent pc = ParserService.GetProjectContent(context.Project); if (pc != null) { IClass existingClass = pc.GetClass(context.OutputNamespace + "." + StronglyTypedResourceBuilder.VerifyResourceName(Path.GetFileNameWithoutExtension(inputFilePath), pc.Language.CodeDomProvider), 0); if (existingClass != null) { if (!IsGeneratedResourceClass(existingClass)) { context.MessageView.AppendLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, ResourceService.GetString("ResourceEditor.ResourceCodeGeneratorTool.ClassConflict"), inputFilePath, existingClass.FullyQualifiedName)); return; } } } } IResourceReader reader; if (string.Equals(Path.GetExtension(inputFilePath), ".resx", StringComparison.OrdinalIgnoreCase)) { reader = new ResXResourceReader(inputFilePath); ((ResXResourceReader)reader).BasePath = Path.GetDirectoryName(inputFilePath); } else { reader = new ResourceReader(inputFilePath); } Hashtable resources = new Hashtable(); foreach (DictionaryEntry de in reader) { resources.Add(de.Key, de.Value); } string[] unmatchable = null; string generatedCodeNamespace = context.OutputNamespace; context.WriteCodeDomToFile( item, context.GetOutputFileName(item, ".Designer"), StronglyTypedResourceBuilder.Create( resources, // resourceList Path.GetFileNameWithoutExtension(inputFilePath), // baseName generatedCodeNamespace, // generatedCodeNamespace context.OutputNamespace, // resourcesNamespace context.Project.LanguageProperties.CodeDomProvider, // codeProvider createInternalClass, // internal class out unmatchable )); foreach (string s in unmatchable) { context.MessageView.AppendLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, ResourceService.GetString("ResourceEditor.ResourceCodeGeneratorTool.CouldNotGenerateResourceProperty"), s)); } }
private static Dictionary<string, string> ReadAllResources(string path) { var dict = new Dictionary<string, string>(); using (var reader = new ResXResourceReader(path)) { foreach (DictionaryEntry item in reader) dict.Add(item.Key.ToString(), item.Value.ToString()); } return dict; }
private static CultureInfo AppendResX(RootCategory root, string file) { CultureInfo locale = GetLocale(file); ResXResourceReader rxrr = new ResXResourceReader(file); foreach (DictionaryEntry de in rxrr) { ResourceItem item = root.GetItem((string)de.Key); item.ValueCollection[locale] = de.Value.ToString(); } return locale; }
public override void Run() { // Here an example that shows how to access the current text document: ITextEditorProvider tecp = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorProvider; if (tecp == null) { // active content is not a text editor control return; } // Get the active text area from the control: ITextEditor textEditor = tecp.TextEditor; if (textEditor.SelectionLength == 0) return; // get the selected text: string text = textEditor.SelectedText; string sdSrcPath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "../../../.."); string resxFile = Path.Combine(sdSrcPath, "../data/Resources/StringResources.resx"); using (ResXResourceReader r = new ResXResourceReader(resxFile)) { IDictionaryEnumerator en = r.GetEnumerator(); // Goes through the enumerator, printing out the key and value pairs. while (en.MoveNext()) { if (object.Equals(en.Value, text)) { SetText(textEditor, en.Key.ToString(), text); return; } } } string resourceName = MessageService.ShowInputBox("Add Resource", "Please enter the name for the new resource.\n" + "This should be a namespace-like construct, please see what the names of resources in the same component are.", PropertyService.Get("ResourceToolLastResourceName")); if (resourceName == null || resourceName.Length == 0) return; PropertyService.Set("ResourceToolLastResourceName", resourceName); string purpose = MessageService.ShowInputBox("Add Resource", "Enter resource purpose (may be empty)", ""); if (purpose == null) return; SetText(textEditor, resourceName, text); string path = Path.GetFullPath(Path.Combine(sdSrcPath, "Tools/StringResourceTool/bin/Debug")); ProcessStartInfo info = new ProcessStartInfo(path + "\\StringResourceTool.exe", "\"" + resourceName + "\" " + "\"" + text + "\" " + "\"" + purpose + "\""); info.WorkingDirectory = path; try { Process.Start(info); } catch (Exception ex) { MessageService.ShowException(ex, "Error starting " + info.FileName); } }
// Constructors. public ResXResourceSet(Stream stream) { Reader = new ResXResourceReader(stream); Table = new Hashtable(); ReadResources(); }
public ResXResourceSet(String fileName) { Reader = new ResXResourceReader(fileName); Table = new Hashtable(); ReadResources(); }