private ValidationResult Validate(InstanceRequest instanceRequest) { if (string.IsNullOrEmpty(instanceRequest.InstanceName)) { return(new ValidationResult(false, Constants.SERVER_NAME_SLOT, $"Please enter the instance name you want to operate on")); } if (!string.IsNullOrEmpty(instanceRequest.InstanceName)) { List <string> instanceNames = serverOperationsHelper.validEC2Instances().ConvertAll(x => x.InstanceName); if (!instanceNames.ConvertAll(x => x.ToLower()).Contains(instanceRequest.InstanceName.ToLower())) { return(new ValidationResult(false, Constants.SERVER_NAME_SLOT, $"{instanceRequest.InstanceName} is not a valid instance in your account.\n" + $"Please select one out of the following instances from your account ?\n" + string.Join(" \n ", instanceNames) )); } } if (string.IsNullOrEmpty(instanceRequest.InstanceAction) && !string.IsNullOrEmpty(instanceRequest.InstanceName)) { return(new ValidationResult(false, Constants.ACTION_SLOT, $"Please select the action you want to perform on {instanceRequest.InstanceName}", createResponseCard(Constants.ACTION_SLOT))); } if (string.IsNullOrEmpty(instanceRequest.InstanceAction) && !string.IsNullOrEmpty(instanceRequest.InstanceName)) { return(new ValidationResult(false, Constants.ACTION_SLOT, $"Please select the action you want to perform on {instanceRequest.InstanceName}", createResponseCard(Constants.ACTION_SLOT))); } if (!string.IsNullOrEmpty(instanceRequest.InstanceAction) && !TypeValidators.IsValidActionType(instanceRequest.InstanceAction)) { return(new ValidationResult(false, Constants.ACTION_SLOT, $"I currently do not support {instanceRequest.InstanceAction} as a valid action ." + $"Please select the action you want to perform on {instanceRequest.InstanceName}", createResponseCard(Constants.ACTION_SLOT))); } return(ValidationResult.VALID_RESULT); }
/// <summary> /// Verifies that any values for slots in the intent are valid. /// </summary> /// <param name="reservation"></param> /// <returns></returns> private ValidationResult Validate(Reservation reservation) { if (!string.IsNullOrEmpty(reservation.Location) && !TypeValidators.IsValidCity(reservation.Location)) { return(new ValidationResult(false, LOCATION_SLOT, $"We currently do not support {reservation.Location} as a valid destination. Can you try a different city?")); } if (!string.IsNullOrEmpty(reservation.CheckInDate)) { DateTime checkinDate = DateTime.MinValue; if (!DateTime.TryParse(reservation.CheckInDate, out checkinDate)) { return(new ValidationResult(false, CHECK_IN_DATE_SLOT, "I did not understand your check in date. When would you like to check in?")); } if (checkinDate < DateTime.Today) { return(new ValidationResult(false, CHECK_IN_DATE_SLOT, "Reservations must be scheduled at least one day in advance. Can you try a different date?")); } } if (!string.IsNullOrEmpty(reservation.Nights)) { int nights; if (!int.TryParse(reservation.Nights, out nights)) { return(new ValidationResult(false, NIGHTS_SLOT, "I did not understand the number of nights. Can you enter the number of nights again again?")); } if (nights < 1 || nights > 30) { return(new ValidationResult(false, NIGHTS_SLOT, "You can make a reservations for from one to thirty nights. How many nights would you like to stay for?")); } } return(ValidationResult.VALID_RESULT); }
private ValidationResult Validate(InstanceSetup instanceLaunchRequest) { if (string.IsNullOrEmpty(instanceLaunchRequest.AMIType)) { return(new ValidationResult(false, Constants.AMI_SLOT, "Select an AMI", createResponseCard(Constants.AMI_SLOT))); } if (!string.IsNullOrEmpty(instanceLaunchRequest.AMIType) && !TypeValidators.IsValidAMIType(instanceLaunchRequest.AMIType)) { return(new ValidationResult(false, Constants.AMI_SLOT, $"We currently do not support {instanceLaunchRequest.AMIType} as a valid AMI ." + $"Can you try an AMI out of the following ones ? \n" + TypeValidators.ListOfValidAMITypes(), createResponseCard(Constants.AMI_SLOT) )); } if (string.IsNullOrEmpty(instanceLaunchRequest.StorageType)) { return(new ValidationResult(false, Constants.STORAGE_TYPE_SLOT, "Please enter the Storage type you want to use .", createResponseCard(Constants.STORAGE_TYPE_SLOT))); } if (!string.IsNullOrEmpty(instanceLaunchRequest.StorageType) && !TypeValidators.IsValidStorageType(instanceLaunchRequest.StorageType)) { return(new ValidationResult(false, Constants.STORAGE_TYPE_SLOT, $"I currently do not support {instanceLaunchRequest.StorageType} as a valid Storage Type ." + "Can you try a Storage Type out of the following ones ?", createResponseCard(Constants.STORAGE_TYPE_SLOT) )); } if (string.IsNullOrEmpty(instanceLaunchRequest.InstanceType)) { return(new ValidationResult(false, Constants.INSTANCE_TYPE_SLOT, "Please enter the Instance type you want to use .", createResponseCard(Constants.INSTANCE_TYPE_SLOT))); } if (!string.IsNullOrEmpty(instanceLaunchRequest.InstanceType) && !TypeValidators.IsValidInstanceType(instanceLaunchRequest.InstanceType)) { return(new ValidationResult(false, Constants.INSTANCE_TYPE_SLOT, $"I currently do not support {instanceLaunchRequest.InstanceType} as a valid Instance Type ." + $"Can you try a Instance Type out of the following ones ? {TypeValidators.ListOfValidInstanceTypes()}", createResponseCard(Constants.INSTANCE_TYPE_SLOT))); } if (string.IsNullOrEmpty(instanceLaunchRequest.AvailabilityZone)) { return(new ValidationResult(false, Constants.AZ_SLOT, "Please enter the AZ you want to use .", createResponseCard(Constants.AZ_SLOT))); } if (!string.IsNullOrEmpty(instanceLaunchRequest.AvailabilityZone) && !serverOperationsHelper.getAvailabilityZones().Contains(instanceLaunchRequest.AvailabilityZone)) { return(new ValidationResult(false, Constants.AZ_SLOT, $" {instanceLaunchRequest.AvailabilityZone} is not a valid Availability Zone for your region ." + "Can you try a AZ out of the following ones ? ", createResponseCard(Constants.AZ_SLOT))); } if (instanceLaunchRequest.NumOfInstances == 0) { return(new ValidationResult(false, Constants.NUMBER_TYPE_SLOT, "Please enter the number of instances you want to launch . I currently support a maximum of 5 instances .", createResponseCard(Constants.NUMBER_TYPE_SLOT))); } if (instanceLaunchRequest.NumOfInstances > 5) { return(new ValidationResult(false, Constants.NUMBER_TYPE_SLOT, "I currently only support upto 5 instances. Could you please try with any number between 1 and 5 ", createResponseCard(Constants.NUMBER_TYPE_SLOT))); } return(ValidationResult.VALID_RESULT); }