public static async Task <UserInputInfo> ParseUserInput(string input) { UserInputInfo userInput = null; using (var client = new HttpClient()) { string LuisKey = Config.LuisConfig.LuisKey; string LuisAppId = Config.LuisConfig.LuisAppId; //string LuisURL = Config.LuisConfig.LuisURL; //from the user string query = Uri.EscapeDataString(input); string uri = $"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/{LuisAppId}?subscription-key={LuisKey}&q={query}&verbose=true"; try { var response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); var data = await response.Content.ReadAsStringAsync(); userInput = JsonConvert.DeserializeObject <UserInputInfo>(data); }catch (Exception ex) { } return(userInput); } }
public UserInputInfo IsValid(string treeDepth, string predicatedContainerIndex) { UserInputInfo userInputInfo = null; if (string.IsNullOrEmpty(treeDepth)) { Console.WriteLine($"Please enter a valid number {nameof(treeDepth)}."); return(userInputInfo); } if (!int.TryParse(treeDepth, out int _treeDepth) || _treeDepth <= 0) { Console.WriteLine("Tree depth must be a positive number."); return(userInputInfo); } if (string.IsNullOrEmpty(predicatedContainerIndex)) { Console.WriteLine($"Please enter a valid number {nameof(predicatedContainerIndex)}."); return(userInputInfo); } if (!int.TryParse(predicatedContainerIndex, out int _predicatedContainerIndex) || _predicatedContainerIndex <= 0) { Console.WriteLine("Predicated Container Index must be a positive number."); return(userInputInfo); } if (_predicatedContainerIndex > Math.Pow(2, _treeDepth)) { Console.WriteLine("The predicated container index should be less tha power of tree depth"); return(userInputInfo); } userInputInfo = new UserInputInfo { IsSuccess = true, Depth = _treeDepth, PredicatedContainerIndex = _predicatedContainerIndex }; return(userInputInfo); }