/// <summary> /// 获取Model的属性对象,获取第一次后会放入一个缓存列表中 /// 即只反射一次 /// </summary> public Dictionary <string, FieldAttribute> GetEntityAttribute <T>() where T : BaseEntity { Type t = typeof(T); if (!EntityAttributeCache.ContainsKey(t)) { lock (LockObj2) { if (!EntityAttributeCache.ContainsKey(t)) { var attrs = GetModelParam <T>(); EntityAttributeCache.Add(t, attrs); } } } return(EntityAttributeCache[t]); //Type t = typeof(T); //if (EntityAttributeCache.ContainsKey(t)) //{ // return EntityAttributeCache[t]; //} //var attrs = GetModelParam<T>(); //EntityAttributeCache.Add(t, attrs); //return attrs; }
public void ProcessEntity(EntityWrapper entity, int passNumber, int maxPassNumber) { try { entity.ThrowArgumentNullExceptionIfNull(nameof(entity)); lock (this) { if (!this.cachedRecords.ContainsKey(entity.LogicalName)) { var cache = new EntityAttributeCache(this.targetRepo.GetCurrentOrgService, entity.LogicalName, (from a in entity.OriginalEntity.Attributes where !(a.Value is AliasedValue) select a.Key).ToArray()); cache.LoadAllRecords(); this.cachedRecords[entity.LogicalName] = cache; } } if (entity.OperationType != OperationType.Ignore) { lock (this) { var cache = this.cachedRecords[entity.LogicalName]; var fields = (from a in entity.OriginalEntity.Attributes select new KeyValuePair <string, string>(a.Key, EntityAttributeCache.GetFieldValueAsText(a.Value))).ToArray(); if (cache.MatchCachedEntityAttributes(entity.Id, fields)) { entity.OperationType = OperationType.Ignore; logger.LogInfo($"Skipping {entity.LogicalName} {entity.OriginalEntity.Id}"); } } } } catch (Exception ex) { logger.LogError($"{GetType().FullName}: Processing Error", ex); throw; } }