Skip to content

Commit

Permalink
update from info and sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar committed Dec 22, 2023
1 parent 9f4e734 commit ff0fca5
Show file tree
Hide file tree
Showing 42 changed files with 107 additions and 171 deletions.
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnalyzeCoolantUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class AnalyzeCoolantUsage : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

if (gCodeAnalyses.AllSpecificCommands(Constants.CharM).Any(c => c.CommandValue.Equals(7)))
gCodeAnalyses.AddOptions(AnalysesOptions.UsesMistCoolant);
Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnalyzeDistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class AnalyzeDistance : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

gCodeAnalyses.TotalDistance = gCodeAnalyses.AllCommands.Sum(c => c.Distance);
}
Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnalyzeDuplicates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class AnalyzeDuplicates : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

if (gCodeAnalyses.AllCommands.Any(c => c.Attributes.HasFlag(CommandAttributes.Duplicate)))
gCodeAnalyses.AddOptions(AnalysesOptions.ContainsDuplicates);
Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnalyzeFileDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ internal class AnalyzeFileDetails : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

if (String.IsNullOrEmpty(fileName) || !File.Exists(fileName))
return;
Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnalyzeSafeZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class AnalyzeSafeZ : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

decimal homeZ = gCodeAnalyses.AllCommands.Count > 0 ? gCodeAnalyses.AllCommands.Max(c => c.CurrentZ) : 0;

Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnalyzeTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class AnalyzeTime : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

