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();
        }
示例#2
0
        /// <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;

            }
        }
 void LoadResources(ResXResourceReader resxReader)
 {
     IDictionaryEnumerator enumerator = resxReader.GetEnumerator ();
     while (enumerator.MoveNext ()) {
         Resources.Add (enumerator.Value as ResXDataNode);
     }
 }
示例#4
0
        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 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;
        }
示例#6
0
		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 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();
        }
示例#8
0
		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);
			}
		}
示例#9
0
		protected ResXDataNode GetNodeFromResXReader (string contents)
		{
			StringReader sr = new StringReader (contents);

			using (ResXResourceReader reader = new ResXResourceReader (sr)) {
				reader.UseResXDataNodes = true;
				IDictionaryEnumerator enumerator = reader.GetEnumerator ();
				enumerator.MoveNext ();

				return (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
			}
		}
        public bool KeyExists(FileInfo fileInfo, string key)
        {
            using (reader)
            {
                reader = new ResXResourceReader(fileInfo.FullName);
                var enumerator = reader.GetEnumerator();

                foreach (DictionaryEntry d in reader)
                    if (String.Equals(d.Key.ToString(), key, StringComparison.CurrentCultureIgnoreCase)) return true;

            }
            return false;
        }
		[Test] // ctor (Stream)
		public void Constructor1_Stream_InvalidContent ()
		{
			MemoryStream ms = new MemoryStream ();
			ms.WriteByte (byte.MaxValue);
			ms.Position = 0;
			ResXResourceReader r = new ResXResourceReader (ms);
			try {
				r.GetEnumerator ();
				Assert.Fail ("#1");
			} catch (ArgumentException ex) {
				// Invalid ResX input
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
				Assert.IsNotNull (ex.Message, "#3");
				Assert.IsNull (ex.ParamName, "#4");
				Assert.IsNotNull (ex.InnerException, "#5");
			}
		}
示例#12
0
		protected ResXDataNode GetNodeFromResXReader (ResXDataNode node)
		{
			StringWriter sw = new StringWriter ();
			using (ResXResourceWriter writer = new ResXResourceWriter (sw)) {
				writer.AddResource (node);
			}

			StringReader sr = new StringReader (sw.GetStringBuilder ().ToString ());

			using (ResXResourceReader reader = new ResXResourceReader (sr)) {
				reader.UseResXDataNodes = true;
				IDictionaryEnumerator enumerator = reader.GetEnumerator ();
				enumerator.MoveNext ();

				return ((DictionaryEntry) enumerator.Current).Value as ResXDataNode;
			}
		}
示例#13
0
 public void ImportResxFile(string resxPath, string rootPath, string defaultCulture = "en-US", bool globalResource = false)
 {
     using (var resxFile = new ResXResourceReader(resxPath))
     {
         var dictEnumerator = resxFile.GetEnumerator();
         while (dictEnumerator.MoveNext())
         {
             var record = new ResourceRecord(_connectionString)
             {
                 Page = GetPagePath(resxPath, rootPath, globalResource),
                 CultureCode = GetCulture(resxPath, defaultCulture),
                 Key = dictEnumerator.Key.ToString(),
                 Value = dictEnumerator.Value.ToString()
             };
             record.Save();
             Console.WriteLine(string.Format("Saved record for page {0}, key: {1} value: {2}", record.Page, record.Key, record.Value));
         }
     }
 }
        public static string GetRes(string viewName, string resName)
        {
            var culture = Thread.CurrentThread.CurrentCulture;

            var fileName = viewName + culture.Parent.Name + ".resx";
            var folderName = HttpContext.Current.Server.MapPath("~/LanguageResources/");

            var rr = new System.Resources.ResXResourceReader(folderName + fileName);

            var resources = rr.GetEnumerator();
            while (resources.MoveNext())
            {
                if (resources.Key.ToString() == resName)
                {
                    return resources.Value.ToString();
                }
            }
            return "";
        }
示例#15
0
        public override void ProcessFile(string filePath, Dictionary<string, LocalizableEntity> map)
        {
            Logger.LogFormat("Processing file {0}", filePath);
            try
            {
                using (var reader = new ResXResourceReader(filePath))
                {
                    var dict = reader.GetEnumerator();
                    while (dict.MoveNext())
                        map.Add(dict.Key.ToString(), GetLocalizableProperty(filePath, dict.Key.ToString(), dict.Value.ToString()));
                }

            }
            catch (Exception ex)
            {
                Logger.LogFormat("Error ({0})", filePath);
                throw ex;
            }
        }
示例#16
0
        private static void GenerateJavaScriptResxFile(string resxFilePath, string outDir, string vsdocOutDir, string resourceNamespace, string registerNamespace, bool generateVsDoc)
        {
            StringBuilder resourceSb = new StringBuilder();
            StringBuilder vsdocSb = new StringBuilder();

            using (ResXResourceReader rr = new ResXResourceReader(resxFilePath))
            {
                IDictionaryEnumerator di = rr.GetEnumerator();

                foreach (DictionaryEntry de in rr)
                {
                    string key = de.Key as string;
                    string value = de.Value as string;

                    if (_ReservedWords.Contains(key))
                    {
                        key = "_" + key;
                    }

                    resourceSb.AppendFormat("'{0}': '{1}',", key, value.Replace("'", "\\'").Replace(Environment.NewLine, String.Empty));

                    if (generateVsDoc)
                    {
                        vsdocSb.AppendFormat("'{0}': '',", key);
                    }
                }
            }

            if (!String.IsNullOrWhiteSpace(registerNamespace))
            {
                registerNamespace = "\t" + registerNamespace + " = {};";
            }

            var resourceFileContents = _JavascriptFileTemplate.Replace("#KEYS#", resourceSb.ToString().TrimEnd(',')).Replace("#REGISTERNAMESPACE#", registerNamespace).Replace("#NAMESPACE#", resourceNamespace);
            File.WriteAllText(outDir, resourceFileContents);

            if (generateVsDoc)
            {
                var vsdocFileContents = _VsDocFileTemplate.Replace("#KEYS#", vsdocSb.ToString().TrimEnd(',')).Replace("#REGISTERNAMESPACE#", registerNamespace).Replace("#NAMESPACE#", resourceNamespace);
                File.WriteAllText(vsdocOutDir, vsdocFileContents);
            }
        }
示例#17
0
        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();

        }
