static void ModManagerApplicationExit()
        {
            FileStream configFile = null;

            try
            {
                if (s_pluginsConfig != null)
                {
                    configFile = File.Open(s_sConfigFilePath, FileMode.OpenOrCreate, FileAccess.Write,
                                           FileShare.Read);
                    XmlConfigWriter.Write(s_pluginsConfig, configFile);
                    configFile.Flush();
                }
            }
            catch (Exception ex)
            {
                LoggingManager.SendMessage("ConfigManager - Could not write config file");
                LoggingManager.HandleException(ex);
                UIHelper.ShowError("Failed to save configuration file. See Log file for more information.");
            }
            finally
            {
                if (configFile != null)
                {
                    configFile.Close();
                }
            }
        }
Exemple #2
0
        public void Write()
        {
            try
            {
                Configuration configuration = ReadConfiguration();

                Assert.NotNull(configuration);
                string          path     = FileUtils.GetTempDirectory();
                XmlConfigWriter writer   = new XmlConfigWriter();
                string          filename = writer.Write(configuration, path);

                FileInfo fi = new FileInfo(filename);
                if (!fi.Exists)
                {
                    throw new Exception(String.Format("Error getting created file: [file={0}]", fi.FullName));
                }
                LogUtils.Info(String.Format("Configuration written to file. [file={0}]", fi.FullName));

                Properties properties = new Properties();
                properties.Load(CONFIG_BASIC_PROPS_FILE);

                string cname = properties.GetProperty(CONFIG_PROP_NAME);
                Assert.False(String.IsNullOrWhiteSpace(cname));
                string version = properties.GetProperty(CONFIG_PROP_VERSION);
                Assert.False(String.IsNullOrWhiteSpace(version));

                LogUtils.Info(String.Format("Reading Configuration: [file={0}][version={1}]", filename, version));

                using (FileReader reader = new FileReader(filename))
                {
                    reader.Open();
                    XmlConfigParser       parser   = new XmlConfigParser();
                    ConfigurationSettings settings = new ConfigurationSettings();
                    settings.DownloadOptions = EDownloadOptions.LoadRemoteResourcesOnStartup;

                    parser.Parse(cname, reader, Version.Parse(version), settings);

                    Configuration nconfig = parser.GetConfiguration();

                    LogUtils.Debug("New Configuration:", nconfig);
                }
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }
Exemple #3
0
        public void WriteToString()
        {
            try
            {
                Configuration configuration = ReadIncludeConfiguration(false);

                Assert.NotNull(configuration);
                XmlConfigWriter writer = new XmlConfigWriter();
                string          config = writer.Write(configuration);

                if (String.IsNullOrWhiteSpace(config))
                {
                    throw new Exception("Error getting configuration as String");
                }
                LogUtils.Info(String.Format("Configuration written to String: [config={0}]", config));
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }