Esempio n. 1
0
        private Configuration ReadIncludeConfiguration(bool replace)
        {
            try
            {
                Properties properties = new Properties();
                properties.Load(CONFIG_INCLUDE_PROPS_FILE);

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

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

                using (FileReader reader = new FileReader(cfile))
                {
                    reader.Open();
                    XmlConfigParser       parser   = new XmlConfigParser();
                    ConfigurationSettings settings = new ConfigurationSettings();
                    settings.ReplaceProperties = replace;

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

                    return(parser.GetConfiguration());
                }
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }
Esempio n. 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;
            }
        }
Esempio n. 3
0
        private Configuration ReadConfiguration()
        {
            if (configuration != null)
            {
                return(configuration);
            }
            try
            {
                Properties properties = new Properties();
                properties.Load(CONFIG_BASIC_PROPS_FILE);

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

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

                using (FileReader reader = new FileReader(cfile))
                {
                    reader.Open();
                    XmlConfigParser       parser   = new XmlConfigParser();
                    ConfigurationSettings settings = new ConfigurationSettings();

                    settings.DownloadOptions = EDownloadOptions.LoadRemoteResourcesOnStartup;

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

                    configuration = parser.GetConfiguration();

                    return(configuration);
                }
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }