public async Task <string> GetStatus(string DeviceName, string RoomName)
        {
            string retVal = String.Empty;

            if (IsRoomControllerAlive(RoomName).Result < 1)
            {
                retVal = "The controller for " + RoomName + " is not responding at the moment. Please check the controller.";
            }
            else
            {
                ExtServiceHelper service = new ExtServiceHelper();
                string           baseUri = "https://homeautomationapi.azurewebsites.net/api/home/";
                string           method  = "GetRoomDeviceStatus?RoomName=" + ReplaceAllSpaces(RoomName);

                try
                {
                    string roomStatus = service.GetDataFromService(baseUri, method, new List <object> {
                        null
                    }).Result;
                    retVal = roomStatus.Replace("=", " is ");
                }
                catch (Exception exp)
                {
                    retVal = "An error occurred while executing that operation.";
                }
            }
            return(retVal);
        }
        public async Task <string> OperateDevice(string DeviceName, string RoomName, string NewState)
        {
            string retVal = String.Empty;

            if (IsRoomControllerAlive(RoomName).Result < 1)
            {
                retVal = "The controller for " + RoomName + " is not responding at the moment. Please check the controller.";
            }
            else
            {
                ExtServiceHelper service = new ExtServiceHelper();
                string           baseUri = "https://homeautomationapi.azurewebsites.net/api/home/";
                string           method  = "GetUpdatedDeviceState?DeviceName=" + DeviceName + "&RoomName=" + ReplaceAllSpaces(RoomName) + "&NewState=" + (NewState.Equals("ON", StringComparison.CurrentCultureIgnoreCase) ? 1 : 0);
                try
                {
                    loggerGlobal.LogLine("Invoking room controller operation: " + baseUri + method);
                    string roomStatus = service.GetDataFromService(baseUri, method, new List <object> {
                        null
                    }).Result;
                    loggerGlobal.LogLine("Controller operation response: " + roomStatus);
                    retVal = "Done";
                }
                catch (Exception exp)
                {
                    retVal = "An error occurred while executing that operation.";
                }
            }
            return(retVal);
        }
        private async Task <int> IsRoomControllerAlive(string RoomName)
        {
            ExtServiceHelper service = new ExtServiceHelper();
            string           baseUri = "https://homeautomationapi.azurewebsites.net/api/home/";
            string           method  = "GetIsControllerAlive?RoomName=" + ReplaceAllSpaces(RoomName);
            string           retVal  = String.Empty;
            int result = -1;

            try
            {
                string roomStatus = service.GetDataFromService(baseUri, method, new List <object> {
                    null
                }).Result;
                loggerGlobal.LogLine("Checking controller heartbeat: " + baseUri + method);
                loggerGlobal.LogLine("Heartbeat status: " + roomStatus);
                int.TryParse(roomStatus, out result);
            }
            catch (Exception exp)
            {
                retVal = "An error occurred while executing that operation.";
            }
            loggerGlobal.LogLine("Final Heartbeat status: " + result);
            return(result);
        }