Пример #1
0
 /// <summary>Load configuration from a list of files until the first successful load</summary>
 /// <param name="conf">the configuration object</param>
 /// <param name="files">the list of filenames to try</param>
 /// <returns>the configuration object</returns>
 internal static Org.Apache.Hadoop.Metrics2.Impl.MetricsConfig LoadFirst(string prefix
                                                                         , params string[] fileNames)
 {
     foreach (string fname in fileNames)
     {
         try
         {
             Org.Apache.Commons.Configuration.Configuration cf = new PropertiesConfiguration(fname
                                                                                             ).InterpolatedConfiguration();
             Log.Info("loaded properties from " + fname);
             Log.Debug(ToString(cf));
             Org.Apache.Hadoop.Metrics2.Impl.MetricsConfig mc = new Org.Apache.Hadoop.Metrics2.Impl.MetricsConfig
                                                                    (cf, prefix);
             Log.Debug(mc);
             return(mc);
         }
         catch (ConfigurationException e)
         {
             if (e.Message.StartsWith("Cannot locate configuration"))
             {
                 continue;
             }
             throw new MetricsConfigException(e);
         }
     }
     Log.Warn("Cannot locate configuration: tried " + Joiner.On(",").Join(fileNames));
     // default to an empty configuration
     return(new Org.Apache.Hadoop.Metrics2.Impl.MetricsConfig(new PropertiesConfiguration
                                                                  (), prefix));
 }
        private void Start()
        {
            TextAsset      text = Resources.Load <TextAsset>("application.properties");
            IConfiguration conf = new PropertiesConfiguration(text.text);

            Version appVersion  = conf.GetVersion("application.app.version");
            Version dataVersion = conf.GetVersion("application.data.version");

            Debug.LogFormat("application.app.version:{0}", appVersion);
            Debug.LogFormat("application.data.version:{0}", dataVersion);

            string         groupName        = conf.GetString("application.config-group");
            IConfiguration currentGroupConf = conf.Subset("application." + groupName);

            string upgradeUrl = currentGroupConf.GetString("upgrade.url");
            string username   = currentGroupConf.GetString("username");
            string password   = currentGroupConf.GetString("password");

            string[] gatewayArray = currentGroupConf.GetArray <string>("gateway");

            Debug.LogFormat("upgrade.url:{0}", upgradeUrl);
            Debug.LogFormat("username:{0}", username);
            Debug.LogFormat("password:{0}", password);

            int i = 1;

            foreach (string gateway in gatewayArray)
            {
                Debug.LogFormat("gateway {0}:{1}", i++, gateway);
            }
        }
Пример #3
0
        internal static string ToString(Org.Apache.Commons.Configuration.Configuration c)
        {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();

            try
            {
                TextWriter ps = new TextWriter(buffer, false, "UTF-8");
                PropertiesConfiguration tmp = new PropertiesConfiguration();
                tmp.Copy(c);
                tmp.Save(ps);
                return(buffer.ToString("UTF-8"));
            }
            catch (Exception e)
            {
                throw new MetricsConfigException(e);
            }
        }
Пример #4
0
 public override string CurrentConfig()
 {
     lock (this)
     {
         PropertiesConfiguration saver  = new PropertiesConfiguration();
         StringWriter            writer = new StringWriter();
         saver.Copy(config);
         try
         {
             saver.Save(writer);
         }
         catch (Exception e)
         {
             throw new MetricsConfigException("Error stringify config", e);
         }
         return(writer.ToString());
     }
 }
Пример #5
0
        internal static void Dump(string header, Org.Apache.Commons.Configuration.Configuration
                                  c, TextWriter @out)
        {
            PropertiesConfiguration p = new PropertiesConfiguration();

            p.Copy(c);
            if (header != null)
            {
                @out.WriteLine(header);
            }
            try
            {
                p.Save(@out);
            }
            catch (Exception e)
            {
                throw new RuntimeException("Error saving config", e);
            }
        }
Пример #6
0
 /// <summary>Default constructor</summary>
 public ConfigBuilder()
 {
     config = new PropertiesConfiguration();
 }