private void CopyPlanToClipboard() { ShowPlan showPlan = _query.GetShowPlan(); using (StringWriter sw = new StringWriter()) { XmlTextWriter xmlTextWriter = new XmlTextWriter(sw); showPlan.ToXml().WriteContentTo(xmlTextWriter); Clipboard.SetText(sw.ToString()); } }
private void SavePlan() { if (savePlanFileDialog.ShowDialog() == DialogResult.OK) { ShowPlan showPlan = _query.GetShowPlan(); if (savePlanFileDialog.FilterIndex == 0) { showPlan.ToXml().Save(savePlanFileDialog.FileName); } else { using (StreamWriter sw = new StreamWriter(savePlanFileDialog.FileName)) showPlan.WriteTo(sw, 2); } } }
private void ExportTestDefinition() { if (saveTestDefinitionFileDialog.ShowDialog() == DialogResult.OK) { Text = String.Format("NQuery - [{0}]", Path.GetFileName(saveTestDefinitionFileDialog.FileName)); CompilationErrorCollection compilationErrors = null; RuntimeException runtimeException = null; DataTable result = null; ShowPlan showPlan = null; Query query = new Query(); query.DataContext = _query.DataContext; query.Text = syntaxEditor.Text; try { result = query.ExecuteDataTable(); showPlan = query.GetShowPlan(); } catch (RuntimeException ex) { runtimeException = ex; } catch (CompilationException ex) { compilationErrors = ex.CompilationErrors; } XmlDocument testDefinition = new XmlDocument(); XmlNode rootNode = testDefinition.CreateElement("test"); testDefinition.AppendChild(rootNode); XmlNode sqlNode = testDefinition.CreateElement("sql"); sqlNode.InnerText = syntaxEditor.Text; rootNode.AppendChild(sqlNode); if (runtimeException != null) { XmlNode expectedRuntimeErrorNode = testDefinition.CreateElement("expectedRuntimeError"); rootNode.AppendChild(expectedRuntimeErrorNode); expectedRuntimeErrorNode.InnerText = runtimeException.Message; } else if (compilationErrors != null) { XmlNode expectedErrorsNode = testDefinition.CreateElement("expectedErrors"); rootNode.AppendChild(expectedErrorsNode); foreach (CompilationError error in compilationErrors) { XmlNode errorNode = testDefinition.CreateElement("expectedError"); XmlAttribute idAtt = testDefinition.CreateAttribute("id"); idAtt.Value = error.Id.ToString(); errorNode.Attributes.Append(idAtt); XmlAttribute textAtt = testDefinition.CreateAttribute("text"); textAtt.Value = error.Text; errorNode.Attributes.Append(textAtt); expectedErrorsNode.AppendChild(errorNode); } } if (result != null) { XmlNode resultsNode = testDefinition.CreateElement("expectedResults"); rootNode.AppendChild(resultsNode); StringBuilder sb = new StringBuilder(); using (StringWriter stringWriter = new StringWriter(sb)) { DataSet dataSet = new DataSet(); dataSet.Tables.Add(result); dataSet.WriteXml(stringWriter, XmlWriteMode.WriteSchema); } resultsNode.InnerXml = sb.ToString(); } if (showPlan != null) { XmlNode planNode = testDefinition.CreateElement("expectedPlan"); rootNode.AppendChild(planNode); XmlNode executionPlanNode = testDefinition.ImportNode(showPlan.ToXml().SelectSingleNode("executionPlan"), true); planNode.AppendChild(executionPlanNode); } testDefinition.Save(saveTestDefinitionFileDialog.FileName); } }