/// <summary> /// 修改配置, /// TODO:仔细考虑多个场景,不能出现遗漏,极端情况下减少错误判断的可能性 /// </summary> /// <param name="fileName"></param> /// <param name="content"></param> public void Modify(string fileName, ConfigurationContent content) { var original = Config.Configurations.Find(p => p.Filename.Equals(fileName)); if (original == null) { throw new ConfigurationModifyException (ErrorCode.InvalidConfigurationFile, $"修改配置时无法找到相应的配置文件 : {fileName}"); } // 修改当前配置 Config.Configurations.Remove(original); Config.Configurations.Add(content); // 同步配置文件 using (var sw = new StreamWriter(LOCAL_CONFIG_FILENAME)) { serializer.Serialize(sw, Config); } // 重新初始化 Config.Init(); // 触发监听 registers.TryGetValue(fileName, out var eventList); if (eventList == null) { return; } lock (eventList) { foreach (var manualEvent in eventList) { manualEvent.Set(); } // 清空所有监听事件 eventList.Clear(); } }