private void DisplayPattern(object o, EventArgs e) { // Retrieve all the info for the pattern name from memory (from the list of patterns) var loadPattern = VedwConfigurationSettings.patternList.FirstOrDefault(x => x.LoadPatternName == localComboBoxGenerationPattern.Text); // Set the label with the path so it's visible to the user where the file is located string localFullPath = Path.Combine(VedwConfigurationSettings.LoadPatternListPath, loadPattern.LoadPatternFilePath); localLabelFullFilePath.Text = localFullPath; //Path.Combine(Environment.CurrentDirectory, "Some\\Path.txt")); // Read the file from the path string loadPatternTemplate = ""; try { loadPatternTemplate = File.ReadAllText(localFullPath); } catch { loadPatternTemplate = $"There was an error loading the pattern specified in the load pattern collection file.\r\n\r\nDoes '{loadPattern.LoadPatternFilePath}' exist and is the path correct?\r\n\r\nIf this is not the case please update the load pattern collection information in the 'settings' tab."; } // Display the pattern in the text box on the screen localRichTextBoxGenerationPattern.Text = loadPatternTemplate; // Syntax highlight for Handlebars if (startUpIndicator == false) { TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text); } }
public void SyntaxHighlight() { TextHandling.SyntaxHighlightSql(localRichTextBoxGenerationOutput, localRichTextBoxGenerationOutput.Text); }
public void SyntaxHighlightsHandlebars(object sender, EventArgs e) { TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text.TrimEnd()); }
/// <summary> /// Function can be called from the main form as well this wya. /// </summary> public void ApplySyntaxHighlightingForHandlebars() { TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text.TrimEnd()); }
/// <summary> /// Create output using Handlebars as templating engine /// </summary> private void GenerateFromPattern() { // Establish the current time at the start of generation, to display only messages related to the current generation run. var currentTime = DateTime.Now; localRichTextBoxGenerationOutput.Clear(); RaiseOnClearMainText(); localTabControl.SelectedIndex = 0; // Loop through the checked items, select the right mapping and generate the pattern if (_localCheckedListBox.CheckedItems.Count != 0) { for (int x = 0; x <= _localCheckedListBox.CheckedItems.Count - 1; x++) { var targetTableName = _localCheckedListBox.CheckedItems[x].ToString(); _localRichTextBox.AppendText(@"Processing generation for " + targetTableName + ".\r\n"); // Only process the selected items in the total of available source-to-target mappings ItemList.TryGetValue(targetTableName, out var dataObjectMappingList); // Return the result to the user try { // Compile the template, and merge it with the metadata var template = Handlebars.Compile(localRichTextBoxGenerationPattern.Text); var result = template(dataObjectMappingList); // Check if the metadata needs to be displayed if (DisplayJsonFlag) { try { var json = JsonConvert.SerializeObject(dataObjectMappingList, Formatting.Indented); localRichTextBoxGenerationOutput.AppendText(json + "\r\n\r\n"); } catch (Exception ex) { RaiseOnChangeMainText("An error was encountered while generating the Json metadata. The error message is: " + ex); } } // Display the output of the template to the user localRichTextBoxGenerationOutput.AppendText(result); // Spool the output to disk if (SaveOutputFileFlag) { VdwUtility.SaveOutputToDisk(FormBase.VdwConfigurationSettings.VdwOutputPath + targetTableName + ".sql", result); } //Generate in database if (GenerateInDatabaseFlag) { // Find the right connection for the pattern connection key var localConnection = TeamConfiguration.GetTeamConnectionByInternalId(localLabelActiveConnectionKeyValue.Text, FormBase.TeamConfigurationSettings.ConnectionDictionary); if (localConnection != null) { var conn = new SqlConnection { ConnectionString = localConnection.CreateSqlServerConnectionString(false) }; VdwUtility.CreateVdwSchema(conn); VdwUtility.ExecuteOutputInDatabase(conn, result); } else { FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"There was an issue establishing a connection to generate the output for {targetTableName}. Is there a TEAM connections file in the configuration directory?")); } } } catch (Exception ex) { FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"The template could not be compiled. The error message is: {ex.Message}")); } } } else { _localRichTextBox.AppendText($"There was no metadata selected to generate {_inputNiceName} code. Please check the metadata schema - are there any {_inputNiceName} objects selected?"); } // Report back to the user int errorCounter = 0; foreach (Event individualEvent in FormBase.VdwConfigurationSettings.VdwEventLog) { if (individualEvent.eventCode == 1 && individualEvent.eventTime > currentTime) { errorCounter++; RaiseOnChangeMainText(individualEvent.eventDescription + "\r\n"); } } RaiseOnChangeMainText($"\r\n{errorCounter} error(s) have been found.\r\n"); RaiseOnChangeMainText($"\r\nAssociated scripts have been saved in {FormBase.VdwConfigurationSettings.VdwOutputPath}.\r\n"); // Apply syntax highlighting TextHandling.SyntaxHighlightSql(localRichTextBoxGenerationOutput, localRichTextBoxGenerationOutput.Text); }