Skip to content

Commit

Permalink
Dependency update and corresponding refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
peschuster committed Nov 7, 2023
1 parent 832f9ed commit afd32b2
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 70 deletions.
8 changes: 4 additions & 4 deletions dotnet/PITreaderClient.Tests/PITreaderClient.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/PITreaderClient/PITreaderClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<ItemGroup>
<PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion dotnet/PITreaderCommissioningTool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ Example to
- set an oem coding
- and download the final configuration of the device for backup

```
**Windows Batch:**

```batch
PITreaderCommissioningTool run ^
--set-ip 192.168.0.23 ^
--firmware PITreader_update_2-2-0.zip ^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="SharpCompress" Version="0.33.0" />
<PackageReference Include="SharpCompress" Version="0.34.1" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 0 additions & 19 deletions dotnet/PITreaderNetwork/Pilz.PITreader.Network.csproj

This file was deleted.

11 changes: 9 additions & 2 deletions dotnet/PITreaderTool/Commands/BlocklistCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ internal class BlocklistCommand : Command
// bl export <path to csv>
// bl import <path to csv>
*/
public BlocklistCommand(IValueDescriptor<ConnectionProperties> connectionPropertiesBinder)
public BlocklistCommand(ConnectionPropertiesBinder connectionPropertiesBinder)
: base("bl", "Import of blocklists")
{
var csvPathArgument = new Argument<string>("path to csv");

var importCommand = new Command("import", "Import blocklist from a csv file into a device");
importCommand.AddArgument(csvPathArgument);

System.CommandLine.Handler.SetHandler(importCommand, (ConnectionProperties c, string s) => this.HandleImport(c, s), connectionPropertiesBinder, csvPathArgument);
importCommand.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
string pathToCsv = ctx.ParseResult.GetValueForArgument(csvPathArgument);

return this.HandleImport(conn, pathToCsv);
});

this.AddCommand(importCommand);
}

Expand Down
25 changes: 16 additions & 9 deletions dotnet/PITreaderTool/Commands/CodingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@
//
// SPDX-License-Identifier: MIT

using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Binding;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using CsvHelper;
using CsvHelper.Configuration;
using Pilz.PITreader.Client;
using Pilz.PITreader.Client.Model;

Expand All @@ -31,7 +25,7 @@ internal class CodingCommand : Command
// coding set <coding> [<comment>]
// coding delete
*/
public CodingCommand(IValueDescriptor<ConnectionProperties> connectionPropertiesBinder)
public CodingCommand(ConnectionPropertiesBinder connectionPropertiesBinder)
: base("coding", "Set basic coding of device")
{
var codingArgument = new Argument<string>("coding", "coding identifier");
Expand All @@ -41,11 +35,24 @@ public CodingCommand(IValueDescriptor<ConnectionProperties> connectionProperties
setCommand.AddArgument(codingArgument);
setCommand.AddArgument(commentArgument);

System.CommandLine.Handler.SetHandler(setCommand, (ConnectionProperties c, string id, string comment, IConsole console) => this.HandleSet(c, id, comment, console), connectionPropertiesBinder, codingArgument, commentArgument);
setCommand.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
string id = ctx.ParseResult.GetValueForArgument(codingArgument);
string comment = ctx.ParseResult.GetValueForArgument(commentArgument);

return this.HandleSet(conn, id, comment, ctx.Console);
});

this.AddCommand(setCommand);

var deleteCommand = new Command("delete", "Delete basic coding of device");
System.CommandLine.Handler.SetHandler(deleteCommand, (ConnectionProperties c, IConsole console) => this.HandleDelete(c, console), connectionPropertiesBinder);
deleteCommand.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
return this.HandleDelete(conn, ctx.Console);
});

this.AddCommand(deleteCommand);
}

Expand Down
19 changes: 16 additions & 3 deletions dotnet/PITreaderTool/Commands/FirmwareCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ internal class FirmwareCommand : Command
// firmware version
// firmware update <path to fwu> [--force]
*/
public FirmwareCommand(IValueDescriptor<ConnectionProperties> connectionPropertiesBinder)
public FirmwareCommand(ConnectionPropertiesBinder connectionPropertiesBinder)
: base("firmware", "Firmware update")
{
var versionCommand = new Command("version", "Get firmware version");

System.CommandLine.Handler.SetHandler(versionCommand, (ConnectionProperties c, IConsole console) => this.HandleVersion(c, console), connectionPropertiesBinder);
versionCommand.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
return this.HandleVersion(conn, ctx.Console);
});

this.AddCommand(versionCommand);

