当前位置: 首页>>代码示例>>C#>>正文


C# ResXResourceReader.Close方法代码示例

本文整理汇总了C#中System.Resources.ResXResourceReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceReader.Close方法的具体用法?C# ResXResourceReader.Close怎么用?C# ResXResourceReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Resources.ResXResourceReader的用法示例。


在下文中一共展示了ResXResourceReader.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCustomerCredentials

        /// <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;

            }
        }
开发者ID:hemap,项目名称:PhoenixAutomationRepo,代码行数:40,代码来源:Common.cs

示例2: SaveResxAsTypeScriptFile

        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());
            }
        }
开发者ID:projectkudu,项目名称:AzureFunctionsPortal,代码行数:30,代码来源:ResxConvertor.cs

示例3: InitResource

        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();
                }
            }
        }
开发者ID:Benguan,项目名称:Code,代码行数:25,代码来源:LocalizationHelpers.cs

示例4: TestReader

			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");
			}
开发者ID:nlhepler,项目名称:mono,代码行数:29,代码来源:CompatTest.cs

示例5: getBMPFiles

        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();
        }
开发者ID:Tab3r,项目名称:Tab3r.Utils,代码行数:25,代码来源:myResxFileBMPExtractor.cs

示例6: UpdateResourceFile

        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 !!";
        }
开发者ID:nathanpower,项目名称:resource-translator,代码行数:60,代码来源:Helper.cs

示例7: Test

		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");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:CultureTest.cs

示例8: TranslateFile

        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();
        }
开发者ID:Gevil,项目名称:Projects,代码行数:59,代码来源:Translator.cs

示例9: LoadResource

 /// <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(); 
 }
开发者ID:jordfocus,项目名称:CleRexTool,代码行数:16,代码来源:ResourceFileHandler.cs

示例10: ResXAggregator

        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();
        }
开发者ID:Jeff-Tian,项目名称:ResX-Aggregator,代码行数:52,代码来源:ResXAggregator.cs

示例11: AddDoubleKey

        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();
        }
开发者ID:pitchcontrol,项目名称:Atom,代码行数:17,代码来源:ResourceTests.cs

示例12: AddNewKeyTest

        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();
        }
开发者ID:pitchcontrol,项目名称:Atom,代码行数:19,代码来源:ResourceTests.cs

示例13: UpdateResourceFile

        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();

        }
开发者ID:ericjohnolson,项目名称:NadaNtd,代码行数:41,代码来源:GlobalizationUtil.cs

示例14: addResource

        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();
        }
开发者ID:dotob,项目名称:localizer,代码行数:36,代码来源:LocalizeTools.cs

示例15: Serializable_ITRSUsed

		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 ();
			}
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:24,代码来源:ResXResourceReaderTest.cs


注:本文中的System.Resources.ResXResourceReader.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。