Esempio n. 1
0
        private void RegisterDatabase(DaoProxyRegistration reg)
        {
            DaoConf daoConf = BamConf.DaoConfigs.Where(d => d.ConnectionName.Equals(reg.ContextName)).FirstOrDefault() ?? DaoConf.GetDefault(reg.ContextName, BamConf);

            daoConf.Register();
            reg.Database = Db.For(reg.ContextName);
            reg.Database.TryEnsureSchema(reg.Assembly, Logger);
        }
Esempio n. 2
0
        /// <summary>
        /// Load the BamConf from one of BamConf.json, BamConf.yaml, BamConf.xml
        /// or the Default configuration file whichever is found first in that order.  Default
        /// will always be provided and will never return null.  A json config will be created
        /// if no config is found of any of the formats json, yaml or xml.
        /// </summary>
        /// <returns></returns>
        public static BamConf Load(string contentRootDir)
        {
            BamConf config = null;

            string jsonConfig = Path.Combine(contentRootDir, string.Format("{0}.json", typeof(BamConf).Name));

            if (File.Exists(jsonConfig))
            {
                BamConf temp = LoadJsonConfig(jsonConfig);
                config = temp;
            }

            if (config == null)
            {
                string yamlConfig = Path.Combine(contentRootDir, string.Format("{0}.yaml", typeof(BamConf).Name));
                if (File.Exists(yamlConfig))
                {
                    BamConf temp = LoadYamlConfig(yamlConfig);
                    config = temp;
                }
            }

            if (config == null)
            {
                string xmlConfig = Path.Combine(contentRootDir, string.Format("{0}.xml", typeof(BamConf).Name));
                if (File.Exists(xmlConfig))
                {
                    BamConf temp = LoadXmlConfig(xmlConfig);
                    config = temp;
                }
            }

            if (config == null)
            {
                config = new BamConf();
                DefaultConfiguration.SetProperties(config);
                config.LoadedFrom = new FileInfo(jsonConfig).FullName;
                config.Save();
            }

            config.ContentRoot = contentRootDir;

            if (config.DaoConfigs.Length == 0)
            {
                config.DaoConfigs = new DaoConf[] { DaoConf.GetDefault("DaoConf", config) };
            }
            return(config);
        }