Пример #1
0
        public static void BamInit()
        {
            // Read BAM_HOME environment variable
            string applicationName = EnvironmentApplicationNameProvider.Instance.GetApplicationName();

            Message.PrintLine("ApplicationName = {0}", ConsoleColor.DarkBlue, applicationName);

            string bamHome = BamEnvironmentVariables.Home();

            Message.PrintLine("BAM_HOME = {0}", ConsoleColor.DarkBlue, bamHome);
            // create a directory in {{bamHome}}/content/apps/{{applicationName}}
            DirectoryInfo appHome = new DirectoryInfo(Path.Combine(bamHome, "content", "apps", applicationName));

            if (!appHome.Exists)
            {
                appHome.Create();
            }
            // create
            // - pages/
            DirectoryInfo pagesDir = new DirectoryInfo(Path.Combine(appHome.FullName, "pages"));

            if (!pagesDir.Exists)
            {
                pagesDir.Create();
            }

            //    home.html
            //    about.html
            //    contact.html
            //    tests.html

            // TODO: finish this
            throw new NotImplementedException();

            DirectoryInfo docsDir = new DirectoryInfo(Path.Combine(appHome.FullName, "docs"));

            if (!docsDir.Exists)
            {
                docsDir.Create();
            }
            //    docs/
            //        intro.md
            //        books.md
            //        data.md
            //        models.md
            //        viewModels.md
            // - data/
            // - data/dao/
            // - data/repo/
            // - data/json/
            // - data/yaml/
            // - data/csv/
            // - models/
            // - viewModels/
        }
        public ConfigurationValue this[string key, string defaultValue = null, bool callConfigService = false]
        {
            get
            {
                ConfigurationSources source = ConfigurationSources.NotFound;

                string value = NetCoreConfiguration?[key];
                if (!string.IsNullOrEmpty(value))
                {
                    source = ConfigurationSources.NetCoreConfiguration;
                }
                else
                {
                    value  = DefaultConfiguration[key];
                    source = ConfigurationSources.DefaultConfiguration;
                }

                if (string.IsNullOrEmpty(value) && AppSettings.ContainsKey(key))
                {
                    value  = AppSettings[key];
                    source = ConfigurationSources.ConfigAppSettings;
                }

                if (string.IsNullOrEmpty(value))
                {
                    value  = BamEnvironmentVariables.GetBamVariable(key);
                    source = ConfigurationSources.BamEnvironmentVariable;
                }

                if (string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(defaultValue))
                {
                    value  = defaultValue;
                    source = ConfigurationSources.DefaultValue;
                }

                if (string.IsNullOrEmpty(value) && callConfigService)
                {
                    value  = FromService(key);
                    source = ConfigurationSources.ConfigurationService;
                }

                if (string.IsNullOrEmpty(value))
                {
                    FireEvent(ConfigurationValueNotFound, new ConfigurationEventArgs {
                        Key = key
                    });
                }

                if (!string.IsNullOrEmpty(value))
                {
                    Config.AppSettings.AddMissing(key, value);
                    Config.Save();
                }

                return(new ConfigurationValue(value)
                {
                    Key = key,
                    DefaultValue = defaultValue,
                    CallConfigService = callConfigService,
                    ConfigurationSource = source
                });
            }
        }