/// <summary> /// 重新加载配置信息 /// </summary> private static void ReloadConfigFile() { try { if (File.Exists(ConfigFilePath)) { XmlDocument doc = new XmlDocument(); doc.Load(ConfigFilePath); foreach (XmlNode node in doc.DocumentElement.ChildNodes) { bool isGlobal = true; if (node.Attributes["global"] != null) { isGlobal = bool.Parse(node.Attributes["global"].Value); } if (node.Attributes["interface"] != null && node.Attributes["instance"] != null && node.Attributes["file"] != null && !string.IsNullOrEmpty(node.Attributes["interface"].Value) && !string.IsNullOrEmpty(node.Attributes["instance"].Value) && !string.IsNullOrEmpty(node.Attributes["file"].Value) && !string.IsNullOrEmpty(node.Attributes["file"].Value)) { if (BusinessInters.ContainsKey(node.Attributes["interface"].Value) && (!BusinessInters[node.Attributes["interface"].Value].Instance.Equals(node.Attributes["instance"].Value) || !BusinessInters[node.Attributes["interface"].Value].File.Equals(node.Attributes["file"].Value))) { BusinessInters[node.Attributes["interface"].Value].Instance = node.Attributes["instance"].Value; BusinessInters[node.Attributes["interface"].Value].File = node.Attributes["file"].Value; BusinessInters[node.Attributes["interface"].Value].IsGlobal = isGlobal; CacheInjector.RemoveCatche(node.Attributes["interface"].Value); } if (!BusinessInters.ContainsKey(node.Attributes["interface"].Value)) { InjectorItem item = new InjectorItem(); item.InterFace = node.Attributes["interface"].Value; item.Instance = node.Attributes["instance"].Value; item.File = node.Attributes["file"].Value; item.IsGlobal = isGlobal; BusinessInters.Add(node.Attributes["interface"].Value, item); } } } string[] keys = new string[BusinessInters.Count]; BusinessInters.Keys.CopyTo(keys, 0); foreach (string key in keys) { bool isExist = false; foreach (XmlNode node in doc.DocumentElement.ChildNodes) { if (node.Attributes["interface"] != null && key.Equals(node.Attributes["interface"].Value)) { isExist = true; break; } } if (isExist == false) { BusinessInters.Remove(key); CacheInjector.RemoveCatche(key); } } } } catch { } }
/// <summary> /// 读取文件 /// </summary> private static void LoadDatabaseConfig() { if (File.Exists(ConfigFilePath)) { XmlDocument doc = new XmlDocument(); doc.Load(ConfigFilePath); BusinessInters = new Dictionary<string, InjectorItem>(); foreach (XmlNode node in doc.DocumentElement.ChildNodes) { bool isGlobal = true; if (node.Attributes["global"] != null) { isGlobal = bool.Parse(node.Attributes["global"].Value); } if (node.Attributes["interface"] != null && node.Attributes["instance"] != null && node.Attributes["file"] != null && !string.IsNullOrEmpty(node.Attributes["interface"].Value) && !string.IsNullOrEmpty(node.Attributes["instance"].Value) && !string.IsNullOrEmpty(node.Attributes["file"].Value) ) { InjectorItem item = new InjectorItem(); item.InterFace = node.Attributes["interface"].Value; item.Instance = node.Attributes["instance"].Value; item.File = node.Attributes["file"].Value; item.IsGlobal = isGlobal; BusinessInters.Add(node.Attributes["interface"].Value, item); } } } }