public PersistenceColumnAttribute() { this.IsIndex = this.IsShard = false; this.ShardSpan = WcfExtension.ShardSpan.Month; }
/// <summary> /// 保存日志异常配置信息 /// </summary> /// <param name="logInfo"></param> public void SaveSetting(List <AbstractLogInfo> logInfo) { try { // 库名:WcfLogServer 表名 InfoSetting // 读出属性,做索引,分库处理 // 保存到数据库中去,采用批量方式 List <InfoSetting> listInfo = new List <InfoSetting>(); InfoSetting infoSetting; string temp; logInfo.ForEach(log => { Type typeLog = log.GetType(); string typeName = typeLog.Name; if (!ConfigProvider.Common.DicInfoSetting.Contains(typeName)) //判断索引是否已经创建过 { ConfigProvider.Common.DicInfoSetting.Add(typeName); //添加到已创建索引列表中 infoSetting = new InfoSetting(); string indexes = ""; ShardSpan shardSpan = ShardSpan.Month; bool isShard = false; bool isAdd = true; listInfo.ForEach(info => { if (info.CollectionName == typeName) { isAdd = false; } }); if (isAdd) { //通过反射获取属性 typeLog.GetProperties().ToList().ForEach(property => { property.GetCustomAttributes(typeof(PersistenceColumnAttribute), true).Cast <PersistenceColumnAttribute>().ToList().ForEach(pca => { if (pca.IsIndex) { temp = property.Name + ","; if (indexes.IndexOf(temp) == -1) { indexes += property.Name + ","; } } if (pca.IsShard) { isShard = true; shardSpan = pca.ShardSpan; } }); }); infoSetting.CollectionName = typeName; infoSetting.IndexName = indexes.TrimEnd(','); infoSetting.IsShard = isShard; infoSetting.ShardSpan = shardSpan; listInfo.Add(infoSetting); } } }); SaveSettingToMongoDB(listInfo); } catch (Exception ex) { LogService.Write(ex); } }