Parallel.ForEach(gCodeAnalyses.AllCommands, c =>
{
Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnalyzeToolChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class AnalyzeToolChange : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

if (gCodeAnalyses.AllSpecificCommands(Constants.CharM).Any(c => c.CommandValue.Equals(6)))
gCodeAnalyses.AddOptions(AnalysesOptions.ContainsAutomaticToolChanges);
Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnalyzeUnitOfMeasure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class AnalyzeUnitOfMeasure : BaseAnalyzer, IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

IReadOnlyList<IGCodeCommand> allCommands = gCodeAnalyses.AllSpecificCommands(Constants.CharG).Where(c => (c.CommandValue.Equals(20) || c.CommandValue.Equals(21))).ToList();

Expand Down
6 changes: 3 additions & 3 deletions src/GCAAnalyser/Analyzers/AnalyzeVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
foreach (ushort id in varBlock.VariableIds)
{
if (!declaredVariables.ContainsKey(id))
if (declaredVariables.TryGetValue(id, out int value))
{
declaredVariables.Add(id, 1);
declaredVariables[id] = ++value;
}
else
{
declaredVariables[id]++;
declaredVariables.Add(id, 1);
}

if (!subprogramVariables.Contains(id))
Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/AnaylzeHomeZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class AnalyzeHomeZ : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses == null)
throw new ArgumentNullException(nameof(gCodeAnalyses));
ArgumentNullException.ThrowIfNull(gCodeAnalyses);

List<IGCodeCommand> allCommands = gCodeAnalyses.AllCommands.ToList();
gCodeAnalyses.HomeZ = allCommands.Count > 0 ? allCommands.Max(c => c.CurrentZ) : 0;
Expand Down
3 changes: 1 addition & 2 deletions src/GCAAnalyser/Analyzers/BaseAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ protected static bool HasCommandsOnSameLine(IGCodeCommand command, char ignoreCo

protected static List<IGCodeCommand> CommandsOnSameLine(IGCodeCommand command)
{
if (command == null)
throw new ArgumentNullException(nameof(command));
ArgumentNullException.ThrowIfNull(command);

List<IGCodeCommand> Result = new();

Expand Down
12 changes: 6 additions & 6 deletions src/GCAAnalyser/GCodeAnalyses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public GCodeAnalyses(IPluginClassesService pluginClassesService)

internal void Add(GCodeCommand command)
{
if (command == null)
throw new ArgumentNullException(nameof(command));
ArgumentNullException.ThrowIfNull(command);

_commands.Add(command);
}
Expand All @@ -47,7 +46,7 @@ public void Analyse(string fileName)
totalAnalyze.Start();
try
{
IGCodeAnalyzerFactory gCodeAnalyzerFactory = new GCodeAnalyzerFactory(_pluginClassesService);
GCodeAnalyzerFactory gCodeAnalyzerFactory = new (_pluginClassesService);

IReadOnlyList<IGCodeAnalyzer> analyzers = gCodeAnalyzerFactory.Create();

Expand Down Expand Up @@ -110,12 +109,13 @@ public IReadOnlyList<IGCodeCommand> AllSpecificCommands(char commandCode)
{
using (TimedLock tl = TimedLock.Lock(_lockObject))
{
if (!_allSpecificCommands.ContainsKey(commandCode))
if (!_allSpecificCommands.TryGetValue(commandCode, out List<IGCodeCommand> value))
{
_allSpecificCommands.Add(commandCode, AllCommands.Where(c => c.Command.Equals(commandCode)).ToList());
value = AllCommands.Where(c => c.Command.Equals(commandCode)).ToList();
_allSpecificCommands.Add(commandCode, value);
}

return _allSpecificCommands[commandCode];
return value;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/GCATests/Mocks/MockComPortFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public IComPort CreateComPort(IMachine machine)

public IComPort CreateComPort(IComPortModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
ArgumentNullException.ThrowIfNull(model);

using (TimedLock tl = TimedLock.Lock(_lockObject))
{
Expand Down
18 changes: 6 additions & 12 deletions src/GCSDB/Providers/GSendDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public IJobExecution JobExecutionCreate(long machineId, long toolId, long jobPro

public void JobExecutionUpdate(IJobExecution jobExecution)
{
if (jobExecution == null)
throw new ArgumentNullException(nameof(jobExecution));
ArgumentNullException.ThrowIfNull(jobExecution);

JobExecutionDataRow jobExecutionDataRow = _jobExecutionTable.Select(jobExecution.Id);

Expand All @@ -87,8 +86,7 @@ public void JobExecutionUpdate(IJobExecution jobExecution)

public TimeSpan JobExecutionByTool(IToolProfile toolProfile)
{
if (toolProfile == null)
throw new ArgumentNullException(nameof(toolProfile));
ArgumentNullException.ThrowIfNull(toolProfile);

string cacheName = $"Tool execution: {toolProfile.Id} {toolProfile.Name}";

Expand All @@ -109,8 +107,7 @@ public TimeSpan JobExecutionByTool(IToolProfile toolProfile)

public IEnumerable<JobExecutionStatistics> JobExecutionModelsGetByTool(IToolProfile toolProfile, bool sinceLastUsed)
{
if (toolProfile == null)
throw new ArgumentNullException(nameof(toolProfile));
ArgumentNullException.ThrowIfNull(toolProfile);

string cacheName = $"Tool execution statistics: {toolProfile.Id} {toolProfile.Name} {sinceLastUsed}";

Expand Down Expand Up @@ -356,8 +353,7 @@ public IToolProfile ToolGet(long toolProfileId)

public void ToolAdd(IToolProfile toolProfile)
{
if (toolProfile == null)
throw new ArgumentNullException(nameof(toolProfile));
ArgumentNullException.ThrowIfNull(toolProfile);

_toolDatabaseTable.Insert(new ToolDatabaseDataRow()
{
Expand All @@ -369,8 +365,7 @@ public void ToolAdd(IToolProfile toolProfile)

public void ToolUpdate(IToolProfile toolProfile)
{
if (toolProfile == null)
throw new ArgumentNullException(nameof(toolProfile));
ArgumentNullException.ThrowIfNull(toolProfile);

ToolDatabaseDataRow dataRow = _toolDatabaseTable.Select(toolProfile.Id) ?? throw new InvalidOperationException("Tool not found");
dataRow.ToolName = toolProfile.Name;
Expand All @@ -382,8 +377,7 @@ public void ToolUpdate(IToolProfile toolProfile)

public void ToolResetUsage(IToolProfile toolProfile)
{
if (toolProfile == null)
throw new ArgumentNullException(nameof(toolProfile));
ArgumentNullException.ThrowIfNull(toolProfile);

_memoryCache.GetExtendingCache().Clear();
ToolDatabaseDataRow dataRow = _toolDatabaseTable.Select(toolProfile.Id) ?? throw new InvalidOperationException("Tool not found");
Expand Down
2 changes: 1 addition & 1 deletion src/GCSDB/Tables/JobProfileDataRowDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public List<JobProfileDataRow> InitialData(ushort version)

return new List<JobProfileDataRow>()
{
new JobProfileDataRow() { JobName = "(Default)", JobDescription = "Default job" },
new() { JobName = "(Default)", JobDescription = "Default job" },
};
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/GCSDB/Tables/ServiceItemsDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ public List<ServiceItemsDataRow> InitialData(ushort version)
{
return new List<ServiceItemsDataRow>()
{
new ServiceItemsDataRow() { Name = "Clean Machine/Enclosure", IsDaily = true, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Inspect Bits for Damage", IsDaily = true, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Inspect Wires and Connections", IsDaily = true, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Inspect Surfacing Board", IsDaily = true, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Clean X Axis Moving Parts", IsDaily = false, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Clean Y Axis Moving Parts", IsDaily = false, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Clean Z Axis Moving Parts", IsDaily = false, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Lubricate moving parts (dry lube)", IsDaily = false, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Inspect Collets", IsDaily = false, IsMinor = true, IsMajor = true },
new ServiceItemsDataRow() { Name = "Tram Router", IsDaily = false, IsMinor = false, IsMajor = true },
new ServiceItemsDataRow() { Name = "Inspect Lead/Ball Screws", IsDaily = false, IsMinor = false, IsMajor = true },
new ServiceItemsDataRow() { Name = "Test individual Limit Switches", IsDaily = false, IsMinor = false, IsMajor = true },
new ServiceItemsDataRow() { Name = "Validate Gantry is Square", IsDaily = false, IsMinor = false, IsMajor = true },
new ServiceItemsDataRow() { Name = "Verify screws/bolts correctly tightened", IsDaily = false, IsMinor = false, IsMajor = true },
new() { Name = "Clean Machine/Enclosure", IsDaily = true, IsMinor = true, IsMajor = true },
new() { Name = "Inspect Bits for Damage", IsDaily = true, IsMinor = true, IsMajor = true },
new() { Name = "Inspect Wires and Connections", IsDaily = true, IsMinor = true, IsMajor = true },
new() { Name = "Inspect Surfacing Board", IsDaily = true, IsMinor = true, IsMajor = true },
new() { Name = "Clean X Axis Moving Parts", IsDaily = false, IsMinor = true, IsMajor = true },
new() { Name = "Clean Y Axis Moving Parts", IsDaily = false, IsMinor = true, IsMajor = true },
new() { Name = "Clean Z Axis Moving Parts", IsDaily = false, IsMinor = true, IsMajor = true },
new() { Name = "Lubricate moving parts (dry lube)", IsDaily = false, IsMinor = true, IsMajor = true },
new() { Name = "Inspect Collets", IsDaily = false, IsMinor = true, IsMajor = true },
new() { Name = "Tram Router", IsDaily = false, IsMinor = false, IsMajor = true },
new() { Name = "Inspect Lead/Ball Screws", IsDaily = false, IsMinor = false, IsMajor = true },
new() { Name = "Test individual Limit Switches", IsDaily = false, IsMinor = false, IsMajor = true },
new() { Name = "Validate Gantry is Square", IsDaily = false, IsMinor = false, IsMajor = true },
new() { Name = "Verify screws/bolts correctly tightened", IsDaily = false, IsMinor = false, IsMajor = true },
};
}

return new List<ServiceItemsDataRow>();
return [];
}
}
}
2 changes: 1 addition & 1 deletion src/GCSDB/Tables/ToolDatabaseDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public List<ToolDatabaseDataRow> InitialData(ushort version)
{
return new List<ToolDatabaseDataRow>()
{
new ToolDatabaseDataRow() { ToolName = "(Default)", Description = "Default profile for no tool selected"}
new () { ToolName = "(Default)", Description = "Default profile for no tool selected"}
};
}

Expand Down
3 changes: 1 addition & 2 deletions src/GCSDesktop/Forms/FrmMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2664,8 +2664,7 @@ public List<IShortcut> GetShortcuts()

public void AddPlugin(IGSendPluginModule pluginModule)
{
if (pluginModule == null)
throw new ArgumentNullException(nameof(pluginModule));
ArgumentNullException.ThrowIfNull(pluginModule);

if (pluginModule.Options.HasFlag(PluginOptions.MessageReceived))
_pluginsWithClientMessage.Add(pluginModule);
Expand Down
3 changes: 1 addition & 2 deletions src/GCSDesktop/Internal/GSendContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public GSendContext(IServiceProvider serviceProvider, IGSendSettings gsendSettin

public void ShowMachine(IMachine machine)
{
if (machine == null)
throw new ArgumentNullException(nameof(machine));
ArgumentNullException.ThrowIfNull(machine);

if (!_machines.ContainsKey(machine))
{
Expand Down
3 changes: 1 addition & 2 deletions src/GCSService/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public IActionResult ViewLicense()
[HttpPost]
public IActionResult ViewLicense(AddLicenseModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
ArgumentNullException.ThrowIfNull(model);

if (String.IsNullOrEmpty(model.NewLicense))
ModelState.AddModelError(nameof(model.NewLicense), GSend.Language.Resources.LicenseInvalidEmpty);
Expand Down
9 changes: 3 additions & 6 deletions src/GCSService/Controllers/MachinesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public IActionResult Edit(long machineId)
[HttpPost]
public IActionResult Edit(EditMachineModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
ArgumentNullException.ThrowIfNull(model);

IMachine machine = _gSendDataProvider.MachineGet(model.Id);

Expand Down Expand Up @@ -127,8 +126,7 @@ public IActionResult Add()
[HttpPost]
public IActionResult Add(EditMachineModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
ArgumentNullException.ThrowIfNull(model);

if (ModelState.IsValid && _gSendDataProvider.MachinesGet().Any(m => m.Name == model.Name))
{
Expand Down Expand Up @@ -191,8 +189,7 @@ public IActionResult Delete(long machineId)
[HttpPost]
public IActionResult Delete(DeleteMachineModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
ArgumentNullException.ThrowIfNull(model);

IMachine machine = _gSendDataProvider.MachineGet(model.Id);

Expand Down
6 changes: 2 additions & 4 deletions src/GCSService/Controllers/ToolsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public IActionResult Add()
[HttpPost]
public IActionResult Add(ToolModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
ArgumentNullException.ThrowIfNull(model);

if (String.IsNullOrEmpty(model.Name))
ModelState.AddModelError(String.Empty, GSend.Language.Resources.ToolErrorInvalidName);
Expand Down Expand Up @@ -102,8 +101,7 @@ public IActionResult Edit(long id)
[HttpPost]
public IActionResult Edit(ToolModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
ArgumentNullException.ThrowIfNull(model);

if (String.IsNullOrEmpty(model.Name))
ModelState.AddModelError(String.Empty, GSend.Language.Resources.ToolErrorInvalidName);
Expand Down
6 changes: 2 additions & 4 deletions src/GCSService/Internal/LicenseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public ILicense LoadLicense(in string license)
/// <param name="license"></param>
public void SetActiveLicense(in ILicense license)
{
if (license == null)
throw new ArgumentNullException(nameof(license));
ArgumentNullException.ThrowIfNull(license);

if (!LicenseIsValid(license))
throw new InvalidLicenseException("License is not valid");
Expand All @@ -118,8 +117,7 @@ public void SetActiveLicense(in ILicense license)
/// <returns>bool</returns>
public bool LicenseIsValid(in ILicense license)
{
if (license == null)
throw new ArgumentNullException(nameof(license));
ArgumentNullException.ThrowIfNull(license);

return license.Expires > DateTime.MinValue &&
license.Expires >= DateTime.Now &&
Expand Down
3 changes: 1 addition & 2 deletions src/GCSService/Models/ServiceConfigurationMachineModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public ServiceConfigurationMachineModel()
public ServiceConfigurationMachineModel(BaseModelData modelData, IMachine machine)
: base(modelData)
{
if (machine == null)
throw new ArgumentNullException(nameof(machine));
ArgumentNullException.ThrowIfNull(machine);

MachineId = machine.Id;
Name = machine.Name;
Expand Down
Loading

0 comments on commit ff0fca5

Please sign in to comment.