public WolframAlphaQueryResult LoadResponse(string Response) { XmlDocument Document = new XmlDocument(); WolframAlphaQueryResult Result = null; try { Document.LoadXml(Response); Result = LoadResponse(Document); } catch { } Document = null; return(Result); }
private void ShowResult(WolframAlphaQueryResult result) { //textBoxOutput.AppendText("Детали ответа\r\n"); //textBoxOutput.AppendText("Ветвей найдено: " + result.NumberOfPods + "\r\n"); //textBoxOutput.AppendText("Время разбора: " + result.ParseTiming + " сек.\r\n"); //textBoxOutput.AppendText("Время выполнения: " + result.Timing + " сек.\r\n"); //textBoxOutput.AppendText("=============================\r\n"); //textBoxOutput.Clear(); //labelPodsFound.Text = result.NumberOfPods.ToString(); //labelExecTime.Text = result.ParseTiming + "/" + result.Timing; Int32 PodNumber = 1; int nexty = 3; foreach (WolframAlphaPod Item in result.Pods) { //textBoxOutput.AppendText("\r\n"); //textBoxOutput.AppendText("Ветвь " + PodNumber + "\r\n"); //textBoxOutput.AppendText("Саб-ветвей: " + Item.NumberOfSubPods + "\r\n"); //textBoxOutput.AppendText("Заголовок: \"" + Item.Title + "\"\r\n"); //textBoxOutput.AppendText("Позиция: " + Item.Position + "\r\n"); ShowedPods.Add(new WolframPod(Item.Title)); this.panelContent.Controls.Add(ShowedPods.Last()); ShowedPods.Last().Location = new Point(3, nexty); if (nexty + ShowedPods.Last().Height > panelContent.Height) { ShowedPods.Last().Width = panelContent.Width - 10 - 17; } else { ShowedPods.Last().Width = panelContent.Width - 10; } ShowedPods.Last().Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; nexty += ShowedPods.Last().Height + 3; Int32 SubPodNumber = 1; foreach (WolframAlphaSubPod SubItem in Item.SubPods) { //textBoxOutput.AppendText("\r\n"); //textBoxOutput.AppendText(">Саб-ветвь " + SubPodNumber + "\r\n"); //textBoxOutput.AppendText(">Заголовок: \"" + SubItem.Title + "\"\r\n"); //textBoxOutput.AppendText(">Содержимое: \"" + SubItem.PodText + "\"\r\n"); if (SubItem.PodImage == null) { ShowedPods.Add(new WolframPod(SubItem.Title, SubItem.PodText)); panelContent.Controls.Add(ShowedPods.Last()); ShowedPods.Last().Location = new Point(3, nexty); if (nexty + ShowedPods.Last().Height > panelContent.Height) { ShowedPods.Last().Width = panelContent.Width - 10 - 17; } else { ShowedPods.Last().Width = panelContent.Width - 10; } ShowedPods.Last().Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; } else { ShowedPods.Add(new WolframPod(SubItem.Title, SubItem.PodText, SubItem.PodImage.Location.ToString())); panelContent.Controls.Add(ShowedPods.Last()); ShowedPods.Last().Location = new Point(3, nexty); if (nexty + ShowedPods.Last().Height > panelContent.Height) { ShowedPods.Last().Width = panelContent.Width - 10 - 17; } else { ShowedPods.Last().Width = panelContent.Width - 10; } ShowedPods.Last().Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; } nexty += ShowedPods.Last().Height + 3; /*if (SubItem.PodImage != null) * { * textBoxOutput.AppendText(">>Заголовок изображения: \"" + SubItem.PodImage.Title + "\"\r\n"); * textBoxOutput.AppendText(">>Ширина изображения: " + SubItem.PodImage.Width + "\r\n"); * textBoxOutput.AppendText(">>Высота изображения: " + SubItem.PodImage.Height + "\r\n"); * textBoxOutput.AppendText(">>Путь к изображению: \"" + SubItem.PodImage.Location.ToString() + "\"\r\n"); * textBoxOutput.AppendText(">>Описание к изображению: \"" + SubItem.PodImage.HoverText + "\"\r\n"); * }*/ SubPodNumber += 1; } PodNumber += 1; } ShowedPods.Add(new WolframPod("Info", "Pods: " + result.NumberOfPods.ToString() + "; Execute time: " + result.Timing, false)); this.panelContent.Controls.Add(ShowedPods.Last()); ShowedPods.Last().Location = new Point(3, nexty); if (nexty + ShowedPods.Last().Height > panelContent.Height) { ShowedPods.Last().Width = panelContent.Width - 10 - 17; } else { ShowedPods.Last().Width = panelContent.Width - 10; } ShowedPods.Last().Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelContent.Visible = true; panelLoading.Visible = false; }
public WolframAlphaQueryResult LoadResponse(XmlDocument Response) { System.Threading.Thread.Sleep(1); XmlNode MainNode = Response.SelectNodes("/queryresult")[0]; WA_QueryResult = new WolframAlphaQueryResult(); WA_QueryResult.Success = MainNode.Attributes["success"].Value.toBool(); WA_QueryResult.ErrorOccured = MainNode.Attributes["error"].Value.toBool(); WA_QueryResult.NumberOfPods = MainNode.Attributes["numpods"].Value.toInt(); WA_QueryResult.Timing = MainNode.Attributes["timing"].Value.toDouble(); WA_QueryResult.TimedOut = MainNode.Attributes["timedout"].Value; WA_QueryResult.DataTypes = MainNode.Attributes["datatypes"].Value; WA_QueryResult.Pods = new List<WolframAlphaPod>(); foreach (XmlNode Node in MainNode.SelectNodes("pod")) { System.Threading.Thread.Sleep(1); WolframAlphaPod Pod = new WolframAlphaPod(); Pod.Title = Node.Attributes["title"].Value; Pod.Scanner = Node.Attributes["scanner"].Value; Pod.Position = Node.Attributes["position"].Value.toInt(); Pod.ErrorOccured = Node.Attributes["error"].Value.toBool(); Pod.NumberOfSubPods = Node.Attributes["numsubpods"].Value.toInt(); Pod.SubPods = new List<WolframAlphaSubPod>(); foreach (XmlNode SubNode in Node.SelectNodes("subpod")) { System.Threading.Thread.Sleep(1); WolframAlphaSubPod SubPod = new WolframAlphaSubPod(); SubPod.Title = SubNode.Attributes["title"].Value; foreach (XmlNode ContentNode in SubNode.SelectNodes("plaintext")) { System.Threading.Thread.Sleep(1); SubPod.PodText = ContentNode.InnerText; } foreach (XmlNode ContentNode in SubNode.SelectNodes("img")) { System.Threading.Thread.Sleep(1); WolframAlphaImage Image = new WolframAlphaImage(); Image.Location = new Uri(ContentNode.Attributes["src"].Value); Image.HoverText = ContentNode.Attributes["alt"].Value; Image.Title = ContentNode.Attributes["title"].Value; Image.Width = ContentNode.Attributes["width"].Value.toInt(); Image.Height = ContentNode.Attributes["height"].Value.toInt(); SubPod.PodImage = Image; } Pod.SubPods.Add(SubPod); } WA_QueryResult.Pods.Add(Pod); } return WA_QueryResult; }
public WolframAlphaQueryResult LoadResponse(XmlDocument Response) { System.Threading.Thread.Sleep(1); XmlNode MainNode = Response.SelectNodes("/queryresult")[0]; WA_QueryResult = new WolframAlphaQueryResult(); WA_QueryResult.Success = MainNode.Attributes["success"].Value.toBool(); WA_QueryResult.ErrorOccured = MainNode.Attributes["error"].Value.toBool(); WA_QueryResult.NumberOfPods = MainNode.Attributes["numpods"].Value.toInt(); WA_QueryResult.Timing = MainNode.Attributes["timing"].Value.toDouble(); WA_QueryResult.TimedOut = MainNode.Attributes["timedout"].Value; WA_QueryResult.DataTypes = MainNode.Attributes["datatypes"].Value; WA_QueryResult.Pods = new List <WolframAlphaPod>(); foreach (XmlNode Node in MainNode.SelectNodes("pod")) { System.Threading.Thread.Sleep(1); WolframAlphaPod Pod = new WolframAlphaPod(); Pod.Title = Node.Attributes["title"].Value; Pod.Scanner = Node.Attributes["scanner"].Value; Pod.Position = Node.Attributes["position"].Value.toInt(); Pod.ErrorOccured = Node.Attributes["error"].Value.toBool(); Pod.NumberOfSubPods = Node.Attributes["numsubpods"].Value.toInt(); Pod.SubPods = new List <WolframAlphaSubPod>(); foreach (XmlNode SubNode in Node.SelectNodes("subpod")) { System.Threading.Thread.Sleep(1); WolframAlphaSubPod SubPod = new WolframAlphaSubPod(); SubPod.Title = SubNode.Attributes["title"].Value; foreach (XmlNode ContentNode in SubNode.SelectNodes("plaintext")) { System.Threading.Thread.Sleep(1); SubPod.PodText = ContentNode.InnerText; } foreach (XmlNode ContentNode in SubNode.SelectNodes("img")) { System.Threading.Thread.Sleep(1); WolframAlphaImage Image = new WolframAlphaImage(); Image.Location = new Uri(ContentNode.Attributes["src"].Value); Image.HoverText = ContentNode.Attributes["alt"].Value; Image.Title = ContentNode.Attributes["title"].Value; Image.Width = ContentNode.Attributes["width"].Value.toInt(); Image.Height = ContentNode.Attributes["height"].Value.toInt(); SubPod.PodImage = Image; } Pod.SubPods.Add(SubPod); } WA_QueryResult.Pods.Add(Pod); } return(WA_QueryResult); }