当前位置: 首页>>代码示例>>C#>>正文


C# IConfigSource.ExpandKeyValues方法代码示例

本文整理汇总了C#中IConfigSource.ExpandKeyValues方法的典型用法代码示例。如果您正苦于以下问题:C# IConfigSource.ExpandKeyValues方法的具体用法?C# IConfigSource.ExpandKeyValues怎么用?C# IConfigSource.ExpandKeyValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConfigSource的用法示例。


在下文中一共展示了IConfigSource.ExpandKeyValues方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        public uint Configure(IConfigSource config)
        {
            Config = config;

            IConfig startconfig = Config.Configs["Startup"];
            string configdirectory = startconfig.GetString("ConfigDirectory", ".");

            ConfigFile = Path.Combine(configdirectory, CONFIG_FILE);

            IConfig wifiConfig = Config.Configs[ConfigName];

            if (wifiConfig == null)
            {
                // No [WifiService] in the main configuration. We need to read it from its own file
                if (!File.Exists(ConfigFile))
                {
                    // We need to copy the one that comes in the package
                    if (!Directory.Exists(configdirectory))
                        Directory.CreateDirectory(configdirectory);

                    string embeddedConfig = Path.Combine(AssemblyDirectory, CONFIG_FILE);
                    File.Copy(embeddedConfig, ConfigFile);
                    m_log.ErrorFormat("[Wifi]: PLEASE EDIT {0} BEFORE RUNNING THIS SERVICE", ConfigFile);
                    throw new Exception("Wifi addin must be configured prior to running");
                }
                else
                {
                    m_log.DebugFormat("[Wifi]: Configuring from {0}...", ConfigFile);

                    IConfigSource configsource = new IniConfigSource(ConfigFile);
                    AdjustStorageProvider(configsource);

                    wifiConfig = configsource.Configs[ConfigName];

                    // Merge everything and expand eventual key values used by our config
                    Config.Merge(configsource);
                    Config.ExpandKeyValues();
                }

                if (wifiConfig == null)
                    throw new Exception(string.Format("[Wifi]: Could not load configuration from {0}. Unable to proceed.", ConfigFile));

            }

            Enabled = wifiConfig.GetBoolean("Enabled", false);

            // Let's look for the port in WifiService first, then look elsewhere
            int port = wifiConfig.GetInt("ServerPort", -1);
            if (port > 0)
                return (uint)port;

            IConfig section = Config.Configs["Const"];
            if (section != null)
            {
                port = section.GetInt("PublicPort", -1);
                if (port > 0)
                    return (uint)port;
            }

            if (port < 0)
                throw new Exception("[Wifi]: Could not find port in configuration file");

            return 0;
        }
开发者ID:MelanieT,项目名称:diva-distribution,代码行数:64,代码来源:WifiServerConnector.cs


注:本文中的IConfigSource.ExpandKeyValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。