| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Xml;
- using Abp.Configuration;
- using IwbZero.ToolCommon.LogHelpers;
- namespace WeEngine.Configuration
- {
- public class IwbSettingProvider : SettingProvider
- {
- private static string FileName => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin/Resources", "Setting.iwbx");
- public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
- {
- if (!File.Exists(FileName))
- {
- throw new Exception("未查询到Setting文件,请检查配置!");
- }
- var list = new List<SettingDefinition>();
- var t = typeof(IwbSettingNames);
- var fts = t.GetFields().Select(a=>a.GetRawConstantValue()).ToList();
- try
- {
- var xDoc = new XmlDocument();
- xDoc.Load(FileName);
- XmlNode xmlNode = xDoc.LastChild;
- if (xmlNode != null && xmlNode.HasChildNodes)
- {
- foreach (XmlNode node in xmlNode.ChildNodes)
- {
- var name = node.Attributes?["name"] != null ? node.Attributes["name"].Value : "";
- var value = node.Attributes?["value"] != null ? node.Attributes["value"].Value : "";
- if (fts.Contains(name))
- {
- var setting = new SettingDefinition(name, value,
- scopes: SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User,
- isVisibleToClients: true);
- if (!list.Contains(setting))
- {
- list.Add(setting);
- }
- }
-
- }
- }
- }
- catch (Exception e)
- {
- typeof(IwbSettingProvider).LogError(e);
- throw new Exception($"Setting文件解析失败,请检查配置!({e.Message})");
- }
-
- return list;
- }
- }
- }
|