/// <summary> /// 获取model /// </summary> /// <param name="exeConfig"></param> /// <param name="info"></param> /// <returns></returns> private static MapConfigModel getModel(ExeConfigurationFileMap exeConfig, FileInfo info) { var result = new MapConfigModel(); var config = ConfigurationManager.OpenMappedExeConfiguration(exeConfig, ConfigurationUserLevel.None); var item = (MapConfig)config.GetSection("MapConfig"); if (item != null) { foreach (var temp in item.SqlMap) { var path = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, (temp as MapElement).File.Replace("/", "\\")); if (File.Exists(path)) { result.Path.Add(path); } } result.LastWrite = info.LastWriteTime; return(result); } else { return(new MapConfigModel()); } }
public static void InstanceMapResource(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json") { var projectName = Assembly.GetCallingAssembly().GetName().Name; var config = DataConfig.Get(dbKey, projectName, dbFile); var db = new DataContext(dbKey); var assembly = Assembly.Load(projectName); var map = new MapConfigModel(); using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, mapFile))) { if (resource != null) { using (var reader = new StreamReader(resource)) { var content = reader.ReadToEnd(); map.Path = BaseJson.JsonToModel <List <string> >(BaseJson.JsonToDic(BaseJson.ModelToJson(BaseJson.JsonToDic(content).GetValue(AppSettingKey.Map))).GetValue("Path").ToStr()); } } else { map = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile); } } if (map.Path == null) { return; } map.Path.ForEach(a => { using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, a.Replace("/", ".")))) { var xml = ""; if (resource != null) { using (var reader = new StreamReader(resource)) { xml = reader.ReadToEnd(); } } var info = new FileInfo(a); var key = BaseSymmetric.Generate(info.FullName); if (!DbCache.Exists(config.CacheType, key)) { var temp = new MapXmlModel(); temp.LastWrite = info.LastWriteTime; temp.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml); temp.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, temp); } } else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0) { DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(f => { DbCache.Remove(config.CacheType, f); }); var model = new MapXmlModel(); model.LastWrite = info.LastWriteTime; model.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml); model.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, model); } } } }); }