Ejemplo n.º 1
0
        static Config()
        {
            // static C'tor, run once to check for compiled/embedded config

            // scan ALL linked assemblies and merge their default configs while
            // giving the entry assembly top priority in merge
            try
            {
                var entryAssembly = Assembly.GetEntryAssembly();
                var assemblies    = AppDomain.CurrentDomain.GetAssemblies();
                foreach (var assembly in assemblies.Where(assembly => !assembly.Equals(entryAssembly) && assembly.GetName().Name.StartsWith("FlexibleMVC")))
                {
                    Default = Merger.Merge(GetDefaultConfig(assembly), Default);
                }
                if (entryAssembly != null)
                {
                    Default = Merger.Merge(GetDefaultConfig(entryAssembly), Default);
                }

                // User config (provided through a settings.conf file)
                var execution_path       = AppDomain.CurrentDomain.BaseDirectory;
                var user_config_filename = "settings";

                var d          = new DirectoryInfo(execution_path);
                var userConfig = (from FileInfo fi in d.GetFiles()
                                  where (
                                      fi.FullName.EndsWith(user_config_filename + ".conf") ||
                                      fi.FullName.EndsWith(user_config_filename + ".json") ||
                                      fi.FullName.EndsWith(user_config_filename + ".conf.json") ||
                                      fi.FullName.EndsWith(user_config_filename + ".json.conf")
                                      )
                                  select fi).FirstOrDefault();

                if (userConfig != null)
                {
                    User = Config.ParseJson(File.ReadAllText(userConfig.FullName));
                    WatchUserConfig(userConfig);
                }
                else
                {
                    User = new NullExceptionPreventer();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
Ejemplo n.º 2
0
        private static dynamic GetDefaultConfig(Assembly assembly)
        {
            var dconf_json = ScanForDefaultConfig(assembly);

            if (dconf_json == null || dconf_json.Count == 0)
            {
                return(null);
            }

            ConfigObject cfg = new ConfigObject();

            foreach (var dconf in dconf_json)
            {
                cfg = Merger.Merge(ParseJson(dconf), cfg);
            }

            return(cfg);
        }
Ejemplo n.º 3
0
 object Clone()
 {
     return(Merger.Merge(new ConfigObject(), this));
 }