/// <summary> /// make the entity hash data fields according to configuration. /// Example: config is : ssg_person, ssg_firstname|ssg_lastname /// ssg_person person1: firstname="person1", lastname="lastname1" /// it should return SHA512("person1lastname1") /// This is mainly used for Person /// </summary> /// <param name="entity"></param> /// <returns>SHA512 </returns> public async Task <string> GetDuplicateDetectHashData(object entity) { if (_configs == null) { await GetDuplicateDetectionConfig(CancellationToken.None); } Type type = entity.GetType(); string name; if (!EntityNameMap.TryGetValue(type.Name, out name)) { return(null); } SSG_DuplicateDetectionConfig config = _configs.FirstOrDefault(m => m.EntityName == name); if (config == null) { return(null); } IList <PropertyInfo> props = new List <PropertyInfo>(type.GetProperties()); return(hashstring(GetConcateFieldsStr(config.DuplicateFieldList, props, entity))); }
/// <summary> /// This is to compare if an entity obj is the same as ssg obj. same means the configed properties are same value /// </summary> /// <param name="entity"></param> /// <param name="ssg"></param> /// <returns></returns> public async Task <bool> Same(object entity, object ssg) { if (entity == null && ssg == null) { return(true); } if (entity == null || ssg == null) { return(false); } if (_configs == null) { await GetDuplicateDetectionConfig(CancellationToken.None); } Type type = entity.GetType(); string ssgName; if (!EntityNameMap.TryGetValue(type.Name, out ssgName)) { return(false); } if (!ssgName.Equals(ssg.GetType().Name, StringComparison.InvariantCultureIgnoreCase)) { return(false); } SSG_DuplicateDetectionConfig config = _configs.FirstOrDefault(m => m.EntityName.ToLower() == ssgName.ToLower()); if (config == null) { return(false); } IList <PropertyInfo> props = new List <PropertyInfo>(type.GetProperties()); string entityStr = GetConcateFieldsStr(config.DuplicateFieldList, props, entity); string ssgStr = GetConcateFieldsStr(config.DuplicateFieldList, props, ssg); return(entityStr.Equals(ssgStr, StringComparison.InvariantCultureIgnoreCase)); }