public static bool FindElementsFromRoot(string body, List <GameObject> rootBag, HttpListenerResponse response) { FindBody findRequest = ParseFindElementBody(body, response); if (findRequest == null) { return(true); } List <Component> found = new List <Component> (); //need to go use all root objects //as context foreach (var rgo in rootBag) { found.AddRange(parser.Evaluate(findRequest.selector, rgo)); } found = found.Distinct().ToList(); //no results found if (found.Count == 0) { if (WebDriverManager.instance.ImplicitTimeout == 0) { WriteEmptyResult(response); return(true); } else { return(false); } } List <string> objs = new List <string> (); //we have results, lets //add them to context foreach (var go in found) { string uuid = System.Guid.NewGuid().ToString(); uuid = WebDriverManager.instance.AddElement(go, uuid); Dictionary <string, string> attributes = ComponentAttributes.Attributes(go.GetType(), go); StringBuilder jsonRepr = new StringBuilder("{"); jsonRepr.AppendFormat("\"name\":\"{0}\",", go.name); foreach (var attr in attributes) { jsonRepr.AppendFormat("\"{0}\":\"{1}\", ", attr.Key, attr.Value); } jsonRepr.AppendFormat("\"{0}\":\"{1}\"", WebElementIdentifierKey, uuid); jsonRepr.Append("}"); objs.Add(jsonRepr.ToString()); } WriteElementList(response, objs); return(true); }
private static bool FindElementFromRoot(string body, List <GameObject> root, HttpListenerResponse response) { FindBody findRequest = ParseFindElementBody(body, response); if (findRequest == null) { return(true); } Component found = null; //need to go use all root objects //as context foreach (var rgo in root) { var resp = parser.Evaluate(findRequest.selector, rgo); if (resp.Count != 0) { found = resp [0]; break; } } //no results found if (found == null) { if (WebDriverManager.instance.ImplicitTimeout == 0) { WebDriverManager.instance.WriteElementNotFound(response); return(true); } else { return(false); } } string uuid = System.Guid.NewGuid().ToString(); uuid = WebDriverManager.instance.AddElement(found, uuid); Dictionary <string, string> attributes = ComponentAttributes.Attributes(found.GetType(), found); StringBuilder jsonRepr = new StringBuilder("{"); jsonRepr.AppendFormat("\"name\":\"{0}\",", found.name); foreach (var attr in attributes) { jsonRepr.AppendFormat("\"{0}\":\"{1}\", ", attr.Key, attr.Value); } jsonRepr.AppendFormat("\"{0}\":\"{1}\"", WebElementIdentifierKey, uuid); jsonRepr.Append("}"); WriteElementList(response, new List <string> { jsonRepr.ToString() }); return(true); }