示例#1
0
        public RestHandlerResult DoDeviceListing()
        {
            var result  = new RestHandlerResult(_log);
            var request = RequestBasis(UserListDevices, Method.GET);

            try
            {
                result.Response = _client.Execute(request);
            }
            catch (Exception e)
            {
                _log.Error($"Could not fetch devices from Melcloud: {e.Message}");
                result.Error = e.Message;
            }

            if (result.ResponseIsOk())
            {
                result.Success = true;
            }
            else
            {
                if (!string.IsNullOrEmpty(result.Response.ErrorMessage))
                {
                    result.Error = result.Response.ErrorMessage;
                }
            }

            return(result);
        }
示例#2
0
        public RestHandlerResult UpdateDevice(object jsonObject)
        {
            var result  = new RestHandlerResult(_log);
            var request = RequestBasis(DeviceSetAta);

            request.AddJsonBody(jsonObject);

            try
            {
                result.Response = _client.Execute(request);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result.Error = $"Tried to save device to Melcloud but got an error: {e.Message}";
            }

            if (result.ResponseIsOk())
            {
                result.Success = true;
            }
            return(result);
        }
示例#3
0
        public RestHandlerResult DoDeviceGet(JToken deviceId, JToken buildingId)
        {
            var result  = new RestHandlerResult(_log);
            var request = RequestBasis(DeviceGet, Method.GET);

            request.AddParameter("id", deviceId);
            request.AddParameter("buildingID", buildingId);

            try
            {
                result.Response = _client.Execute(request);
            }
            catch (Exception e)
            {
                _log.Error($"Could not fetch data for updating devices from Melcloud: {e.Message}");
                result.Error = e.Message;
            }

            if (result.ResponseIsOk())
            {
                result.Success = true;
            }
            return(result);
        }