示例#18
0
        public string GetResultPath(string appPath)
        {
            // temporarily hardcoded the default path => change this TODO:
            string DefalutPath = string.Empty;
            string AppPath = appPath ;
            fileName = AppPath + "..\\SeShell.Test.XMLTestResult\\Resources\\TestResultResources.resx";
            string xml = System.IO.File.ReadAllText(fileName);

            ResXResourceReader resXResourceReader = new ResXResourceReader(fileName);
            IDictionaryEnumerator dict = resXResourceReader.GetEnumerator();
            while (dict.MoveNext())
            {
                if ((string)dict.Key == "FinalResultLocation")
                {
                    DefalutPath = (string)dict.Value;
                    break;
                }
            }

            return DefalutPath;
        }
 /// <summary>
 /// Creates a <see cref="ResourceDescription"/> from a resx file im memory.
 /// </summary>
 /// <param name="name">The name of the resource.</param>
 /// <param name="path">The path to the resource</param>
 /// <returns>A resource description for the resx file</returns>
 internal static ResourceDescription ReadResource(string name, string path)
 {
     return new ResourceDescription(
         name,
         () =>
     {
         using (ResXResourceReader reader = new ResXResourceReader(path))
         {
             IDictionaryEnumerator enumerator = reader.GetEnumerator();
             MemoryStream memStream = new MemoryStream();
             using (IResourceWriter writer = new ResourceWriter(memStream))
             {
                 while (enumerator.MoveNext())
                 {
                     writer.AddResource(enumerator.Key.ToString(), enumerator.Value);
                 }
             }
             return new MemoryStream(memStream.ToArray());
         }
     },
     false);
 }
示例#20
0
        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();
        }
示例#21
0
		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();
		}
示例#22
0
        private static void TranslateSingleFile(string fileName, string fileSaveName, bool includeBlankResources)
        {
            // Open the input file.
            ResXResourceReader reader = new ResXResourceReader(fileName);
            try
            {
                // Get the enumerator.  If this throws an ArguementException
                // it means the file is not a .RESX file.
                IDictionaryEnumerator enumerator = reader.GetEnumerator();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("WARNING: could not parse " + fileName);
                Console.WriteLine("         " + ex.Message);
                return;
            }

            // Allocate the list for this instance.
            SortedList textResourcesList = new SortedList();

            // Run through the file looking for only true text related
            // properties and only those with values set.
            foreach (DictionaryEntry dic in reader)
            {
                // Only consider this entry if the value is something.
                if (null != dic.Value)
                {
                    // Is this a System.String.
                    if ("System.String" == dic.Value.GetType().ToString())
                    {
                        String KeyString = dic.Key.ToString();

                        // Make sure the key name does not start with the
                        // "$" or ">>" meta characters and is not an empty
                        // string (or we're explicitly including empty strings).
                        if ((false == KeyString.StartsWith(">>")) &&
                            (false == KeyString.StartsWith("$")) &&
                            (includeBlankResources || "" != dic.Value.ToString()))
                        {
                            // We've got a winner.
                            textResourcesList.Add(dic.Key, dic.Value);
                        }

                        // Special case the Windows Form "$this.Text" or
                        // I don't get the form titles.
                        if (0 == String.Compare(KeyString, "$this.Text"))
                        {
                            textResourcesList.Add(dic.Key, dic.Value);
                        }

                    }
                }
            }

            // It's entirely possible that there are no text strings in the
            // .ResX file.
            if (textResourcesList.Count > 0)
            {
                if (null != fileSaveName)
                {
                    if (File.Exists(fileSaveName))
                        File.Delete(fileSaveName);

                    // Create the new file.
                    ResXResourceWriter writer =
                        new ResXResourceWriter(fileSaveName);

                    foreach (DictionaryEntry textdic in textResourcesList)
                    {
                        writer.AddResource(textdic.Key.ToString(), Psuedoizer.ConvertToFakeInternationalized(textdic.Value.ToString()));
                    }

                    writer.Generate();
                    writer.Close();
                    Console.WriteLine(String.Format("{0}: converted {1} text resource(s).", fileName, textResourcesList.Count));
                }
            }
            else
            {
                Console.WriteLine("WARNING: No text resources found in " + fileName);
            }
        }
