Skip to content

Commit

Permalink
Improve configuration init; consistent exception types.
Browse files Browse the repository at this point in the history
Upgrade to MQTTnet 4.x

Prefer 'is null'

Prefer 'is null'
  • Loading branch information
joelp committed Nov 1, 2023
1 parent ed05a38 commit 6c506bd
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 110 deletions.
4 changes: 2 additions & 2 deletions XbeeSharp/src/TransmitATPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class TransmitATPacket
public static bool CreateXbeeFrame(out XbeeFrame? xbeeFrame, XbeeAddress address, byte frameId,
byte[] command, IReadOnlyList<byte> parameterValue, bool escaped)
{
if (command == null || command.Length != 2)
if (command is null || command.Length != 2)
{
throw new ArgumentException("command");
}
Expand Down Expand Up @@ -66,7 +66,7 @@ public static bool CreateXbeeFrame(out XbeeFrame? xbeeFrame, XbeeAddress address
throw new InvalidOperationException();
}
xbeeFrame = new XbeeFrame(rawData, escaped);
if (xbeeFrame == null)
if (xbeeFrame is null)
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions XbeeSharp/src/TransmitPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class TransmitPacket
public static bool CreateXbeeFrame(out XbeeFrame? xbeeFrame, XbeeAddress address,
byte frameId, IReadOnlyList<byte> data, bool escaped=false)
{
if (data == null)
if (data is null)
{
throw new ArgumentException("data");
}
Expand Down Expand Up @@ -65,7 +65,7 @@ public static bool CreateXbeeFrame(out XbeeFrame? xbeeFrame, XbeeAddress address
throw new InvalidOperationException();
}
xbeeFrame = new XbeeFrame(rawData, escaped);
if (xbeeFrame == null)
if (xbeeFrame is null)
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions XbeeSharp/src/XbeeAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private XbeeAddress(IReadOnlyList<byte> address)
/// </summary>
public static XbeeAddress Create(IReadOnlyList<byte> address)
{
if (address == null || address.Count != 8)
if (address is null || address.Count != 8)
{
throw new ArgumentException("address");
}
Expand All @@ -80,7 +80,7 @@ public static XbeeAddress Create(string address)
{
// Expecting format like 0x0013010203040506

if (address == null || address.Length != 18)
if (address is null || address.Length != 18)
{
throw new ArgumentException("address");
}
Expand Down
2 changes: 1 addition & 1 deletion XbeeSharp/src/XbeeSerial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class XbeeSerial
/// </summary>
public XbeeSerial(ILogger logger, CancellationToken stoppingToken)
{
if (logger == null)
if (logger is null)
{
throw new ArgumentNullException("logger");
}
Expand Down
10 changes: 10 additions & 0 deletions apps/xbee2mqtt/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
using xbee2mqtt;

var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional:true, reloadOnChange:true)
.AddEnvironmentVariables()
.Build();

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(builder =>
{
builder.Sources.Clear();
builder.AddConfiguration(configuration);
})
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
Expand Down
Loading

0 comments on commit 6c506bd

Please sign in to comment.