예제 #1
0
        public String ConvertToCode(String luisIntentJson)
        {
            StringBuilder sbCode = new StringBuilder();


            JObject jObject = JObject.Parse(luisIntentJson);

            string topIntent = (string)jObject["prediction"]["topIntent"];

            switch (topIntent)
            {
            case "openWebPage":
                string page = (string)jObject["prediction"]["entities"]["webpage"].First;
                sbCode.Append(codeGenerator.ImportLib());
                sbCode.Append(codeGenerator.OpenWebPageCode(BrowserType.Firefox, page));
                break;

            case "typeSomething":
                string findAttribute = (string)jObject["prediction"]["entities"]["elementAttribute"].First;
                string typedText     = (string)jObject["prediction"]["entities"]["typedText"].First;
                typedText = typedText.Replace(@"""", "");
                if (findAttribute.StartsWith("name"))
                {
                    sbCode.Append(codeGenerator.FindElementByCode(FindElementAttribute.find_element_by_name, findAttribute.Split("=")[1]));
                    sbCode.Append(codeGenerator.TypeSomething(codeGenerator.CurrentElementName, typedText));
                }
                else if (findAttribute.StartsWith("id"))
                {
                    sbCode.Append(codeGenerator.FindElementByCode(FindElementAttribute.find_element_by_id, findAttribute.Split("=")[1]));
                    sbCode.Append(codeGenerator.TypeSomething(codeGenerator.CurrentElementName, typedText));
                }
                else if (findAttribute.StartsWith("xpath"))
                {
                    sbCode.Append(codeGenerator.FindElementByCode(FindElementAttribute.find_element_by_xpath, findAttribute.Split("=")[1]));
                    sbCode.Append(codeGenerator.TypeSomething(codeGenerator.CurrentElementName, typedText));
                }
                break;

            case "submitPage":
                string currentElement = codeGenerator.CurrentElementName;
                sbCode.Append(codeGenerator.Submit(currentElement));
                break;

            default:
                break;
            }

            return(sbCode.ToString());
        }