コード例 #1
0
        public static bool TryGetTdPickTime(this IRedisClient redisClient, BaseTransducer td, out DateTime?resultTime)
        {
            resultTime = null;
            var timeStr = string.Empty;

            switch (td.GetType().Name)
            {
            case nameof(SpeedTransducer):
                timeStr = redisClient.GetValue($"{{{td.Guid.ToFormatedString()}}}_SPEED_PICKDATE");
                break;

            case nameof(NonVibraTransducer):
                timeStr = redisClient.GetValue("IntouchUpdateTime");
                break;

            case nameof(VibraTransducer):
                timeStr = redisClient.GetValue("IntouchUpdateTime");
                break;
            }

            if (string.IsNullOrEmpty(timeStr))
            {
                Log.Warn($"无法读取 {td.Guid} 的更新时间");
                return(false);
            }

            timeStr = timeStr.Replace("\"", string.Empty);
            DateTime time;

            if (DateTime.TryParse(timeStr, out time))
            {
                resultTime = time;
            }
            return(true);
        }
コード例 #2
0
        public static bool IsTdDataUpdated(this IRedisClient redisClient, BaseTransducer td)
        {
            DateTime?time;

            if (redisClient.TryGetTdPickTime(td, out time))
            {
                //第一次进来是空,赋值, 并认为数值更新
                if (td.DataUpdateTime == null)
                {
                    td.DataUpdateTime = time;
                    return(true);
                }

                //时间相差大于1秒,则认为时间不同, 数值更新
                if (time - td.DataUpdateTime > TimeSpan.FromSeconds(1))
                {
                    td.DataUpdateTime = time;
                    Log.Inform($"{td.NameRemark}[传感器] {td.Code}已更新数据({td.DataUpdateTime})");
                    return(true);
                }
            }
            return(false);
        }