public bool TryGetInfo(out DeviceCacheInfo info) { EnsureLockOwner(); info = this.cacheStore.GetObject <DeviceCacheInfo>(this.cacheKey); return(info != null); }
public bool Initialize(uint fCntUp = 0, uint fCntDown = 0) { // it is the first message from this device var serverStateForDeviceInfo = new DeviceCacheInfo { FCntDown = fCntDown, FCntUp = fCntUp, GatewayId = this.gatewayId }; return(this.StoreInfo(serverStateForDeviceInfo, true)); }
public bool TryGetInfo(out DeviceCacheInfo info) { info = null; this.EnsureLockOwner(); string cachedFCnt = this.cacheStore.StringGet(this.cacheKey); if (string.IsNullOrEmpty(cachedFCnt)) { return(false); } info = JsonConvert.DeserializeObject <DeviceCacheInfo>(cachedFCnt); return(info != null); }
internal static uint ProcessExistingDeviceInfo(LoRaDeviceCache deviceCache, DeviceCacheInfo cachedDeviceState, string gatewayId, uint clientFCntUp, uint clientFCntDown) { uint newFCntDown = 0; if (cachedDeviceState != null) { // we have a state in the cache matching this device and now we own the lock if (clientFCntUp > cachedDeviceState.FCntUp) { // it is a new message coming up by the first gateway if (clientFCntDown >= cachedDeviceState.FCntDown) { newFCntDown = clientFCntDown + 1; } else { newFCntDown = cachedDeviceState.FCntDown + 1; } cachedDeviceState.FCntUp = clientFCntUp; cachedDeviceState.FCntDown = newFCntDown; cachedDeviceState.GatewayId = gatewayId; deviceCache.StoreInfo(cachedDeviceState); } else if (clientFCntUp == cachedDeviceState.FCntUp && gatewayId == cachedDeviceState.GatewayId) { // it is a retry message coming up by the same first gateway newFCntDown = cachedDeviceState.FCntDown + 1; cachedDeviceState.FCntDown = newFCntDown; deviceCache.StoreInfo(cachedDeviceState); } } return(newFCntDown); }
public bool StoreInfo(DeviceCacheInfo info, bool initialize = false) { this.EnsureLockOwner(); return(this.cacheStore.StringSet(this.cacheKey, JsonConvert.SerializeObject(info), new TimeSpan(1, 0, 0, 0), initialize)); }
public void StoreInfo(DeviceCacheInfo info) { this.EnsureLockOwner(); this.cacheStore.StringSet(this.cacheKey, JsonConvert.SerializeObject(info), new TimeSpan(30, 0, 0, 0)); }