示例#23
0
		public void BasePathSetOnResXResourceReaderDoesAffectResXDataNode ()
		{
			ResXFileRef fileRef = new ResXFileRef ("file.name", "type.name");
			ResXDataNode node = new ResXDataNode("anode", fileRef);
			string resXFile = GetResXFileWithNode (node, "afilename.xxx");

			using (ResXResourceReader rr = new ResXResourceReader (resXFile)) {
				rr.BasePath = "basePath";
				rr.UseResXDataNodes = true;
				IDictionaryEnumerator en = rr.GetEnumerator ();
				en.MoveNext ();

				ResXDataNode returnedNode = ((DictionaryEntry) en.Current).Value as ResXDataNode;

				Assert.IsNotNull (node, "#A1");
				Assert.AreEqual (Path.Combine ("basePath", "file.name"), returnedNode.FileRef.FileName, "#A2");
			}
		}
示例#24
0
		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 ();
		}
示例#25
0
		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 ();
		}
示例#26
0
		public void AssemblyNamesPassedToResourceReaderDoesNotAffectResXDataNode_TypeConverter ()
		{
			string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
			AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
			
			string resXFile = GetFileFromString ("test.resx", convertableResXWithoutAssemblyName);

			using (ResXResourceReader rr = new ResXResourceReader (resXFile, assemblyNames)) {
				rr.UseResXDataNodes = true;
				IDictionaryEnumerator en = rr.GetEnumerator ();
				en.MoveNext ();

				ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
				
				Assert.IsNotNull (node, "#A1");

				//should raise exception 
				object o = node.GetValue ((AssemblyName []) null);
			}
		}
示例#27
0
		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");
		}
示例#28
0
		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 ResHeader_Reader_Invalid ()
		{
			const string resXTemplate =
				"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
				"<root>" +
				"	<resheader name=\"resmimetype\">" +
				"		{0}" +
				"	</resheader>" +
				"	<resheader name=\"version\">" +
				"		<value>{1}</value>" +
				"	</resheader>" +
				"	<resheader name=\"reader\">" +
				"		<value>System.Resources.InvalidResXResourceReader, {2}</value>" +
				"	</resheader>" +
				"	<resheader name=\"writer\">" +
				"		<value>System.Resources.ResXResourceWriter, {2}</value>" +
				"	</resheader>" +
				"</root>";

			string resXContent = string.Format (CultureInfo.InvariantCulture,
				resXTemplate, ResXResourceWriter.ResMimeType, "1.0",
				Consts.AssemblySystem_Windows_Forms);
			using (ResXResourceReader r = new ResXResourceReader (new StringReader (resXContent))) {
				try {
					r.GetEnumerator ();
					Assert.Fail ("#1");
				} catch (ArgumentException ex) {
					//Invalid ResX input.  Could not find valid \"resheader\"
					// tags for the ResX reader & writer type names
					Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
					Assert.IsNull (ex.InnerException, "#3");
					Assert.IsNotNull (ex.Message, "#4");
					Assert.IsTrue (ex.Message.IndexOf ("\"resheader\"") != -1, "#5");
					Assert.IsNull (ex.ParamName, "#6");
				}
			}
		}
		[Test] // ctor (TextReader)
		public void Constructor3_Reader_InvalidContent ()
		{
			StringReader sr = new StringReader ("</definitelyinvalid<");
			ResXResourceReader r = new ResXResourceReader (sr);
			try {
				r.GetEnumerator ();
				Assert.Fail ("#1");
			} catch (ArgumentException ex) {
				// Invalid ResX input
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
				Assert.IsNotNull (ex.Message, "#3");
				Assert.IsNull (ex.ParamName, "#4");
				Assert.IsNotNull (ex.InnerException, "#5");
				Assert.AreEqual (typeof (XmlException), ex.InnerException.GetType (), "#6");
			}
		}