Skip to content

Commit

Permalink
Pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Jul 20, 2023
1 parent 1cd500a commit f89dca4
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion Rdmp.Core.Tests/Curation/Unit/PermissionWindowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions Rdmp.Core.Tests/QueryCaching/QueryCachingCrossServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -239,8 +239,8 @@ public void Test_SingleServerPatientIndexTable_WithTwoParameters(DatabaseType db

AssertNoErrors(compiler);
}


}


Expand Down Expand Up @@ -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");
}

/// <summary>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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<AggregationTask>().Single(t => t.Aggregate.Equals(hospitalAdmissions));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Rdmp.Core/CommandLine/Runners/DleRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Rdmp.Core/Curation/Data/ImportExport/ShareManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,22 @@ private IEnumerable<IColumn> 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<ColumnInfo> GetColumnInfoPrimaryKeys()
{
return GetProperTables().SelectMany(t=>t.ColumnInfos).Where(column => column.IsPrimaryKey);
return GetProperTables().SelectMany(static t=>t.ColumnInfos).Where(static column => column.IsPrimaryKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion Rdmp.Core/Sharing/Dependency/Gathering/GatheredObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ShareDefinition ToShareDefinition(ShareManager shareManager,List<ShareDef
var attribute = relationshipFinder.GetAttribute(property);

//if it's a relationship to a shared object
if (attribute != null && (attribute.Type == RelationshipType.SharedObject || attribute.Type == RelationshipType.OptionalSharedObject))
if (attribute is { Type: RelationshipType.SharedObject or RelationshipType.OptionalSharedObject })
{
var idOfParent = property.GetValue(Object);
var typeOfParent = attribute.Cref;
Expand Down
14 changes: 7 additions & 7 deletions Rdmp.UI/Collections/TableInfoCollectionUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public partial class TableInfoCollectionUI : RDMPCollectionUI, ILifetimeSubscrib
public TableInfoCollectionUI()
{
InitializeComponent();

tlvTableInfos.KeyUp += olvTableInfos_KeyUp;

tlvTableInfos.ItemActivate += tlvTableInfos_ItemActivate;
Expand All @@ -62,7 +62,7 @@ private object tlvTableInfos_DataTypeAspectGetter(object rowobject) =>
private void tlvTableInfos_ItemActivate(object sender, EventArgs e)
{
var o = tlvTableInfos.SelectedObject;

if (o is DecryptionPrivateKeyNode)
{
var c = new PasswordEncryptionKeyLocationUI();
Expand Down Expand Up @@ -97,22 +97,22 @@ public override void SetItemActivator(IActivateItems activator)
olvColumn1,
olvColumn1
);

if(_isFirstTime)
{
CommonTreeFunctionality.SetupColumnTracking(olvDataType, new Guid("c743eab7-1c07-41dd-bb10-68b25a437056"));
CommonTreeFunctionality.SetupColumnTracking(olvValue, new Guid("157fde35-d084-42f6-97d1-13a00ba4d0c1"));
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);


Expand All @@ -135,8 +135,8 @@ public void RefreshBus_RefreshObject(object sender, RefreshObjectEventArgs e)
{
if(e.Object is DataAccessCredentials)
tlvTableInfos.RefreshObject(tlvTableInfos.Objects.OfType<AllDataAccessCredentialsNode>());
if(e.Object is Catalogue || e.Object is TableInfo)

if(e.Object is Catalogue or TableInfo)
tlvTableInfos.RefreshObject(tlvTableInfos.Objects.OfType<AllServersNode>());

if (tlvTableInfos.IndexOf(Activator.CoreChildProvider.AllPipelinesNode) != -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions Rdmp.UI/SimpleDialogs/Revertable/OfferChanceToSaveDialogUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@ private OfferChanceToSaveDialogUI(IRevertable revertable, RevertableObjectReport
}

/// <summary>
/// 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
/// </summary>
/// <param name="revertable"></param>
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;
}
Expand Down
2 changes: 1 addition & 1 deletion Tools/rdmp/CommandLine/Gui/ConsoleGuiSqlEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f89dca4

Please sign in to comment.