From f89dca476e2dcb114f2ea34b46631c324ab6e664 Mon Sep 17 00:00:00 2001 From: jas88 Date: Thu, 20 Jul 2023 18:01:25 -0500 Subject: [PATCH] Pattern matching --- .../WindowManagement/WindowManager.cs | 2 +- .../Curation/Unit/PermissionWindowTests.cs | 2 +- .../QueryCachingCrossServerTests.cs | 30 +++++++++---------- ...hortIdentificationConfigurationUICommon.cs | 2 +- .../AtomicCommands/ExecuteCommandDelete.cs | 3 +- Rdmp.Core/CommandLine/Runners/DleRunner.cs | 2 +- .../Data/ImportExport/ShareManager.cs | 2 +- ...utePkSynthesizerDatasetExtractionSource.cs | 15 ++++++---- .../IdentifierDumperSynchronizer.cs | 4 +-- .../Dependency/Gathering/GatheredObject.cs | 2 +- Rdmp.UI/Collections/TableInfoCollectionUI.cs | 14 ++++----- ...ionWhenTargetIsCohortAggregateContainer.cs | 2 +- .../Revertable/OfferChanceToSaveDialogUI.cs | 9 ++---- .../CommandLine/Gui/ConsoleGuiSqlEditor.cs | 2 +- 14 files changed, 46 insertions(+), 45 deletions(-) diff --git a/Application/ResearchDataManagementPlatform/WindowManagement/WindowManager.cs b/Application/ResearchDataManagementPlatform/WindowManagement/WindowManager.cs index b8cc33ebfb..51d1bc852b 100644 --- a/Application/ResearchDataManagementPlatform/WindowManagement/WindowManager.cs +++ b/Application/ResearchDataManagementPlatform/WindowManagement/WindowManager.cs @@ -342,7 +342,7 @@ private void mainDockPanel_ActiveDocumentChanged(object sender, EventArgs e) { var newTab = (DockContent) _mainDockPanel.ActiveDocument; - if(newTab != null && newTab.ParentForm != null) + if(newTab?.ParentForm != null) { Navigation.Append(new TabNavigation(newTab)); newTab.ParentForm.Text = $"{newTab.TabText} - RDMP"; diff --git a/Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs b/Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs index 7294f3342e..924b37180f 100644 --- a/Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs +++ b/Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs @@ -70,7 +70,7 @@ public void TestCurrentlyOutsidePermissionPeriod() { var dtNow = DateTime.UtcNow; - if ((dtNow.Hour == 23 && dtNow.Minute >= 50) || (dtNow.Hour == 0 && dtNow.Minute <= 3)) + if (dtNow is { Hour: 23, Minute: >= 50 } or { Hour: 0, Minute: <= 3 }) Assert.Inconclusive("This test cannot run at midnight since it is afraid of the dark"); var oneMinute = new TimeSpan(0, 1, 0); diff --git a/Rdmp.Core.Tests/QueryCaching/QueryCachingCrossServerTests.cs b/Rdmp.Core.Tests/QueryCaching/QueryCachingCrossServerTests.cs index da387522de..4b7b10b7d5 100644 --- a/Rdmp.Core.Tests/QueryCaching/QueryCachingCrossServerTests.cs +++ b/Rdmp.Core.Tests/QueryCaching/QueryCachingCrossServerTests.cs @@ -90,7 +90,7 @@ public void Test_SingleServer_WithOneParameter(DatabaseType dbType, bool usePara runner.Run(new CancellationToken()); AssertNoErrors(compiler); - + Assert.IsTrue(compiler.Tasks.Where(t=>t.Key is AggregationContainerTask).Any(t => t.Key.GetCachedQueryUseCount().Equals("1/1")), "Expected UNION container to use the cache"); } @@ -239,8 +239,8 @@ public void Test_SingleServerPatientIndexTable_WithTwoParameters(DatabaseType db AssertNoErrors(compiler); } - - + + } @@ -299,11 +299,11 @@ public void Test_EXCEPT_TwoAggregates(DatabaseType dbType) AssertNoErrors(compiler); - Assert.AreEqual(compiler.Tasks.Single(t=> t.Value!=null && t.Value.IsResultsForRootContainer).Key.FinalRowCount,0); + Assert.AreEqual(compiler.Tasks.Single(static t=> t.Value is { IsResultsForRootContainer: true }).Key.FinalRowCount,0); Assert.Greater(compiler.Tasks.Single(t=>t.Key is AggregationTask at && at.Aggregate.Equals(ac1)).Key.FinalRowCount, 0); //both ac should have the same total Assert.Greater(compiler.Tasks.Single(t => t.Key is AggregationTask at && at.Aggregate.Equals(ac2)).Key.FinalRowCount, 0); // that is not 0 - - Assert.IsTrue(compiler.Tasks.Any(t => t.Key.GetCachedQueryUseCount().Equals("2/2")), "Expected EXCEPT container to use the cache"); + + Assert.IsTrue(compiler.Tasks.Any(static t => t.Key.GetCachedQueryUseCount().Equals("2/2")), "Expected EXCEPT container to use the cache"); } /// @@ -348,7 +348,7 @@ public void Join_PatientIndexTable_OptionalCacheOnSameServer(DatabaseType dbType var cic = new CohortIdentificationConfiguration(CatalogueRepository, "cic"); var joinable = SetupPatientIndexTable(db,people,r,cic); - + cic.CreateRootContainerIfNotExists(); cic.QueryCachingServer_ID = cache?.ID; cic.SaveToDatabase(); @@ -415,11 +415,11 @@ public void Join_PatientIndexTable_DoNotUseCacheOnDifferentServer(DatabaseType d var compiler = new CohortCompiler(cic); var runner = new CohortCompilerRunner(compiler, 50000); - + runner.Run(new CancellationToken()); AssertNoErrors(compiler); - + Assert.IsTrue(compiler.Tasks.Any(t => t.Key.GetCachedQueryUseCount().Equals("1/1")),"Expected cache to be used only for the final UNION"); } @@ -466,11 +466,11 @@ public void Join_PatientIndexTable_NotOnCacheServer() var compiler = new CohortCompiler(cic); var runner = new CohortCompilerRunner(compiler, 50000); - + runner.Run(new CancellationToken()); AssertNoErrors(compiler); - + Assert.IsTrue(compiler.Tasks.Any(t => t.Key.GetCachedQueryUseCount().Equals("1/1")),"Expected cache to be used only for the final UNION"); } @@ -521,7 +521,7 @@ public void Join_PatientIndexTable_ThreeServers() var compiler = new CohortCompiler(cic); var runner = new CohortCompilerRunner(compiler, 50000); - + runner.Run(new CancellationToken()); var hospitalAdmissionsTask = compiler.Tasks.Keys.OfType().Single(t => t.Aggregate.Equals(hospitalAdmissions)); @@ -635,7 +635,7 @@ private JoinableCohortAggregateConfiguration SetupPatientIndexTable(DiscoveredDa ac.AddDimension(code); ac.AddDimension(date); ac.CountSQL = null; - + cic.EnsureNamingConvention(ac); var and = new AggregateFilterContainer(CatalogueRepository, FilterContainerOperation.AND); @@ -789,7 +789,7 @@ private static void AssertNoErrors(CohortCompiler compiler) var i = 0; foreach (var kvp in compiler.Tasks.Keys) TestContext.WriteLine($"{i++} - {kvp.ToString()} | {kvp.GetType()} | {kvp.State} | {kvp.CrashMessage} | {kvp.FinalRowCount} | {kvp.GetCachedQueryUseCount()}"); - + Assert.IsTrue(compiler.Tasks.All(static t => t.Key.State == CompilationState.Finished), "Expected all tasks to finish without error"); } @@ -853,7 +853,7 @@ private static void AssertCacheUsed(CohortCompiler compiler, CohortAggregateCont { //cache should have been used var containerResult = compiler.Tasks.Single(t => t.Key is AggregationContainerTask c && c.Container.Equals(container)); - + Assert.AreEqual(CompilationState.Finished,containerResult.Key.State); Assert.AreEqual(expectedCacheUsageCount,containerResult.Key.GetCachedQueryUseCount()); } diff --git a/Rdmp.Core/CohortCreation/CohortIdentificationConfigurationUICommon.cs b/Rdmp.Core/CohortCreation/CohortIdentificationConfigurationUICommon.cs index f58a6c1e1b..fc37da2710 100644 --- a/Rdmp.Core/CohortCreation/CohortIdentificationConfigurationUICommon.cs +++ b/Rdmp.Core/CohortCreation/CohortIdentificationConfigurationUICommon.cs @@ -103,7 +103,7 @@ public object ExecuteAspectGetter(object rowObject) if (IsExecutingGlobalOperations()) return null; - if (rowObject is AggregateConfiguration || rowObject is CohortAggregateContainer) + if (rowObject is AggregateConfiguration or CohortAggregateContainer) { var plannedOp = GetNextOperation(GetState((IMapsDirectlyToDatabaseTable)rowObject)); diff --git a/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandDelete.cs b/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandDelete.cs index f1efa2f00e..b0b42f63d3 100644 --- a/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandDelete.cs +++ b/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandDelete.cs @@ -95,8 +95,7 @@ public override void Execute() private static bool ShouldUseTransactionsWhenDeleting(IDeleteable deleteable) { return - deleteable is CatalogueItem || - deleteable is ExtractionInformation; + deleteable is CatalogueItem or ExtractionInformation; } private string GetDescription() diff --git a/Rdmp.Core/CommandLine/Runners/DleRunner.cs b/Rdmp.Core/CommandLine/Runners/DleRunner.cs index 90c89891d7..48246d0544 100644 --- a/Rdmp.Core/CommandLine/Runners/DleRunner.cs +++ b/Rdmp.Core/CommandLine/Runners/DleRunner.cs @@ -93,7 +93,7 @@ public override int Run(IRDMPPlatformRepositoryServiceLocator locator, IDataLoad var exitCode = dataLoadProcess.Run(token); //return 0 for success or load not required otherwise return the exit code (which will be non zero so error) - return exitCode == ExitCodeType.Success || exitCode == ExitCodeType.OperationNotRequired? 0: (int)exitCode; + return exitCode is ExitCodeType.Success or ExitCodeType.OperationNotRequired? 0: (int)exitCode; case CommandLineActivity.check: checkable.Check(checkNotifier); diff --git a/Rdmp.Core/Curation/Data/ImportExport/ShareManager.cs b/Rdmp.Core/Curation/Data/ImportExport/ShareManager.cs index 6478a47f99..7270e4ef9c 100644 --- a/Rdmp.Core/Curation/Data/ImportExport/ShareManager.cs +++ b/Rdmp.Core/Curation/Data/ImportExport/ShareManager.cs @@ -59,7 +59,7 @@ public ShareManager(IRDMPPlatformRepositoryServiceLocator repositoryLocator, Loc var defaults = RepositoryLocator.CatalogueRepository; - if(property.Name == "LiveLoggingServer_ID" || property.Name == "TestLoggingServer_ID") + if(property.Name is "LiveLoggingServer_ID" or "TestLoggingServer_ID") { var server = defaults.GetDefaultFor(PermissableDefaults.LiveLoggingServer_ID); diff --git a/Rdmp.Core/DataExport/DataExtraction/Pipeline/Sources/ExecutePkSynthesizerDatasetExtractionSource.cs b/Rdmp.Core/DataExport/DataExtraction/Pipeline/Sources/ExecutePkSynthesizerDatasetExtractionSource.cs index 9fa0a5424d..accd8c2a69 100644 --- a/Rdmp.Core/DataExport/DataExtraction/Pipeline/Sources/ExecutePkSynthesizerDatasetExtractionSource.cs +++ b/Rdmp.Core/DataExport/DataExtraction/Pipeline/Sources/ExecutePkSynthesizerDatasetExtractionSource.cs @@ -123,17 +123,22 @@ private IEnumerable GetCatalogueItemPrimaryKeys() { foreach (var column in Request.ColumnsToExtract.Union(Request.ReleaseIdentifierSubstitutions)) { - if (column is ReleaseIdentifierSubstitution ri) - if (ri.IsPrimaryKey || ri.OriginalDatasetColumn.IsPrimaryKey) + switch (column) + { + case ReleaseIdentifierSubstitution ri when (ri.IsPrimaryKey || ri.OriginalDatasetColumn.IsPrimaryKey): yield return ri; - if (column is ExtractableColumn ec && ec.IsPrimaryKey) - yield return ec; + break; + case ExtractableColumn { IsPrimaryKey: true } ec: + yield return ec; + + break; + } } } private IEnumerable GetColumnInfoPrimaryKeys() { - return GetProperTables().SelectMany(t=>t.ColumnInfos).Where(column => column.IsPrimaryKey); + return GetProperTables().SelectMany(static t=>t.ColumnInfos).Where(static column => column.IsPrimaryKey); } } \ No newline at end of file diff --git a/Rdmp.Core/DataLoad/Engine/Pipeline/Components/Anonymisation/IdentifierDumperSynchronizer.cs b/Rdmp.Core/DataLoad/Engine/Pipeline/Components/Anonymisation/IdentifierDumperSynchronizer.cs index 3d04c66a6e..a73e337b36 100644 --- a/Rdmp.Core/DataLoad/Engine/Pipeline/Components/Anonymisation/IdentifierDumperSynchronizer.cs +++ b/Rdmp.Core/DataLoad/Engine/Pipeline/Components/Anonymisation/IdentifierDumperSynchronizer.cs @@ -111,7 +111,7 @@ public void Synchronize(ICheckNotifier notifier) continue; //these are also expected don't warn user about them - if (columnNameInDump == SpecialFieldNames.ValidFrom || columnNameInDump == SpecialFieldNames.DataLoadRunID) + if (columnNameInDump is SpecialFieldNames.ValidFrom or SpecialFieldNames.DataLoadRunID) continue; notifier.OnCheckPerformed( @@ -120,7 +120,7 @@ public void Synchronize(ICheckNotifier notifier) } //for each column that we are supposed to dump, make sure it is actually in the dump table - foreach (var column in _parent.ColumnsToRouteToSomewhereElse.Where(c => c.GoesIntoIdentifierDump())) + foreach (var column in _parent.ColumnsToRouteToSomewhereElse.Where(static c => c.GoesIntoIdentifierDump())) { var colInIdentifierDumpDatabase = columnsInTheIdentifiersDumpTable.SingleOrDefault(c => c.GetRuntimeName().Equals(column.RuntimeColumnName)); diff --git a/Rdmp.Core/Sharing/Dependency/Gathering/GatheredObject.cs b/Rdmp.Core/Sharing/Dependency/Gathering/GatheredObject.cs index 83f38ea70a..8078ba70e2 100644 --- a/Rdmp.Core/Sharing/Dependency/Gathering/GatheredObject.cs +++ b/Rdmp.Core/Sharing/Dependency/Gathering/GatheredObject.cs @@ -80,7 +80,7 @@ public ShareDefinition ToShareDefinition(ShareManager shareManager,List private void tlvTableInfos_ItemActivate(object sender, EventArgs e) { var o = tlvTableInfos.SelectedObject; - + if (o is DecryptionPrivateKeyNode) { var c = new PasswordEncryptionKeyLocationUI(); @@ -97,7 +97,7 @@ public override void SetItemActivator(IActivateItems activator) olvColumn1, olvColumn1 ); - + if(_isFirstTime) { CommonTreeFunctionality.SetupColumnTracking(olvDataType, new Guid("c743eab7-1c07-41dd-bb10-68b25a437056")); @@ -105,14 +105,14 @@ public override void SetItemActivator(IActivateItems activator) CommonTreeFunctionality.SetupColumnTracking(olvColumn1, new Guid("3743e6dd-4166-4f71-b42f-c80ccda1446d")); _isFirstTime = false; } - + CommonTreeFunctionality.WhitespaceRightClickMenuCommandsGetter = a=> new IAtomicCommand[] { new ExecuteCommandImportTableInfo(a,null,false), new ExecuteCommandBulkImportTableInfos(a) }; - + Activator.RefreshBus.EstablishLifetimeSubscription(this); @@ -135,8 +135,8 @@ public void RefreshBus_RefreshObject(object sender, RefreshObjectEventArgs e) { if(e.Object is DataAccessCredentials) tlvTableInfos.RefreshObject(tlvTableInfos.Objects.OfType()); - - if(e.Object is Catalogue || e.Object is TableInfo) + + if(e.Object is Catalogue or TableInfo) tlvTableInfos.RefreshObject(tlvTableInfos.Objects.OfType()); if (tlvTableInfos.IndexOf(Activator.CoreChildProvider.AllPipelinesNode) != -1) diff --git a/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsCohortAggregateContainer.cs b/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsCohortAggregateContainer.cs index 98c0de76ab..22725dcabf 100644 --- a/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsCohortAggregateContainer.cs +++ b/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsCohortAggregateContainer.cs @@ -74,7 +74,7 @@ public override ICommandExecution ProposeExecution(ICombineToMakeCommand cmd, Co } //source is another container (UNION / INTERSECT / EXCEPT) //can never drag the root container elsewhere - case CohortAggregateContainerCombineable sourceCohortAggregateContainerCommand when sourceCohortAggregateContainerCommand.ParentContainerIfAny == null: + case CohortAggregateContainerCombineable { ParentContainerIfAny: null }: return null; //they are trying to drag it onto its current parent case CohortAggregateContainerCombineable sourceCohortAggregateContainerCommand when sourceCohortAggregateContainerCommand.ParentContainerIfAny.Equals(targetCohortAggregateContainer): diff --git a/Rdmp.UI/SimpleDialogs/Revertable/OfferChanceToSaveDialogUI.cs b/Rdmp.UI/SimpleDialogs/Revertable/OfferChanceToSaveDialogUI.cs index 23cebe7d19..60f359770f 100644 --- a/Rdmp.UI/SimpleDialogs/Revertable/OfferChanceToSaveDialogUI.cs +++ b/Rdmp.UI/SimpleDialogs/Revertable/OfferChanceToSaveDialogUI.cs @@ -54,17 +54,14 @@ private OfferChanceToSaveDialogUI(IRevertable revertable, RevertableObjectReport } /// - /// Shows a yes no to saving and describes differences in an IMapsDirectlyToDatabaseTable object which suports IRevertable + /// Shows a yes no to saving and describes differences in an IMapsDirectlyToDatabaseTable object which supports IRevertable /// /// public static DialogResult? ShowIfRequired(IRevertable revertable) { - if (revertable == null) - return null; - - var differences = revertable.HasLocalChanges(); + var differences = revertable?.HasLocalChanges(); - return differences.Evaluation == ChangeDescription.DatabaseCopyDifferent + return differences?.Evaluation == ChangeDescription.DatabaseCopyDifferent ? new OfferChanceToSaveDialogUI(revertable,differences).ShowDialog() : null; } diff --git a/Tools/rdmp/CommandLine/Gui/ConsoleGuiSqlEditor.cs b/Tools/rdmp/CommandLine/Gui/ConsoleGuiSqlEditor.cs index 6d6e3e7873..9b98cfc1e9 100644 --- a/Tools/rdmp/CommandLine/Gui/ConsoleGuiSqlEditor.cs +++ b/Tools/rdmp/CommandLine/Gui/ConsoleGuiSqlEditor.cs @@ -268,7 +268,7 @@ private void ResetSql() private void RunOrCancel() { // if task is still running we should cancel - if(_runSqlTask != null && !_runSqlTask.IsCompleted) + if(_runSqlTask is { IsCompleted: false }) { // Cancel the sql command and let that naturally end the task _runSqlCmd?.Cancel();