var fwuPathArgument = new Argument<string>("path to *.fwu");
Expand All @@ -41,7 +46,15 @@ public FirmwareCommand(IValueDescriptor<ConnectionProperties> connectionProperti
updateCommand.AddArgument(fwuPathArgument);
updateCommand.AddOption(forceOption);

System.CommandLine.Handler.SetHandler(updateCommand, (ConnectionProperties c, IConsole console, string s, bool b) => this.HandleUpdate(c, console, s, b), connectionPropertiesBinder, fwuPathArgument, forceOption);
updateCommand.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
string fwuPath = ctx.ParseResult.GetValueForArgument(fwuPathArgument);
bool force = ctx.ParseResult.GetValueForOption(forceOption);

return this.HandleUpdate(conn, ctx.Console, fwuPath, force);
});

this.AddCommand(updateCommand);
}

Expand Down
8 changes: 6 additions & 2 deletions dotnet/PITreaderTool/Commands/StatusMonitorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ namespace Pilz.PITreader.Tool.Commands
{
internal class StatusMonitorCommand : Command
{
public StatusMonitorCommand(IValueDescriptor<ConnectionProperties> connectionPropertiesBinder)
public StatusMonitorCommand(ConnectionPropertiesBinder connectionPropertiesBinder)
: base("monitor", "Monitor the status of a PITreader")
{
System.CommandLine.Handler.SetHandler(this, (ConnectionProperties c, IConsole console) => this.Handle(c, console), connectionPropertiesBinder);
this.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
return this.Handle(conn, ctx.Console);
});
}

private Task Handle(ConnectionProperties properties, IConsole console)
Expand Down
34 changes: 30 additions & 4 deletions dotnet/PITreaderTool/Commands/TransponderCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System;
using System.CommandLine;
using System.CommandLine.Binding;
using System.CommandLine.Invocation;
using System.IO;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -31,14 +32,22 @@ internal class TransponderCommand : Command
// if --update-udc is set the user data configuration in the device is updated, if necessary.
// if --loop is set the operation runs forever and updates transponder when inserted.
*/
public TransponderCommand(IValueDescriptor<ConnectionProperties> connectionPropertiesBinder)
public TransponderCommand(ConnectionPropertiesBinder connectionPropertiesBinder)
: base("xpndr", "Export and writing of transponder content")
{
var jsonPathArg = new Argument<string>("path to json");

var xpndrExportCommand = new Command("export", "Export content of a transponder to file");
xpndrExportCommand.AddArgument(jsonPathArg);
System.CommandLine.Handler.SetHandler(xpndrExportCommand, (ConnectionProperties c, string s) => this.HandleExport(c, s), connectionPropertiesBinder, jsonPathArg);

xpndrExportCommand.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
string pathToJson = ctx.ParseResult.GetValueForArgument(jsonPathArg);

return this.HandleExport(conn, pathToJson);
});

this.AddCommand(xpndrExportCommand);

var xpndrWriteCommand = new Command("write", "Write data from file (see export) to transponders");
Expand All @@ -50,14 +59,31 @@ public TransponderCommand(IValueDescriptor<ConnectionProperties> connectionPrope

xpndrWriteCommand.AddArgument(jsonPathArg);

System.CommandLine.Handler.SetHandler(xpndrWriteCommand, (ConnectionProperties c, bool b1, bool b2, string s, IConsole console) => this.HandleWrite(c, b1, b2, s, console), connectionPropertiesBinder, updateUdcOption, loopOption, jsonPathArg);
xpndrWriteCommand.SetHandler((InvocationContext c) =>
{
var conn = connectionPropertiesBinder.GetValue(c);
bool updateUdc = c.ParseResult.GetValueForOption(updateUdcOption);
bool loop = c.ParseResult.GetValueForOption(loopOption);
string pathToJson = c.ParseResult.GetValueForArgument(jsonPathArg);

return this.HandleWrite(conn, updateUdc, loop, pathToJson, c.Console);
});

this.AddCommand(xpndrWriteCommand);

var xpndrLogCommand = new Command("log", "Log ids of transponder to file");

var csvPathArg = new Argument<string>("path to csv");
xpndrLogCommand.AddArgument(csvPathArg);
System.CommandLine.Handler.SetHandler(xpndrLogCommand, (ConnectionProperties c, string s, IConsole console) => this.HandleLog(c, s, console), connectionPropertiesBinder, csvPathArg);

xpndrLogCommand.SetHandler((InvocationContext c) =>
{
var conn = connectionPropertiesBinder.GetValue(c);
string pathToCsv = c.ParseResult.GetValueForArgument(csvPathArg);

return this.HandleLog(conn, pathToCsv, c.Console);
});

this.AddCommand(xpndrLogCommand);
}

