Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeQL fixups #2134

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,11 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)

private void newFindToolStripMenuItem_Click(object sender, EventArgs e)
{
var focusItem = _windowManager.GetAllWindows<RDMPUserControl>().Where(c => c.ContainsFocus).FirstOrDefault();
var nf = new NewfindUI(Activator, false,focusItem);
var focusItem = _windowManager.GetAllWindows<RDMPUserControl>().FirstOrDefault(c => c.ContainsFocus);
var nf = new NewfindUI(Activator, false, focusItem);
nf.ShowDialog();
}

private void newReplaceToolStripMenuItem_Click(object sender, EventArgs e)
{
var nf = new NewfindUI(Activator, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ private T Activate<T, T2>(T2 databaseObject, Image<Rgba32> tabImage)
var floatable = WindowFactory.Create(this, RefreshBus, uiInstance, tabImage, databaseObject);

int? insertIndex = null;
var panel = _mainDockPanel.Panes.Where(p => p.IsActiveDocumentPane).SingleOrDefault();
var panel = _mainDockPanel.Panes.SingleOrDefault(static p => p.IsActiveDocumentPane);
if (panel is not null)
{
var contents = panel.Contents;
insertIndex = contents.IndexOf(panel.ActiveContent)+1;
insertIndex = contents.IndexOf(panel.ActiveContent) + 1;
}

floatable.Show(_mainDockPanel, DockState.Document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace ResearchDataManagementPlatform.WindowManagement.WindowArranging;

/// <inheritdoc/>
public class WindowArranger : IArrangeWindows
public partial class WindowArranger : IArrangeWindows
{
private readonly IActivateItems _activator;
private readonly WindowManager _windowManager;
Expand Down Expand Up @@ -57,10 +57,12 @@ public void Setup(WindowLayout target)

private static bool AreBasicallyTheSameLayout(string oldXml, string newXml)
{
var patStripActive = @"Active.*=[""\-\d]*";
oldXml = Regex.Replace(oldXml, patStripActive, "");
newXml = Regex.Replace(newXml, patStripActive, "");
oldXml = StripActive().Replace(oldXml, "");
newXml = StripActive().Replace(newXml, "");

return oldXml.Equals(newXml, StringComparison.CurrentCultureIgnoreCase);
return oldXml.Equals(newXml, StringComparison.OrdinalIgnoreCase);
}

[GeneratedRegex(@"Active.*=[""\-\d]*")]
private static partial Regex StripActive();
}
4 changes: 1 addition & 3 deletions Documentation/CodeTutorials/DoubleClickAndDragDrop.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ If you find you cannot use Visual Studio Designer to edit your control because o
<!--- 56df0867990f4b0397e51a6a49f7bdd0 --->
```csharp
[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<ANOTableUI_Design, UserControl>))]
public abstract class ANOTableUI_Design : RDMPSingleDatabaseObjectControl<ANOTable>
{
}
public abstract class ANOTableUI_Design : RDMPSingleDatabaseObjectControl<ANOTable>;
```

# Drop
Expand Down
4 changes: 2 additions & 2 deletions Documentation/CodeTutorials/Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ RDMP features a viewer which renders the By Date and By Column tables as graphs.


## Plugin Constraints
You can write new validation rules by inheriting from `HIC.Common.Validation.Constraints.Secondary.PluginSecondaryConstraint`. Implement the Validate method returning null if validation passed or a `ValidationFailure` if it didn't. Public properties will be rendered as CheckBoxes, TextBoxes etc.
You can write new validation rules by inheriting from `HIC.Common.Validation.Constraints.Secondary.SecondaryConstraint`. Implement the Validate method returning null if validation passed or a `ValidationFailure` if it didn't. Public properties will be rendered as CheckBoxes, TextBoxes etc.

```csharp
public class NoFishConstraint : PluginSecondaryConstraint
public class NoFishConstraint : SecondaryConstraint
{
//Will be exposed in user interface
public bool IgnoreCaps { get; set; }
Expand Down
4 changes: 1 addition & 3 deletions Rdmp.Core.Tests/Caching/Unit/TestIFileDataFlowComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

namespace Rdmp.Core.Tests.Caching.Unit;

public interface IFileDataFlowDestination : TestIFileDataFlowComponent
{
}
public interface IFileDataFlowDestination : TestIFileDataFlowComponent;

public interface TestIFileDataFlowComponent
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void ImportCatalogueWithMandatoryFilter()
[TestCase(false)]
public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalOverrideBeforeHand)
{
var parameterSQL = "DECLARE @dragonCount as varchar(100)";
const string parameterSQL = "DECLARE @dragonCount as varchar(100)";

var filter = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[0])
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using NUnit.Framework;
using Rdmp.Core.Curation.Data.DataLoad;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Repositories;
using Tests.Common;
using Rdmp.Core.DataLoad.Modules.Attachers;
using Rdmp.Core.MapsDirectlyToDatabaseTable;
using System.Linq;

namespace Rdmp.Core.Tests.CommandExecution
{
public class ExecuteCommandCloneLoadMetadataTests: DatabaseTests
public class ExecuteCommandCloneLoadMetadataTests : DatabaseTests
{

[Test]
public void TestCloneLoadMetadata()
{
Expand All @@ -31,15 +28,17 @@ public void TestCloneLoadMetadata()
};
pt1.SaveToDatabase();

pt1.CreateArgumentsForClassIfNotExists(typeof(AnySeparatorFileAttacher));
var pta = pt1.ProcessTaskArguments.Single(pt => pt.Name == "Separator");
pt1.CreateArgumentsForClassIfNotExists<AnySeparatorFileAttacher>();
var pta = pt1.ProcessTaskArguments.Single(static pt => pt.Name == "Separator");
pta.SetValue(",");
pta.SaveToDatabase();
LoadMetadata clonedLmd;
clonedLmd = lmd1.Clone();
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
var clonedLmd = lmd1.Clone();
Assert.Multiple(() =>
{
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using NUnit.Framework;
using Rdmp.Core.Curation.Data.DataLoad;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Repositories;
using Tests.Common;
using Rdmp.Core.DataLoad.Modules.Attachers;
using Rdmp.Core.MapsDirectlyToDatabaseTable;
using System.Linq;

namespace Rdmp.Core.Tests.CommandExecution
Expand All @@ -31,16 +29,18 @@ public void TestCreateLoadMetadataVersion()
};
pt1.SaveToDatabase();

pt1.CreateArgumentsForClassIfNotExists(typeof(AnySeparatorFileAttacher));
var pta = pt1.ProcessTaskArguments.Single(pt => pt.Name == "Separator");
pt1.CreateArgumentsForClassIfNotExists<AnySeparatorFileAttacher>();
var pta = pt1.ProcessTaskArguments.Single(static pt => pt.Name == "Separator");
pta.SetValue(",");
pta.SaveToDatabase();
LoadMetadata clonedLmd;
clonedLmd = (LoadMetadata)lmd1.SaveNewVersion();
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.RootLoadMetadata_ID, Is.EqualTo(lmd1.ID));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
var clonedLmd = (LoadMetadata)lmd1.SaveNewVersion();
Assert.Multiple(() =>
{
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.RootLoadMetadata_ID, Is.EqualTo(lmd1.ID));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.Curation.DataHelper.RegexRedaction;
using System.Text.RegularExpressions;
using Rdmp.Core.CommandLine.Interactive;
using Rdmp.Core.ReusableLibraryCode.Checks;
using System.Data;
using FAnsi.Discovery;
Expand Down Expand Up @@ -105,8 +104,8 @@ public void OneTimeTearDown()
[Test]
public void Redaction_BasicRedactionTest()
{
_dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234" });
_dt.Rows.Add(new object[] { DateTime.Now, '2', "1234TEST1234" });
_dt.Rows.Add(DateTime.Now, '1', "1234TEST1234");
_dt.Rows.Add(DateTime.Now, '2', "1234TEST1234");
(_catalogue, var columnInfos) = CreateTable(_db, _dt);

var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "GG", "Replace TEST with GG");
Expand All @@ -126,8 +125,8 @@ public void Redaction_BasicRedactionTest()
[Test]
public void Redaction_BasicRedactionTestWithLimit()
{
_dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234" });
_dt.Rows.Add(new object[] { DateTime.Parse("10-10-2010"), '2', "1234TEST1234" });
_dt.Rows.Add(DateTime.Now, '1', "1234TEST1234");
_dt.Rows.Add(DateTime.Parse("10-10-2010"), '2', "1234TEST1234");
(_catalogue, var columnInfos) = CreateTable(_db, _dt, new[] { true, true, false });

var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "GG", "Replace TEST with GG");
Expand All @@ -147,7 +146,7 @@ public void Redaction_BasicRedactionTestWithLimit()
[Test]
public void Redaction_OddStringLength()
{
_dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TESTT1234" });
_dt.Rows.Add(DateTime.Now, '1', "1234TESTT1234");
(_catalogue, var columnInfos) = CreateTable(_db, _dt);
var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TESTT"), "GG", "Replace TEST with GG");
regexConfiguration.SaveToDatabase();
Expand All @@ -161,7 +160,7 @@ public void Redaction_OddStringLength()
[Test]
public void Redaction_RedactionTooLong()
{
_dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234" });
_dt.Rows.Add(DateTime.Now, '1', "1234TEST1234");
var (catalogue, columnInfos) = CreateTable(_db, _dt);
var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "FARTOOLONG", "Replace TEST with GG");
regexConfiguration.SaveToDatabase();
Expand All @@ -173,7 +172,7 @@ public void Redaction_RedactionTooLong()
[Test]
public void Redaction_RedactAPK()
{
_dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234" });
_dt.Rows.Add(DateTime.Now, '1', "1234TEST1234");
(_catalogue, var columnInfos) = CreateTable(_db, _dt, new[] { true,true,true});
var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "GG", "Replace TEST with GG");
regexConfiguration.SaveToDatabase();
Expand All @@ -187,7 +186,7 @@ public void Redaction_RedactAPK()
[Test]
public void Redaction_NoPKS()
{
_dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234" });
_dt.Rows.Add(DateTime.Now, '1', "1234TEST1234");
(_catalogue, var columnInfos) = CreateTable(_db, _dt, new[] { false, false, false });
var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "GG", "Replace TEST with GG");
regexConfiguration.SaveToDatabase();
Expand All @@ -199,7 +198,7 @@ public void Redaction_NoPKS()
[Test]
public void Redaction_MultipleInOneCell()
{
_dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234TEST1234" });
_dt.Rows.Add(DateTime.Now, '1', "1234TEST1234TEST1234");
(_catalogue, var columnInfos) = CreateTable(_db, _dt);
var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "DB", "Replace TEST with GG");
regexConfiguration.SaveToDatabase();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using NUnit.Framework;
using Rdmp.Core.Curation.Data.DataLoad;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Repositories;
using Tests.Common;
using Rdmp.Core.DataLoad.Modules.Attachers;
using Rdmp.Core.MapsDirectlyToDatabaseTable;
using System.Linq;
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.CommandLine.Interactive;
using Rdmp.Core.ReusableLibraryCode.Checks;
using Rdmp.Core.CommandExecution;

namespace Rdmp.Core.Tests.CommandExecution
Expand All @@ -35,16 +31,18 @@ public void TestRestoreLoadMetadataVersion()
};
pt1.SaveToDatabase();

pt1.CreateArgumentsForClassIfNotExists(typeof(AnySeparatorFileAttacher));
var pta = pt1.ProcessTaskArguments.Single(pt => pt.Name == "Separator");
pt1.CreateArgumentsForClassIfNotExists<AnySeparatorFileAttacher>();
var pta = pt1.ProcessTaskArguments.Single(static pt => pt.Name == "Separator");
pta.SetValue(",");
pta.SaveToDatabase();
LoadMetadata clonedLmd;
clonedLmd = (LoadMetadata)lmd1.SaveNewVersion();
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.RootLoadMetadata_ID, Is.EqualTo(lmd1.ID));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
var clonedLmd = (LoadMetadata)lmd1.SaveNewVersion();
Assert.Multiple(() =>
{
Assert.That(clonedLmd.ProcessTasks.Count(), Is.EqualTo(1));
Assert.That(clonedLmd.RootLoadMetadata_ID, Is.EqualTo(lmd1.ID));
Assert.That(clonedLmd.Description, Is.EqualTo(lmd1.Description));
Assert.That(clonedLmd.ProcessTasks.First().ProcessTaskArguments.First().Value, Is.EqualTo(lmd1.ProcessTasks.First().ProcessTaskArguments.First().Value));
});
pt1.DeleteInDatabase();
var fetchedlmd = CatalogueRepository.GetObjectByID<LoadMetadata>(lmd1.ID);
Assert.That(fetchedlmd.ProcessTasks.Count(), Is.EqualTo(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,18 @@ private DataTable GetRedactionTestDataTable()
var ei = new ExtractionInformation(CatalogueRepository, ci, columnInfo, "");
ei.SaveToDatabase();
}

return (catalogue, _columnInfos);
}

private DataTable Retrieve(DiscoveredDatabase db)
private static DataTable Retrieve(DiscoveredDatabase db)
{
var retrieveSQL = @"select [Condition2] from [RedactionTest]";
const string retrieveSQL = @"select [Condition2] from [RedactionTest]";
var dt = new DataTable();
dt.BeginLoadData();
using (var fetchCmd = db.Server.GetCommand(retrieveSQL, db.Server.GetConnection()))
{
using var da = db.Server.GetDataAdapter(fetchCmd);
da.Fill(dt);
}
using var fetchCmd = db.Server.GetCommand(retrieveSQL, db.Server.GetConnection());
using var da = db.Server.GetDataAdapter(fetchCmd);
da.Fill(dt);
return dt;
}

Expand All @@ -67,13 +66,13 @@ public void RedactionRestore_BasicTest()
{
var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer);
var dt = GetRedactionTestDataTable();
dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234" });
(Catalogue catalogue, ColumnInfo[] _columnInfos) = CreateTable(db, dt);
dt.Rows.Add(DateTime.Now, '1', "1234TEST1234");
var (catalogue, columnInfos) = CreateTable(db, dt);

var activator = new ConsoleInputManager(RepositoryLocator, ThrowImmediatelyCheckNotifier.Quiet);
var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "GG", "Replace TEST with GG");
regexConfiguration.SaveToDatabase();
var cmd = new ExecuteCommandPerformRegexRedactionOnCatalogue(activator, catalogue, regexConfiguration, _columnInfos.Where(c => c.GetRuntimeName() == "Condition2").ToList());
var cmd = new ExecuteCommandPerformRegexRedactionOnCatalogue(activator, catalogue, regexConfiguration, columnInfos.Where(c => c.GetRuntimeName() == "Condition2").ToList());
Assert.DoesNotThrow(() => cmd.Execute());
dt = Retrieve(db);
Assert.That(dt.Rows.Count, Is.EqualTo(1));
Expand All @@ -92,8 +91,8 @@ public void RedactionRestore_RestoreTwice()
{
var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer);
var dt = GetRedactionTestDataTable();
dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234" });
(Catalogue catalogue, ColumnInfo[] _columnInfos) = CreateTable(db, dt);
dt.Rows.Add(DateTime.Now, '1', "1234TEST1234");
(var catalogue, var _columnInfos) = CreateTable(db, dt);

var activator = new ConsoleInputManager(RepositoryLocator, ThrowImmediatelyCheckNotifier.Quiet);
var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "GG", "Replace TEST with GG");
Expand Down Expand Up @@ -132,8 +131,8 @@ public void RedactionRestore_MultipleInOneCell()
{
var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer);
var dt = GetRedactionTestDataTable();
dt.Rows.Add(new object[] { DateTime.Now, '1', "1234TEST1234TEST1234" });
(Catalogue catalogue, ColumnInfo[] _columnInfos) = CreateTable(db, dt);
dt.Rows.Add(DateTime.Now, '1', "1234TEST1234TEST1234");
(var catalogue, var _columnInfos) = CreateTable(db, dt);

var activator = new ConsoleInputManager(RepositoryLocator, ThrowImmediatelyCheckNotifier.Quiet);
var regexConfiguration = new RegexRedactionConfiguration(CatalogueRepository, "TestReplacer", new Regex("TEST"), "DB", "Replace TEST with DB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ private void CreateDatabase()
{
RemoteDatabase = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(RemoteDatabaseName);
RemoteDatabase.Create(true);
using (var dt = new DataTable())
{
dt.Columns.Add("Column1", typeof(string));
dt.Columns.Add("Column2", typeof(int));

var dr = dt.NewRow();
dr["Column1"] = "d";
dr["Column2"] = 100;
dt.Rows.Add(dr);
RemoteTable = RemoteDatabase.CreateTable("SomeTable", dt);
}
using var dt = new DataTable();
dt.Columns.Add("Column1", typeof(string));
dt.Columns.Add("Column2", typeof(int));

var dr = dt.NewRow();
dr["Column1"] = "d";
dr["Column2"] = 100;
dt.Rows.Add(dr);
RemoteTable = RemoteDatabase.CreateTable("SomeTable", dt);
}

private void CreateCatalogue()
Expand Down
Loading
Loading