private bool LoadOptionFile(Zongsoft.Plugins.Plugin plugin)
        {
            if (_providers.ContainsKey(plugin))
            {
                return(false);
            }

            var filePath = Path.GetDirectoryName(plugin.FilePath);
            var fileName = Path.GetFileNameWithoutExtension(plugin.FilePath);

            var composite = new CompositeConfigurationProvider(new[]
            {
                new Zongsoft.Configuration.Xml.XmlConfigurationSource()
                {
                    Path           = Path.Combine(filePath, $"{fileName}.option"),
                    Optional       = true,
                    ReloadOnChange = true,
                }.Build(null),
                new Zongsoft.Configuration.Xml.XmlConfigurationSource()
                {
                    Path           = Path.Combine(filePath, $"{fileName}.{_source.Options.EnvironmentName.ToLowerInvariant()}.option"),
                    Optional       = true,
                    ReloadOnChange = true,
                }.Build(null),
            });

            //加载配置文件
            composite.Load();

            return(_providers.TryAdd(plugin, composite));
        }
        public static Profile GetProfile(Zongsoft.Plugins.Plugin plugin)
        {
            if (plugin == null)
            {
                return(null);
            }

            return(Profile.Load(GetAssistedFilePath(plugin, ".ini")));
        }
        public static OptionConfiguration GetConfiguration(Zongsoft.Plugins.Plugin plugin)
        {
            if (plugin == null)
            {
                return(null);
            }

            string filePath = GetAssistedFilePath(plugin, ".option");

            return(OptionConfigurationManager.Open(filePath));
        }
 public static bool HasConfigurationFile(Zongsoft.Plugins.Plugin plugin)
 {
     try
     {
         return(File.Exists(GetConfigurationFilePath(plugin)));
     }
     catch
     {
         return(false);
     }
 }
        public static string GetAssistedFilePath(Zongsoft.Plugins.Plugin plugin, string extensionName)
        {
            if (plugin == null || string.IsNullOrWhiteSpace(extensionName))
            {
                return(null);
            }

            return(Path.Combine(
                       Path.GetDirectoryName(plugin.FilePath),
                       Path.GetFileNameWithoutExtension(plugin.FilePath) + (extensionName[0] == '.' ? extensionName : "." + extensionName)));
        }
Exemple #6
0
        public static PluginSettingsProvider GetProvider(Zongsoft.Plugins.Plugin plugin)
        {
            if (plugin == null)
            {
                throw new ArgumentNullException("plugin");
            }

            var configuration = OptionUtility.GetConfiguration(plugin);

            if (configuration == null)
            {
                return(null);
            }

            return(_cache.Get(plugin.FilePath, key =>
            {
                return new PluginSettingsProvider(plugin, configuration);
            }));
        }
 public static string GetConfigurationFilePath(Zongsoft.Plugins.Plugin plugin)
 {
     return(GetAssistedFilePath(plugin, ".option"));
 }
 internal PluginSettingsProvider(Zongsoft.Plugins.Plugin plugin, OptionConfiguration configuration)
 {
     _plugin        = plugin;
     _configuration = configuration;
     _settings      = (ISettingsProvider)_configuration.GetOptionValue("/settings");
 }