예제 #1
0
        public string GetCurrentStatus(UserSelectedData userSelectedData)
        {
            try
            {
                var client = GetDbClient();

                // get device of location
                var deviceInLocations = GetDevicesInLocation(client, userSelectedData);

                if (deviceInLocations.Any())
                {
                    var rooms = QueryInformationOfRooms(client, deviceInLocations);
                    return(_messageBuilderService.BuildStatusInfoMessage(userSelectedData.KeyInfo, rooms));
                }
                else
                {
                    return(_messageBuilderService.BuildNotFoundMessage(userSelectedData));
                }
            }
            catch (Exception ex)
            {
            }

            return(Resources.Resource.HelpWithInstruction);
        }
예제 #2
0
        public string ProccessWaitingMessage(UserSelectedData userSelectedData)
        {
            (bool isHasLocation, string locationStr) = GetLocationString(userSelectedData);

            if (userSelectedData.IsHasKeyInfo && isHasLocation)
            {
                return(string.Format(Resources.Resource.LookForInforOfDefine, userSelectedData.KeyInfo, locationStr));
            }
            else
            {
                if (userSelectedData.IsHasKeyInfo || isHasLocation)
                {
                    if (userSelectedData.IsHasKeyInfo)
                    {
                        return(string.Format(Resources.Resource.LookForDefine, userSelectedData.KeyInfo));
                    }
                    else
                    {
                        return(string.Format(Resources.Resource.LookForCurrentDefine, locationStr));
                    }
                }
                else
                {
                    return(string.Format(Resources.Resource.HelpNotUnderstand, userSelectedData.LastInputMessage));
                }
            }
        }
예제 #3
0
 public string BuildHelpMessage(UserSelectedData userSelectedData)
 {
     if (!userSelectedData.IsHasKeyInfo && !userSelectedData.IsHasLocationName && !userSelectedData.IsHasRoomName)
     {
         return(Resources.Resource.HelpWithInstruction);
     }
     return(string.Empty);
 }
예제 #4
0
        public static UserSelectedData GetUserSelectedData(IDialogContext context)
        {
            UserSelectedData userSelectedData = null;

            context.UserData.TryGetValue(AppConstants.UserSelectedDataKey, out userSelectedData);
            if (userSelectedData == null)
            {
                userSelectedData = new UserSelectedData();
            }

            return(userSelectedData);
        }
예제 #5
0
        public string BuildNotFoundMessage(UserSelectedData userSelectedData)
        {
            (bool isHasLocation, string locationStr) = GetLocationString(userSelectedData);

            if (isHasLocation)
            {
                return(string.Format(Resources.Resource.HelpNotFoundLocationInput, locationStr));
            }
            else
            {
                return(Resources.Resource.HelpNotFoundLocation);
            }
        }
예제 #6
0
        private (bool isHasLocation, string locationStr) GetLocationString(UserSelectedData userSelectedData)
        {
            var isHasLocation = userSelectedData.IsHasLocationName || userSelectedData.IsHasRoomName;
            var locationStr   = "";

            if (isHasLocation)
            {
                if (userSelectedData.IsHasLocationName && userSelectedData.IsHasRoomName)
                {
                    locationStr = string.Format(Resources.Resource.InDefine2Phrase, userSelectedData.RoomName, userSelectedData.LocationName);
                }
                else
                {
                    locationStr = userSelectedData.IsHasLocationName ? userSelectedData.LocationName : userSelectedData.RoomName;
                }
            }

            return(isHasLocation, locationStr);
        }
예제 #7
0
        private List <DevicesInLocation> GetDevicesInLocation(AmazonDynamoDBClient client, UserSelectedData userSelectedData)
        {
            List <DevicesInLocation> devicesInLocations = new List <DevicesInLocation>();

            if (userSelectedData.IsHasLocationName)
            {
                var keyConditionExpression    = "location_id = :v_locationName";
                var expressionAttributeValues = new Dictionary <string, AttributeValue>
                {
                    { ":v_locationName", new AttributeValue {
                          S = userSelectedData.LocationName
                      } }
                };

                var request = new QueryRequest
                {
                    TableName = "devices-in-location",
                    KeyConditionExpression    = keyConditionExpression,
                    ExpressionAttributeValues = expressionAttributeValues
                };

                var response = client.Query(request);
                devicesInLocations = DevicesInLocationMapper.MapFromResponse(response);
                if (userSelectedData.IsHasRoomName)
                {
                    devicesInLocations = devicesInLocations.Where(c => c.Room.Equals(userSelectedData.RoomName)).ToList();
                }
            }

            return(devicesInLocations);
        }