private Hashtable GetSatelliteAssembliesFromConfig() { string configurationFileInternal = AppDomain.CurrentDomain.FusionStore.ConfigurationFileInternal; if (configurationFileInternal == null) { return(null); } if (((configurationFileInternal.Length >= 2) && ((configurationFileInternal[1] == Path.VolumeSeparatorChar) || ((configurationFileInternal[0] == Path.DirectorySeparatorChar) && (configurationFileInternal[1] == Path.DirectorySeparatorChar)))) && !File.InternalExists(configurationFileInternal)) { return(null); } ConfigTreeParser parser = new ConfigTreeParser(); string configPath = "/configuration/satelliteassemblies"; ConfigNode node = null; try { node = parser.Parse(configurationFileInternal, configPath, true); } catch (Exception) { } if (node == null) { return(null); } Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (ConfigNode node2 in node.Children) { if (!string.Equals(node2.Name, "assembly")) { throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTag", new object[] { Path.GetFileName(configurationFileInternal), node2.Name })); } if (node2.Attributes.Count == 0) { throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagNoAttr", new object[] { Path.GetFileName(configurationFileInternal) })); } DictionaryEntry entry = node2.Attributes[0]; string str3 = (string)entry.Value; if ((!object.Equals(entry.Key, "name") || string.IsNullOrEmpty(str3)) || (node2.Attributes.Count > 1)) { throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagBadAttr", new object[] { Path.GetFileName(configurationFileInternal), entry.Key, entry.Value })); } ArrayList list = new ArrayList(5); foreach (ConfigNode node3 in node2.Children) { if (node3.Value != null) { list.Add(node3.Value); } } string[] strArray = new string[list.Count]; for (int i = 0; i < strArray.Length; i++) { string cultureName = (string)list[i]; strArray[i] = cultureName; if (FrameworkEventSource.IsInitialized) { FrameworkEventSource.Log.ResourceManagerAddingCultureFromConfigFile(this.BaseNameField, this.MainAssembly, cultureName); } } hashtable.Add(str3, strArray); } return(hashtable); }
private static void InitializeConfigInfo() { // set up the version string Type myType = typeof(CryptoConfig); _Version = myType.Assembly.GetVersion().ToString(); if (defaultNameHT == null) { lock (lockType) { if (defaultNameHT == null) { defaultNameHT = CreateDefaultMappingHT(); } } } if (defaultOidHT == null) { lock (lockType) { if (defaultOidHT == null) { defaultOidHT = CreateDefaultOidHT(); } } } if (defaultCalgHT == null) { lock (lockType) { if (defaultCalgHT == null) { defaultCalgHT = CreateDefaultCalgHT(); } } } if ((machineNameHT == null) && (machineOidHT == null)) { lock (lockType) { String machineConfigFile = machineConfigDir + machineConfigFilename; if (File.Exists(machineConfigFile)) { // we need to assert here the right to read the machineConfigFile, since // the parser now checks for this right. (new FileIOPermission(FileIOPermissionAccess.Read, machineConfigFile)).Assert(); ConfigTreeParser parser = new ConfigTreeParser(); ConfigNode rootNode = parser.Parse(machineConfigFile, "configuration"); if (rootNode == null) { goto endInitialization; } // now, find the mscorlib tag with our version ArrayList rootChildren = rootNode.Children; ConfigNode mscorlibNode = null; foreach (ConfigNode node in rootChildren) { if (node.Name.Equals("mscorlib")) { ArrayList attribs = node.Attributes; if (attribs.Count > 0) { DictionaryEntry attribute = (DictionaryEntry)node.Attributes[0]; if (attribute.Key.Equals("version")) { if (attribute.Value.Equals(_Version)) { mscorlibNode = node; break; } } } else { mscorlibNode = node; } } } if (mscorlibNode == null) { goto endInitialization; } // look for cryptosettings ArrayList mscorlibChildren = mscorlibNode.Children; ConfigNode cryptoSettings = null; foreach (ConfigNode node in mscorlibChildren) { // take the first one that matches if (node.Name.Equals("cryptographySettings")) { cryptoSettings = node; break; } } if (cryptoSettings == null) { goto endInitialization; } // See if there's a CryptoNameMapping section (at most one) ConfigNode cryptoNameMapping = null; foreach (ConfigNode node in cryptoSettings.Children) { if (node.Name.Equals("cryptoNameMapping")) { cryptoNameMapping = node; break; } } if (cryptoNameMapping == null) { goto initializeOIDMap; } // We have a name mapping section, so now we have to build up the type aliases // in CryptoClass elements and the mappings. ArrayList cryptoNameMappingChildren = cryptoNameMapping.Children; ConfigNode cryptoClasses = null; // find the cryptoClases element foreach (ConfigNode node in cryptoNameMappingChildren) { if (node.Name.Equals("cryptoClasses")) { cryptoClasses = node; break; } } // if we didn't find it, no mappings if (cryptoClasses == null) { goto initializeOIDMap; } Hashtable typeAliases = new Hashtable(); Hashtable nameMappings = new Hashtable(); foreach (ConfigNode node in cryptoClasses.Children) { if (node.Name.Equals("cryptoClass")) { if (node.Attributes.Count > 0) { DictionaryEntry attribute = (DictionaryEntry)node.Attributes[0]; typeAliases.Add(attribute.Key, attribute.Value); } } } // Now process the name mappings foreach (ConfigNode node in cryptoNameMappingChildren) { if (node.Name.Equals("nameEntry")) { String friendlyName = null; String className = null; foreach (DictionaryEntry attribNode in node.Attributes) { if (((String)attribNode.Key).Equals("name")) { friendlyName = (String)attribNode.Value; continue; } if (((String)attribNode.Key).Equals("class")) { className = (String)attribNode.Value; continue; } } if ((friendlyName != null) && (className != null)) { String typeName = (String)typeAliases[className]; if (typeName != null) { nameMappings.Add(friendlyName, typeName); } } } } machineNameHT = nameMappings; initializeOIDMap: // Now, process the OID mappings // See if there's an oidMap section (at most one) ConfigNode oidMapNode = null; foreach (ConfigNode node in cryptoSettings.Children) { if (node.Name.Equals("oidMap")) { oidMapNode = node; break; } } if (oidMapNode == null) { goto endInitialization; } Hashtable oidMapHT = new Hashtable(); foreach (ConfigNode node in oidMapNode.Children) { if (node.Name.Equals("oidEntry")) { String oidString = null; String friendlyName = null; foreach (DictionaryEntry attribNode in node.Attributes) { if (((String)attribNode.Key).Equals("OID")) { oidString = (String)attribNode.Value; continue; } if (((String)attribNode.Key).Equals("name")) { friendlyName = (String)attribNode.Value; continue; } } if ((friendlyName != null) && (oidString != null)) { oidMapHT.Add(friendlyName, oidString); } } } machineOidHT = oidMapHT; } } } endInitialization: isInitialized = true; }