Exemple #1
0
        public async Task <Device> GetDeviceAsync(Guid uuid, DeviceGetModes getMode = DeviceGetModes.DeviceOnly, bool allowCache = true)
        {
            if (allowCache && _cachedDevices != null && _cachedDevices.ContainsKey(uuid))
            {
                return(_cachedDevices[uuid]);
            }

            string resource = "devices/" + uuid;

            if (getMode == DeviceGetModes.IncludeState)
            {
                resource += "?state=true";
            }
            if (getMode == DeviceGetModes.IncludeAllInfo)
            {
                resource += "?full=true";
            }

            var request = new RestRequest(resource, HttpMethod.Get);


            var result = await _httpClient.ExecuteWithPolicyAsync <Device>(this, request);

            if (_cachedDevices == null)
            {
                _cachedDevices = new Dictionary <Guid, Device>();
            }

            if (_cachedDevices.ContainsKey(uuid))
            {
                _cachedDevices.Remove(uuid);
            }
            if (allowCache)
            {
                _cachedDevices.Add(uuid, result);
            }
            return(result);
        }
        public async Task<Device> GetDeviceAsync(Guid uuid, DeviceGetModes getMode = DeviceGetModes.DeviceOnly, bool allowCache = true)
        {
            

            if (allowCache && _cachedDevices != null && _cachedDevices.ContainsKey(uuid))
                return _cachedDevices[uuid];

            string resource = "devices/" + uuid;
            if (getMode == DeviceGetModes.IncludeState)
                resource += "?state=true";
            if (getMode == DeviceGetModes.IncludeAllInfo)
                resource += "?full=true";

            var request = new RestRequest(resource, HttpMethod.Get);

            
            var result = await _httpClient.ExecuteWithPolicyAsync<Device>(this, request);

            if (_cachedDevices == null)
                _cachedDevices = new Dictionary<Guid, Device>();

            if (_cachedDevices.ContainsKey(uuid))
                _cachedDevices.Remove(uuid);
            if (allowCache)
            {
                _cachedDevices.Add(uuid, result);
            }
            return result;
        }