diff --git a/Rdmp.Core.Tests/CommandLine/ExampleDatasetsCreationTests.cs b/Rdmp.Core.Tests/CommandLine/ExampleDatasetsCreationTests.cs index 58329fef9e..5429060c0a 100644 --- a/Rdmp.Core.Tests/CommandLine/ExampleDatasetsCreationTests.cs +++ b/Rdmp.Core.Tests/CommandLine/ExampleDatasetsCreationTests.cs @@ -28,8 +28,8 @@ public void Test_ExampleDatasetsCreation() Assert.AreEqual(0, CatalogueRepository.GetAllObjects().Length); //create the pipelines - var pipes = new CataloguePipelinesAndReferencesCreation(RepositoryLocator, null, null); - pipes.CreatePipelines(); + var pipes = new CataloguePipelinesAndReferencesCreation(RepositoryLocator,null,null); + pipes.CreatePipelines(new PlatformDatabaseCreationOptions {}); //create all the stuff var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); diff --git a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelDatabaseTests.cs b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelDatabaseTests.cs index dba7e629a3..1374b12b07 100644 --- a/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelDatabaseTests.cs +++ b/Rdmp.Core.Tests/DataLoad/Engine/Integration/ExcelDatabaseTests.cs @@ -28,7 +28,7 @@ public void TestLoadingFileWithTrailingDotsInHeader() // Create the 'out of the box' RDMP pipelines (which includes an excel bulk importer pipeline) var creator = new CataloguePipelinesAndReferencesCreation( RepositoryLocator, UnitTestLoggingConnectionString, DataQualityEngineConnectionString); - creator.CreatePipelines(); + creator.CreatePipelines(new PlatformDatabaseCreationOptions {}); // find the excel loading pipeline var pipe = CatalogueRepository.GetAllObjects().OrderByDescending(p => p.ID) diff --git a/Rdmp.Core/CommandLine/DatabaseCreation/CataloguePipelinesAndReferencesCreation.cs b/Rdmp.Core/CommandLine/DatabaseCreation/CataloguePipelinesAndReferencesCreation.cs index 6388d14c28..bad1a9bd27 100644 --- a/Rdmp.Core/CommandLine/DatabaseCreation/CataloguePipelinesAndReferencesCreation.cs +++ b/Rdmp.Core/CommandLine/DatabaseCreation/CataloguePipelinesAndReferencesCreation.cs @@ -49,30 +49,28 @@ private void DoStartup() var startup = new Startup.Startup(new EnvironmentInfo(), _repositoryLocator); startup.DoStartup(new IgnoreAllErrorsCheckNotifier()); } - - private void CreateServers() + private void CreateServers(PlatformDatabaseCreationOptions options) { var defaults = _repositoryLocator.CatalogueRepository; + if(options.CreateLoggingServer){ + _edsLogging = new ExternalDatabaseServer(_repositoryLocator.CatalogueRepository, "Logging",new LoggingDatabasePatcher()) + { + Server = _logging?.DataSource ?? throw new InvalidOperationException("Null logging database provided"), + Database = _logging.InitialCatalog + }; + + if(_logging.UserID != null) + { + _edsLogging.Username = _logging.UserID; + _edsLogging.Password = _logging.Password; + } - _edsLogging = new ExternalDatabaseServer(_repositoryLocator.CatalogueRepository, "Logging", - new LoggingDatabasePatcher()) - { - Server = _logging.DataSource, - Database = _logging.InitialCatalog - }; - - if (_logging.UserID != null) - { - _edsLogging.Username = _logging.UserID; - _edsLogging.Password = _logging.Password; + _edsLogging.SaveToDatabase(); + defaults.SetDefault(PermissableDefaults.LiveLoggingServer_ID, _edsLogging); + Console.WriteLine("Successfully configured default logging server"); } - _edsLogging.SaveToDatabase(); - defaults.SetDefault(PermissableDefaults.LiveLoggingServer_ID, _edsLogging); - Console.WriteLine("Successfully configured default logging server"); - - var edsDQE = - new ExternalDatabaseServer(_repositoryLocator.CatalogueRepository, "DQE", new DataQualityEnginePatcher()) + var edsDQE = new ExternalDatabaseServer(_repositoryLocator.CatalogueRepository, "DQE", new DataQualityEnginePatcher()) { Server = _dqe.DataSource, Database = _dqe.InitialCatalog @@ -94,7 +92,8 @@ private void CreateServers() }; //We are expecting a single username/password for everything here, so just use the dqe one - if (_dqe.UserID != null) + bool hasLoggingDB = _logging != null && _logging.UserID != null; + if (_dqe.UserID != null && hasLoggingDB) { if (_logging.UserID != _dqe.UserID || _logging.Password != _dqe.Password) throw new Exception( @@ -109,7 +108,7 @@ private void CreateServers() Console.WriteLine("Successfully configured RAW server"); } - public void CreatePipelines() + public void CreatePipelines(PlatformDatabaseCreationOptions options) { var bulkInsertCsvPipe = CreatePipeline("BULK INSERT: CSV Import File (manual column-type editing)", @@ -124,11 +123,11 @@ public void CreatePipelines() SetComponentProperties(bulkInsertCsvPipewithAdjuster.Source, "Separator", ","); SetComponentProperties(bulkInsertCsvPipewithAdjuster.Source, "StronglyTypeInput", false); - SetComponentProperties(bulkInsertCsvPipe.Destination, "LoggingServer", _edsLogging); - SetComponentProperties(bulkInsertCsvPipewithAdjuster.Destination, "LoggingServer", _edsLogging); - - var createCohortFromCSV = CreatePipeline("CREATE COHORT:From CSV File", typeof(DelimitedFlatFileDataFlowSource), - typeof(BasicCohortDestination)); + if(options.CreateLoggingServer){ + SetComponentProperties(bulkInsertCsvPipe.Destination, "LoggingServer", _edsLogging); + SetComponentProperties(bulkInsertCsvPipewithAdjuster.Destination, "LoggingServer", _edsLogging); + } + var createCohortFromCSV = CreatePipeline("CREATE COHORT:From CSV File",typeof (DelimitedFlatFileDataFlowSource), typeof (BasicCohortDestination)); SetComponentProperties(createCohortFromCSV.Source, "Separator", ","); CreatePipeline("CREATE COHORT:By Executing Cohort Identification Configuration", @@ -198,10 +197,10 @@ private Pipeline CreatePipeline(string nameOfPipe, Type sourceType, Type destina return pipe; } - public void Create() + public void Create(PlatformDatabaseCreationOptions options) { DoStartup(); - CreateServers(); - CreatePipelines(); + CreateServers(options); + CreatePipelines(options); } } \ No newline at end of file diff --git a/Rdmp.Core/CommandLine/DatabaseCreation/PlatformDatabaseCreation.cs b/Rdmp.Core/CommandLine/DatabaseCreation/PlatformDatabaseCreation.cs index d6fb5b732f..17c9b4d845 100644 --- a/Rdmp.Core/CommandLine/DatabaseCreation/PlatformDatabaseCreation.cs +++ b/Rdmp.Core/CommandLine/DatabaseCreation/PlatformDatabaseCreation.cs @@ -38,8 +38,11 @@ public static void CreatePlatformDatabases(PlatformDatabaseCreationOptions optio Create(DefaultDataExportDatabaseName, new DataExportPatcher(), options); var dqe = Create(DefaultDQEDatabaseName, new DataQualityEnginePatcher(), options); - var logging = Create(DefaultLoggingDatabaseName, new LoggingDatabasePatcher(), options); - + + SqlConnectionStringBuilder logging = null; + if(options.CreateLoggingServer){ + logging = Create(DefaultLoggingDatabaseName, new LoggingDatabasePatcher(), options); + } CatalogueRepository.SuppressHelpLoading = true; var repo = new PlatformDatabaseCreationRepositoryFinder(options); @@ -47,7 +50,7 @@ public static void CreatePlatformDatabases(PlatformDatabaseCreationOptions optio if (!options.SkipPipelines) { var creator = new CataloguePipelinesAndReferencesCreation(repo, logging, dqe); - creator.Create(); + creator.Create(options); } if (options.ExampleDatasets || options.Nightmare) diff --git a/Rdmp.Core/CommandLine/DatabaseCreation/PlatformDatabaseCreationOptions.cs b/Rdmp.Core/CommandLine/DatabaseCreation/PlatformDatabaseCreationOptions.cs index fea10b93ed..401eda1ce2 100644 --- a/Rdmp.Core/CommandLine/DatabaseCreation/PlatformDatabaseCreationOptions.cs +++ b/Rdmp.Core/CommandLine/DatabaseCreation/PlatformDatabaseCreationOptions.cs @@ -43,6 +43,9 @@ public class PlatformDatabaseCreationOptions "Skips creating the default Pipelines and Managed Server References in the Catalogue database once created.")] public bool SkipPipelines { get; set; } + [Option('l', "Create Logging Server", Default = true, HelpText = "Create the default logging server in the Catalogue database once created. Is superseeded by 'Skip Pipelines'")] + public bool CreateLoggingServer { get; set; } + [Option('e', "ExampleDatasets", Default = false, HelpText = "Create example datasets, projects, extraction configurations and cohort queries")] public bool ExampleDatasets { get; set; } @@ -80,6 +83,7 @@ public class PlatformDatabaseCreationOptions "Optional connection string keywords to use e.g. \"Key1=Value1; Key2=Value2\". When using this option you must manually specify IntegratedSecurity if required.")] public string OtherKeywords { get; set; } + [Usage] public static IEnumerable Examples { diff --git a/Rdmp.Core/Curation/Data/Catalogue.cs b/Rdmp.Core/Curation/Data/Catalogue.cs index 0b78f3b0a5..64a42b638c 100644 --- a/Rdmp.Core/Curation/Data/Catalogue.cs +++ b/Rdmp.Core/Curation/Data/Catalogue.cs @@ -527,10 +527,17 @@ public LoadMetadata LoadMetadata /// [NoMappingToDatabase] - public ExternalDatabaseServer LiveLoggingServer => - LiveLoggingServer_ID == null - ? null - : Repository.GetObjectByID((int)LiveLoggingServer_ID); + public ExternalDatabaseServer LiveLoggingServer { + get{ + if(LiveLoggingServer_ID != null){ + ExternalDatabaseServer[] dbs = Repository.GetAllObjectsWhere("id",(int)LiveLoggingServer_ID); + if(dbs.Length > 0){ + return dbs.First(); + } + } + return null; + } + } /// [NoMappingToDatabase] diff --git a/Rdmp.Core/Curation/Data/ExternalDatabaseServer.cs b/Rdmp.Core/Curation/Data/ExternalDatabaseServer.cs index 2b9cefe8c5..4a4b0254ab 100644 --- a/Rdmp.Core/Curation/Data/ExternalDatabaseServer.cs +++ b/Rdmp.Core/Curation/Data/ExternalDatabaseServer.cs @@ -275,6 +275,15 @@ public bool DiscoverExistence(DataAccessContext context, out string reason) => public override void DeleteInDatabase() { + + if (WasCreatedBy(new LoggingDatabasePatcher())){ + //If you're trying to delete a logging server, remove all references to it first + Catalogue[] catalogues = Repository.GetAllObjectsWhere("LiveLoggingServer_ID",base.ID); + foreach(Catalogue catalogue in catalogues){ + catalogue.LiveLoggingServer_ID = null; + catalogue.SaveToDatabase(); + } + } base.DeleteInDatabase(); // normally in database schema deleting an ExternalDatabaseServer will cascade to clear defaults diff --git a/Rdmp.Core/GlobalStrings.Designer.cs b/Rdmp.Core/GlobalStrings.Designer.cs index 61f0546536..cb2d918533 100644 --- a/Rdmp.Core/GlobalStrings.Designer.cs +++ b/Rdmp.Core/GlobalStrings.Designer.cs @@ -230,5 +230,11 @@ public static string TriggerStatusIsCurrently { return ResourceManager.GetString("TriggerStatusIsCurrently", resourceCulture); } } + + public static string CreateALoggingServer { + get { + return ResourceManager.GetString("CreateALoggingServer"); + } + } } } diff --git a/Rdmp.Core/GlobalStrings.resx b/Rdmp.Core/GlobalStrings.resx index 52bbed2f06..35bad529ce 100644 --- a/Rdmp.Core/GlobalStrings.resx +++ b/Rdmp.Core/GlobalStrings.resx @@ -174,4 +174,7 @@ Catalogue from File... + + Create a logging server + \ No newline at end of file diff --git a/Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.Designer.cs b/Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.Designer.cs index 81db0fbc68..fe75ce878d 100644 --- a/Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.Designer.cs +++ b/Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.Designer.cs @@ -1,4 +1,5 @@ using System; +using Rdmp.Core; using Rdmp.UI.SimpleControls; @@ -70,6 +71,7 @@ private void InitializeComponent() this.label11 = new System.Windows.Forms.Label(); this.tbRowCount = new System.Windows.Forms.TextBox(); this.cbCreateExampleDatasets = new System.Windows.Forms.CheckBox(); + this.cbCreateLoggingServer = new System.Windows.Forms.CheckBox(); this.tbSeed = new System.Windows.Forms.TextBox(); this.tbOtherKeywords = new System.Windows.Forms.TextBox(); this.tbCreateDatabaseTimeout = new System.Windows.Forms.TextBox(); @@ -375,6 +377,7 @@ private void InitializeComponent() // gbCreateNew // this.gbCreateNew.Controls.Add(this.cbCreateExampleDatasets); + this.gbCreateNew.Controls.Add(this.cbCreateLoggingServer); this.gbCreateNew.Controls.Add(this.gbSqlAuthentication); this.gbCreateNew.Controls.Add(this.gbExampleDatasets); this.gbCreateNew.Controls.Add(this.tbOtherKeywords); @@ -522,7 +525,18 @@ private void InitializeComponent() this.cbCreateExampleDatasets.Text = "Example Datasets"; this.cbCreateExampleDatasets.UseVisualStyleBackColor = true; this.cbCreateExampleDatasets.CheckedChanged += new System.EventHandler(this.cbCreateExampleDatasets_CheckedChanged); - // + // + // cbCreateLoggingServer + // + this.cbCreateLoggingServer.AutoSize = true; + this.cbCreateLoggingServer.Location = new System.Drawing.Point(543, 156); + this.cbCreateLoggingServer.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.cbCreateLoggingServer.Name = "cbCreateLoggingServer"; + this.cbCreateLoggingServer.Size = new System.Drawing.Size(118, 19); + this.cbCreateLoggingServer.TabIndex = 9; + this.cbCreateLoggingServer.Checked = true; + this.cbCreateLoggingServer.Text = Core.GlobalStrings.CreateALoggingServer; + this.cbCreateLoggingServer.UseVisualStyleBackColor = true; // tbSeed // this.tbSeed.Location = new System.Drawing.Point(94, 22); @@ -672,6 +686,7 @@ private void InitializeComponent() private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label9; private System.Windows.Forms.CheckBox cbCreateExampleDatasets; + private System.Windows.Forms.CheckBox cbCreateLoggingServer; private System.Windows.Forms.TextBox tbSeed; private System.Windows.Forms.Label label10; private System.Windows.Forms.TextBox tbRowCount; diff --git a/Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.cs b/Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.cs index b4ae9bc1de..c81b612611 100644 --- a/Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.cs +++ b/Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.cs @@ -271,6 +271,7 @@ private void btnCreateSuite_Click(object sender, EventArgs e) Username = tbUsername.Text, Password = tbPassword.Text, ExampleDatasets = cbCreateExampleDatasets.Checked, + CreateLoggingServer = cbCreateLoggingServer.Checked, Seed = _seed, NumberOfPeople = _peopleCount, NumberOfRowsPerDataset = _rowCount,