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 GetSettingDefinitions(SettingDefinitionProviderContext context) { if (!File.Exists(FileName)) { throw new Exception("未查询到Setting文件,请检查配置!"); } var list = new List(); 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; } } }