Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
Fix: Resolved most of the SonarCloud Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jcapellman committed Aug 13, 2024
1 parent 9b760b4 commit 229c9cb
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 38 deletions.
18 changes: 9 additions & 9 deletions src/MLIDS.UnitTests/lib/DAL/CSVFileDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CSVFileDAL
[ExpectedException(typeof(ArgumentNullException))]
public async Task CSVFileDAL_NullTestAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

await csvDal.GetHostPacketsAsync(null);
}
Expand All @@ -23,7 +23,7 @@ public async Task CSVFileDAL_NullTestAsync()
[ExpectedException(typeof(FileNotFoundException))]
public async Task CSVFileDAL_StringTestAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

await csvDal.GetHostPacketsAsync("test");
}
Expand All @@ -32,7 +32,7 @@ public async Task CSVFileDAL_StringTestAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task CSVFileDAL_WriteNullTestAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await csvDal.WritePacketAsync(null);

Expand All @@ -43,7 +43,7 @@ public async Task CSVFileDAL_WriteNullTestAsync()
[ExpectedException(typeof(NullReferenceException))]
public async Task CSVFileDAL_WriteEmptyTestAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await csvDal.WritePacketAsync(new MLIDS.lib.ML.Objects.PayloadItem());

Expand All @@ -54,7 +54,7 @@ public async Task CSVFileDAL_WriteEmptyTestAsync()
[ExpectedException(typeof(NullReferenceException))]
public async Task CSVFileDAL_WriteNotEmptyTestAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await csvDal.WritePacketAsync(new MLIDS.lib.ML.Objects.PayloadItem
{
Expand All @@ -81,7 +81,7 @@ public async Task CSVFileDAL_WriteNotEmptyTestAsync()
[TestMethod]
public async Task CSVFileDAL_GetTestAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

var initResult = csvDal.Initialize();

Expand Down Expand Up @@ -115,7 +115,7 @@ public async Task CSVFileDAL_GetTestAsync()
[TestMethod]
public async Task CSVFileDAL_QueryResultsAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

var initResult = csvDal.Initialize();

Expand Down Expand Up @@ -150,7 +150,7 @@ public async Task CSVFileDAL_QueryResultsAsync()
[ExpectedException(typeof(ArgumentNullException))]
public async Task CSVFileDAL_QueryNullTestAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await csvDal.QueryPacketsAsync(null);

Expand All @@ -160,7 +160,7 @@ public async Task CSVFileDAL_QueryNullTestAsync()
[TestMethod]
public async Task CSVFileDAL_QueryEmptyTestAsync()
{
var csvDal = new MLIDS.lib.DAL.CSVFileDAL(new MLIDS.lib.Containers.SettingsItem());
var csvDal = new MLIDS.lib.DAL.CsvFileDal(new MLIDS.lib.Containers.SettingsItem());

var result = await csvDal.QueryPacketsAsync(a => a.Label);

Expand Down
10 changes: 5 additions & 5 deletions src/MLIDS.lib.Windows/ViewModels/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public abstract class BaseViewModel : INotifyPropertyChanged

public event EventHandler<string> OnFailedDAL;

private List<BaseDAL> _dataLayers;
private List<BaseDal> _dataLayers;

public List<BaseDAL> DataLayers
public List<BaseDal> DataLayers
{
get => _dataLayers;

Expand All @@ -39,9 +39,9 @@ public List<BaseDAL> DataLayers
}
}

private BaseDAL _selectedDataLayer;
private BaseDal _selectedDataLayer;

public BaseDAL SelectedDataLayer
public BaseDal SelectedDataLayer
{
get => _selectedDataLayer;

Expand Down Expand Up @@ -194,7 +194,7 @@ protected BaseViewModel()

DataLayers = DALHelper.GetAvailableDALs(Settings);

SelectedDataLayer = DataLayers.FirstOrDefault(a => !a.IsSelectable);
SelectedDataLayer = DataLayers.First(a => !a.IsSelectable);
}

/// <exception cref="System.ArgumentNullException">JSON or Filename is null</exception>
Expand Down
7 changes: 2 additions & 5 deletions src/MLIDS.lib/DAL/Base/BaseDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@

namespace MLIDS.lib.DAL.Base
{
public abstract class BaseDAL
public abstract class BaseDal
{
protected SettingsItem settingsItem;

protected BaseDAL(SettingsItem settingsItem)
{
this.settingsItem = settingsItem ?? throw new ArgumentNullException(nameof(settingsItem));
}
protected BaseDal(SettingsItem settingsItem) => this.settingsItem = settingsItem ?? throw new ArgumentNullException(nameof(settingsItem));

public abstract string Description { get; }

Expand Down
4 changes: 2 additions & 2 deletions src/MLIDS.lib/DAL/CSVFileDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace MLIDS.lib.DAL
{
public class CSVFileDAL : BaseDAL
public class CsvFileDal : BaseDal
{
public class CSVWriter
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public async Task WriteToFileAsync(string text)

private string _fileName;

public CSVFileDAL(SettingsItem settingsItem) : base(settingsItem)
public CsvFileDal(SettingsItem settingsItem) : base(settingsItem)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/DAL/EmptyDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace MLIDS.lib.DAL
{
public class EmptyDAL : BaseDAL
public class EmptyDAL : BaseDal
{
public override string Description => "--Select a Data Layer--";

Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/DAL/JsonFileDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace MLIDS.lib.DAL
{
public class JsonFileDAL : BaseDAL
public class JsonFileDAL : BaseDal
{
private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();

Expand Down
4 changes: 2 additions & 2 deletions src/MLIDS.lib/DAL/LiteDBDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace MLIDS.lib.DAL
{
public class LiteDBDAL : BaseDAL
public class LiteDBDAL : BaseDal
{
private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();

Expand Down Expand Up @@ -73,7 +73,7 @@ public override bool Initialize()
return true;
} catch (Exception ex)
{
Log.Error($"LiteDBDAL::Initialize - Exception when loading: {ex}");
Log.Error("LiteDBDAL::Initialize - Exception when loading: {ex}", ex);

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/DAL/MongoDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace MLIDS.lib.DAL
{
public class MongoDAL : BaseDAL
public class MongoDAL : BaseDal
{
private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();

Expand Down
6 changes: 3 additions & 3 deletions src/MLIDS.lib/Helpers/DALHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace MLIDS.lib.Helpers
{
public static class DALHelper
{
public static List<BaseDAL> GetAvailableDALs(SettingsItem settings)
public static List<BaseDal> GetAvailableDALs(SettingsItem settings)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}

return typeof(DALHelper).Assembly.GetTypes().Where(a => typeof(BaseDAL) ==
return typeof(DALHelper).Assembly.GetTypes().Where(a => typeof(BaseDal) ==
a.BaseType && !a.IsAbstract).Select(b =>
(BaseDAL)Activator.CreateInstance(b, settings)).OrderByDescending(c =>
(BaseDal)Activator.CreateInstance(b, settings)).OrderByDescending(c =>
!c.IsSelectable).ThenBy(d => d.Description).ToList();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/MLIDS.lib/ML/Trainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Trainer()
return (_mlContext.Data.TrainTestSplit(trainingDataView, seed: Constants.ML_SEED), cleanDataLength, maliciousDataLength);
}

private static void ValidateArguments(BaseDAL storage, string modelFileName)
private static void ValidateArguments(BaseDal storage, string modelFileName)
{
if (storage == null)
{
Expand All @@ -65,7 +65,7 @@ private static void ValidateArguments(BaseDAL storage, string modelFileName)
}
}

public async Task<ModelMetrics> GenerateModel(BaseDAL storage, string modelFileName)
public async Task<ModelMetrics> GenerateModel(BaseDal storage, string modelFileName)
{
ValidateArguments(storage, modelFileName);

Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/Models/Base/BaseModelRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public abstract class BaseModelRunner
{
public abstract string ModelTypeName { get; }

protected abstract bool Run(string modelFile, BaseDAL dataLayer, SettingsItem settingsItem);
protected abstract bool Run(string modelFile, BaseDal dataLayer, SettingsItem settingsItem);
}
}
2 changes: 1 addition & 1 deletion src/MLIDS.lib/Models/FastTreeRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class FastTreeRunner : BaseModelRunner
{
public override string ModelTypeName => "FastTree";

protected override bool Run(string modelFile, BaseDAL dataLayer, SettingsItem settingsItem)
protected override bool Run(string modelFile, BaseDal dataLayer, SettingsItem settingsItem)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/Models/GamBinaryRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class GamBinaryRunner : BaseModelRunner
{
public override string ModelTypeName => "GAM (Binary)";

protected override bool Run(string modelFile, BaseDAL dataLayer, SettingsItem settingsItem)
protected override bool Run(string modelFile, BaseDal dataLayer, SettingsItem settingsItem)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/Models/KMeansRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class KMeansRunner : BaseModelRunner
{
public override string ModelTypeName => "K-Means";

protected override bool Run(string modelFile, BaseDAL dataLayer, SettingsItem settingsItem)
protected override bool Run(string modelFile, BaseDal dataLayer, SettingsItem settingsItem)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/Models/LightGBMBinaryRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class LightGBMBinaryRunner : BaseModelRunner
{
public override string ModelTypeName => "LightGBM (Binary)";

protected override bool Run(string modelFile, BaseDAL dataLayer, SettingsItem settingsItem)
protected override bool Run(string modelFile, BaseDal dataLayer, SettingsItem settingsItem)
{
throw new System.NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/Models/RandomizedPCARunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class RandomizedPCARunner : BaseModelRunner
{
public override string ModelTypeName => "Randomized PCA";

protected override bool Run(string modelFile, BaseDAL dataLayer, SettingsItem settingsItem)
protected override bool Run(string modelFile, BaseDal dataLayer, SettingsItem settingsItem)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MLIDS.lib/Models/TensorFlowRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TensorFlowRunner : BaseModelRunner
{
public override string ModelTypeName => "TensorFlow";

protected override bool Run(string modelFile, BaseDAL dataLayer, SettingsItem settingsItem)
protected override bool Run(string modelFile, BaseDal dataLayer, SettingsItem settingsItem)
{
throw new NotImplementedException();
}
Expand Down

0 comments on commit 229c9cb

Please sign in to comment.