private void MenuItemCallback(object sender, EventArgs e) { var logger = DbHistoryScriptsPackage.Logger; try { DbProjectManager manager = new DbProjectManager(DbHistoryScriptsPackage._dte, new DefaultConsoleLogger()); var configuration = this.LoadConfiguration(manager, logger); if (configuration != null) { var dacFilePath = manager.BuildDacFile(); if (!string.IsNullOrEmpty(dacFilePath)) { DacDbHistorySchemaControllerBuilder builder = new DacDbHistorySchemaControllerBuilder(configuration.Common, logger); DbHistorySchemaController controller = null; using (FileStream dacFileStream = new FileStream(dacFilePath, FileMode.Open)) { DacSchemaReader reader = new DacSchemaReader(dacFileStream, true, logger); controller = builder.Build(reader, new ProjectScriptDestinationWriter(new DbProjectManager(DbHistoryScriptsPackage._dte, logger), configuration, logger)); if (controller != null) { controller.GenerateHistorySchemaObjects(); } } } } } catch (Exception exc) { logger.LogError("There was an error while generating history scripts.", exc); } }
private DestinationConfiguration LoadConfiguration(DbProjectManager manager, ILogger logger) { string fileName = "HistoryTableGeneration.json"; try { var fileDetails = manager.GetFile(fileName); if (fileDetails == null) { var dialogResult = VsShellUtilities.ShowMessageBox( this.ServiceProvider, string.Format("The file {0} cannot be found, and is required by the generator, would you like to have the default file added to the project?", fileName), "Missing Configuration", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); if (dialogResult == (int)VSConstants.MessageBoxResult.IDYES) { logger.LogMessage("Creating default configuration file {0}", fileName); manager.UpdateOrAddFile(new ProjectFileDetails() { Name = fileName, PathInProject = fileName, //Behold the default Content = Newtonsoft.Json.JsonConvert.SerializeObject( new DestinationConfiguration() { Common = new HistoryCommonConfiguration() { ExpectedCreatedByColumnName = "CreatedBy", ExpectedCreatedTimestampColumnName = "CreatedTimestamp", Prefix = "History_", Schema = "hst" }, DefaultPathFormat = "{{Schema}}/{{ScriptType}}/{{Name}}.sql", TypedPathFormat = new Dictionary <ScriptType, string>() { { ScriptType.Schema, "Security/{{Name}}.sql" } } }) }); } } else { return(Newtonsoft.Json.JsonConvert.DeserializeObject <DestinationConfiguration>(fileDetails.Content)); } } catch (Exception exc) { logger.LogError("There was an error while loading the configuration", exc); } return(null); }