Expand Down
22 changes: 19 additions & 3 deletions dotnet/PITreaderTool/Commands/UserDataConfigurationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,35 @@ internal class UserDataConfigurationCommand : Command
// udc export <path to json> Exports user data configuration of device to JSON file.
// udc import <path to json> Imports user data configuration from JSON file into device.
*/
public UserDataConfigurationCommand(IValueDescriptor<ConnectionProperties> connectionPropertiesBinder)
public UserDataConfigurationCommand(ConnectionPropertiesBinder connectionPropertiesBinder)
: base("udc", "Export and import of user data configurations")
{
var jsonPathArg = new Argument<string>("path to json");

var exportCommand = new Command("export", "Export user data configuration from a device to a json file");
exportCommand.AddArgument(jsonPathArg);
System.CommandLine.Handler.SetHandler(exportCommand, (ConnectionProperties c, string s) => this.HandleExport(c, s), connectionPropertiesBinder, jsonPathArg);

exportCommand.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
string jsonPath = ctx.ParseResult.GetValueForArgument(jsonPathArg);

return this.HandleExport(conn, jsonPath);
});

this.AddCommand(exportCommand);

var importCommand = new Command("import", "Import user data confguration from a json file to a device");
importCommand.AddArgument(jsonPathArg);
System.CommandLine.Handler.SetHandler(importCommand, (ConnectionProperties c, string s) => this.HandleImport(c, s), connectionPropertiesBinder, jsonPathArg);

importCommand.SetHandler(ctx =>
{
var conn = connectionPropertiesBinder.GetValue(ctx);
string jsonPath = ctx.ParseResult.GetValueForArgument(jsonPathArg);

return this.HandleImport(conn, jsonPath);
});

this.AddCommand(importCommand);
}

Expand Down
16 changes: 8 additions & 8 deletions dotnet/PITreaderTool/ConnectionPropertiesBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// SPDX-License-Identifier: MIT

using System.CommandLine;
using System.CommandLine.Binding;
using System.CommandLine.Invocation;

namespace Pilz.PITreader.Tool
{
internal class ConnectionPropertiesBinder : BinderBase<ConnectionProperties>
internal class ConnectionPropertiesBinder
{
private readonly Option<string> host;
private readonly Option<ushort> port;
Expand All @@ -34,15 +34,15 @@ public ConnectionPropertiesBinder(Option<string> host, Option<ushort> port, Opti
this.apiToken = apiToken;
}

protected override ConnectionProperties GetBoundValue(BindingContext bindingContext)
public ConnectionProperties GetValue(InvocationContext context)
{
var properties = new ConnectionProperties
{
Host = bindingContext.ParseResult.GetValueForOption(this.host),
Port = bindingContext.ParseResult.GetValueForOption(this.port),
AcceptAll = bindingContext.ParseResult.GetValueForOption(this.acceptAll),
Thumbprint = bindingContext.ParseResult.GetValueForOption(this.thumbprint),
ApiToken = bindingContext.ParseResult.GetValueForArgument(this.apiToken)
Host = context.ParseResult.GetValueForOption(this.host),
Port = context.ParseResult.GetValueForOption(this.port),
AcceptAll = context.ParseResult.GetValueForOption(this.acceptAll),
Thumbprint = context.ParseResult.GetValueForOption(this.thumbprint),
ApiToken = context.ParseResult.GetValueForArgument(this.apiToken)
};

return properties;
Expand Down
6 changes: 3 additions & 3 deletions dotnet/PITreaderTool/PITreaderTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CsvHelper" Version="27.2.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta2.21617.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta2.21617.1" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 4 additions & 6 deletions dotnet/PITreaderTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ private static int Main(string[] args)
rootCommand.AddCommand(new StatusMonitorCommand(clientBinder));
rootCommand.AddCommand(new FirmwareCommand(clientBinder));

rootCommand.AddValidator(commandResult =>
rootCommand.AddValidator(result =>
{
if (!commandResult.Children.Any(sr => sr.Symbol is IdentifierSymbol id && id.HasAlias(acceptAllOption.Name))
&& !commandResult.Children.Any(sr => sr.Symbol is IdentifierSymbol id && id.HasAlias(thumbprintOption.Name)))
if (!result.GetValueForOption(acceptAllOption)
&& string.IsNullOrEmpty(result.GetValueForOption(thumbprintOption)))
{
return $"One of the options '{acceptAllOption.Name}' or '{thumbprintOption.Name}' are required.";
result.ErrorMessage = $"One of the options '{acceptAllOption.Name}' or '{thumbprintOption.Name}' are required.";
}

return default(string);
});

return new CommandLineBuilder(rootCommand)
Expand Down

0 comments on commit afd32b2

Please sign in to comment.