Example #1
0
        private void LoadSettings(IList <string> assemblyFiles)
        {
            foreach (string assemblyFile in assemblyFiles)
            {
                string assemblyLocation = null;
                try
                {
                    Assembly assembly = Assembly.LoadFile(assemblyFile);
                    assemblyLocation = assembly.Location;

                    // Try to locate and load the embedded resource file
                    string embResText = assembly.GetEmbeddedResourceText(SettingsConfigurationEmbeddedResourceFileName);
                    // If the assembly has no such settings configuration, skip further processing.
                    if (string.IsNullOrWhiteSpace(embResText))
                    {
                        continue;
                    }

                    // Try to parse the settings configuration file
                    XDocument settingsConfigurationXml = XDocument.Parse(embResText);

                    SettingsConfigurationFile scf = SettingsConfigurationFileParser.Parse(settingsConfigurationXml);
                    // Make a check if the configuration file has failed to parse
                    if (scf == null)
                    {
                        Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.SettingsConfigurationEmbResParseFailed, assemblyLocation);
                        continue;
                    }

                    // Success. Add the file to the dictionary.
                    _settings[scf.Identifier] = scf;

                    Logger.Instance.LogFormat(LogType.Debug, this, Properties.Resources.SettingsConfigurationEmbResLoaded, assemblyLocation);
                }
                catch (XmlException ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.SettingsConfigurationEmbResXmlException, assemblyLocation, ex.Message);
                }
                catch (BadImageFormatException)
                {
                    // We can ignore this exception because it may occur with unmanaged dlls.
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        private void LoadSettings(IList <string> assemblyFiles)
        {
            foreach (string assemblyFile in assemblyFiles)
            {
                string assemblyLocation = null;
                try
                {
                    Assembly assembly = Assembly.LoadFile(assemblyFile);
                    assemblyLocation = assembly.Location;

                    string embResText = assembly.GetEmbeddedResourceText(SettingsConfigurationEmbeddedResourceFileName);
                    if (string.IsNullOrWhiteSpace(embResText))
                    {
                        continue;
                    }

                    XDocument settingsConfigurationXml = XDocument.Parse(embResText);

                    SettingsConfigurationFile scf = SettingsConfigurationFileParser.Parse(settingsConfigurationXml);
                    if (scf == null)
                    {
                        Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.SettingsConfigurationEmbResParseFailed, assemblyLocation);
                        continue;
                    }

                    _settings[scf.Identifier] = scf;
                }
                catch (XmlException ex)
                {
                    Logger.Instance.LogException(this, ex);
                    Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.SettingsConfigurationEmbResXmlException, assemblyLocation);
                }
                catch (BadImageFormatException)
                {
                    // We can ignore this exception because it may occur with unmanaged dlls.
                }
            }
        }