Beispiel #1
0
        /// <summary>
        /// 检查指定实体的Hash值,决定是否需要进行数据库同步
        /// </summary>
        public static bool CheckSyncByHash(this IEnumerable <IEntityHash> entityHashes, IServiceProvider provider, ILogger logger)
        {
            IEntityHash[] hashes = entityHashes as IEntityHash[] ?? entityHashes.ToArray();
            if (hashes.Length == 0)
            {
                return(false);
            }
            string         hash       = hashes.Select(m => m.GetHash()).ExpandAndToString().ToMd5Hash();
            IKeyValueStore store      = provider.GetService <IKeyValueStore>();
            string         entityType = hashes[0].GetType().FullName;
            string         key        = $"Dze.Initialize.SyncToDatabaseHash-{entityType}";
            IKeyValue      keyValue   = store.GetKeyValue(key);

            if (keyValue != null && keyValue.Value?.ToString() == hash)
            {
                logger.LogInformation($"{hashes.Length}条基础数据“{entityType}”的内容签名 {hash} 与上次相同,取消数据库同步");
                return(false);
            }
            OperationResult result = store.CreateOrUpdateKeyValue(key, hash).Result;

            logger.LogInformation($"{hashes.Length}条基础数据“{entityType}”的内容签名 {hash} 与上次 {keyValue?.Value} 不同,将进行数据库同步");
            return(true);
        }