/// <summary> /// Write a table to the file system /// </summary> /// <param name="tableSchema">The table to write</param> /// <param name="rootFolder">The root folder for all the CSL files</param> public static void WriteToFile(this TableSchema tableSchema, string rootFolder) { string tableFolder = rootFolder; if (!string.IsNullOrEmpty(tableSchema.Folder)) { string cleanedFolder = string.Join("", tableSchema.Folder.Split(Path.GetInvalidPathChars())); tableFolder = Path.Combine(rootFolder, "Tables", cleanedFolder); } string destinationFile = Path.Combine(tableFolder, tableSchema.Name + ".csl"); if (!Directory.Exists(tableFolder)) { Directory.CreateDirectory(tableFolder); } File.WriteAllText(destinationFile, FormattedCslCommandGenerator.GenerateTableCreateCommand(tableSchema, true)); }
/// <summary> /// Create a comparison for the node that was clicked on /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tvComparison_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { string objectName = e.Node.Text; string sourceText = ""; string targetText = ""; if (_sourceSchema.Functions.ContainsKey(objectName) && e.Node.FullPath.StartsWith(_functionTreeNodeText)) { sourceText = CslCommandGenerator.GenerateCreateOrAlterFunctionCommand(_sourceSchema.Functions[objectName], true); } if (_sourceSchema.Tables.ContainsKey(objectName) && e.Node.FullPath.StartsWith(_tablesTreeNodeText)) { sourceText = FormattedCslCommandGenerator.GenerateTableCreateCommand(_sourceSchema.Tables[objectName], true); } if (_targetSchema.Functions.ContainsKey(objectName) && e.Node.FullPath.StartsWith(_functionTreeNodeText)) { targetText = CslCommandGenerator.GenerateCreateOrAlterFunctionCommand(_targetSchema.Functions[objectName], true); } if (_targetSchema.Tables.ContainsKey(objectName) && e.Node.FullPath.StartsWith(_tablesTreeNodeText)) { targetText = FormattedCslCommandGenerator.GenerateTableCreateCommand(_targetSchema.Tables[objectName], true); } var diffBuilder = new InlineDiffBuilder(new Differ()); DiffPlex.DiffBuilder.Model.DiffPaneModel diff = diffBuilder.BuildDiffModel(targetText, sourceText); rtbSourceText.Clear(); int longestLine = 98; if (diff.Lines.Any()) { longestLine = Math.Max(diff.Lines.Max(l => l.Text.Length), longestLine); } foreach (DiffPlex.DiffBuilder.Model.DiffPiece line in diff.Lines) { switch (line.Type) { case DiffPlex.DiffBuilder.Model.ChangeType.Inserted: rtbSourceText.SelectionBackColor = System.Drawing.Color.Yellow; rtbSourceText.SelectedText = line.Text.PadRight(longestLine); break; case DiffPlex.DiffBuilder.Model.ChangeType.Deleted: rtbSourceText.SelectionBackColor = System.Drawing.Color.Red; rtbSourceText.SelectedText = line.Text.PadRight(longestLine); break; case DiffPlex.DiffBuilder.Model.ChangeType.Imaginary: break; default: rtbSourceText.SelectionBackColor = System.Drawing.Color.White; rtbSourceText.SelectedText = line.Text.PadRight(longestLine); break; } rtbSourceText.SelectedText += "\n"; } }
/// <summary> /// Write a table to Kusto /// </summary> /// <param name="tableSchema">The table to write</param> /// <param name="kustoQueryEngine">An initialized query engine for issuing the Kusto command</param> public static void WriteToKusto(this TableSchema tableSchema, QueryEngine kustoQueryEngine) { kustoQueryEngine.CreateOrAlterTableAsync(FormattedCslCommandGenerator.GenerateTableCreateCommand(tableSchema, false), tableSchema.Name).Wait(); }