/// <summary>Execute the command.</summary> public override void Execute() { IQueryBatchProvider batchProvider = HostWindow.ActiveChildForm as IQueryBatchProvider; if (batchProvider == null) { HostWindow.DisplaySimpleMessageBox(null, "No results to save as a 'DataSet'.", "Save Results as DataSet XML Error"); } else { DataSet ds = null; if (batchProvider.Batch != null) { if (batchProvider.Batch.Queries.Count > 1) { BatchQuerySelectForm querySelectForm = Services.Resolve <BatchQuerySelectForm>(); querySelectForm.Fill(batchProvider.Batch); querySelectForm.ShowDialog(); if (querySelectForm.DialogResult == DialogResult.OK) { ds = querySelectForm.SelectedQuery.Result; } } else if (batchProvider.Batch.Queries.Count == 1) { ds = batchProvider.Batch.Queries[0].Result; } } if (ds == null) { return; } using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Title = "Save Results as DataSet XML"; saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); saveFileDialog.Filter = Properties.Settings.Default.XmlFileDialogFilter; if (saveFileDialog.ShowDialog(HostWindow.Instance) == DialogResult.OK) { ds.WriteXml(saveFileDialog.FileName, XmlWriteMode.WriteSchema); string msg = string.Format("Saved results to file: '{0}'", saveFileDialog.FileName); HostWindow.SetStatus(HostWindow.ActiveChildForm, msg); } } } }
protected void RunExportSqlCe(string fileName) { string file = Path.GetTempFileName() + ".sql"; string conn = Settings.ConnectionDefinition.ConnectionString.Replace(@"""", @"\"""); string arguments = string.Format("\"{0}\" \"{1}\"", conn, file); var tool = new Process(); tool.StartInfo.FileName = fileName; tool.StartInfo.Arguments = arguments; tool.StartInfo.UseShellExecute = false; tool.StartInfo.RedirectStandardOutput = true; tool.StartInfo.RedirectStandardError = true; if (tool.Start()) { string output = tool.StandardOutput.ReadToEnd(); string err = tool.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(err)) { output = "ERROR:" + Environment.NewLine + err + Environment.NewLine + output; } if (File.Exists(file)) { IEditor editor = Services.Resolve <IFileEditorResolver>().ResolveEditorInstance(file); editor.FileName = file; editor.LoadFile(); HostWindow.DisplayDockedForm(editor as DockContent); } else { var sb = new StringBuilder(); sb.AppendLine("Error generating the output file."); sb.AppendLine("Process Info:"); sb.AppendFormat(" File Name: {0}", tool.StartInfo.FileName); sb.AppendLine(); sb.AppendFormat(" Arguments: {0}", tool.StartInfo.Arguments); sb.AppendLine(); sb.AppendLine(output); output = sb.ToString(); } if (!string.IsNullOrEmpty(output)) { HostWindow.DisplaySimpleMessageBox(null, output, fileName + " Output"); } } }