From a6e2ea471e7b6a70d4b6b3f6124cfcf1677057f4 Mon Sep 17 00:00:00 2001
From: jmayer913 <72579603+jmayer913@users.noreply.github.com>
Date: Thu, 20 Nov 2025 16:27:09 -0500
Subject: [PATCH 1/3] Updated Version, .NET & Packages
---
.github/workflows/mainworkflow.yml | 2 +-
.../JMayer.Example.WindowsService.csproj | 8 ++++----
TestProject/TestProject.csproj | 17 ++++++++++++-----
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/.github/workflows/mainworkflow.yml b/.github/workflows/mainworkflow.yml
index c8c3466..ba28f55 100644
--- a/.github/workflows/mainworkflow.yml
+++ b/.github/workflows/mainworkflow.yml
@@ -20,7 +20,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 8.0.x
+ dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
diff --git a/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj b/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
index 3af8922..177d515 100644
--- a/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
+++ b/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
@@ -1,16 +1,16 @@
- net8.0
+ net9.0
enable
enable
dotnet-JMayer.Example.WindowsService-4a84891d-50d1-410c-a081-1ab5bc58916f
- 1.1.0
+ 9.0.0
-
-
+
+
diff --git a/TestProject/TestProject.csproj b/TestProject/TestProject.csproj
index 53e930b..30c7c89 100644
--- a/TestProject/TestProject.csproj
+++ b/TestProject/TestProject.csproj
@@ -1,19 +1,26 @@
- net8.0
+ net9.0
enable
enable
false
true
+ 9.0.0
-
-
-
-
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
From bad1249cb4ceb1bf7482347563934c75a6fbb1f1 Mon Sep 17 00:00:00 2001
From: jmayer913 <72579603+jmayer913@users.noreply.github.com>
Date: Thu, 20 Nov 2025 17:10:43 -0500
Subject: [PATCH 2/3] Code Cleanup
---
JMayer.Example.WindowsService.sln | 6 +++
JMayer.Example.WindowsService/BSM/BSM.cs | 29 +++++-----
.../BSM/BSMEqualityComparer.cs | 2 +-
.../BSM/BSMGenerator.cs | 11 ++--
JMayer.Example.WindowsService/BSM/BSMPDU.cs | 13 ++---
.../BSM/BSMParser.cs | 4 +-
.../BSM/BaggageTagDetailEqualityComparer.cs | 11 ++--
.../BSM/BaggageTagDetails.cs | 43 +++++++++------
.../BSM/OutboundFlight.cs | 31 ++++++-----
.../BSM/OutboundFlightEqualityComparer.cs | 9 ++--
.../BSM/PassengerName.cs | 12 ++---
.../BSM/PassengerNameEqualityComparer.cs | 11 ++--
.../BSM/VersionSupplementaryData.cs | 13 +++--
...ersionSupplementaryDataEqualityComparer.cs | 9 ++--
.../BSMClientWorker.cs | 13 +++--
.../BSMServerConnectionWorker.cs | 4 +-
.../BSMServerOutputWorker.cs | 54 ++++++++++---------
.../JMayer.Example.WindowsService.csproj | 5 +-
18 files changed, 151 insertions(+), 129 deletions(-)
diff --git a/JMayer.Example.WindowsService.sln b/JMayer.Example.WindowsService.sln
index 4d39097..565f801 100644
--- a/JMayer.Example.WindowsService.sln
+++ b/JMayer.Example.WindowsService.sln
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JMayer.Example.WindowsServi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TestProject\TestProject.csproj", "{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JMayer.Net", "..\JMayer-Net-Library\JMayer.Net\JMayer.Net.csproj", "{199CC9E1-812C-35A6-C5C7-25E9AA074F07}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {199CC9E1-812C-35A6-C5C7-25E9AA074F07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {199CC9E1-812C-35A6-C5C7-25E9AA074F07}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {199CC9E1-812C-35A6-C5C7-25E9AA074F07}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {199CC9E1-812C-35A6-C5C7-25E9AA074F07}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/JMayer.Example.WindowsService/BSM/BSM.cs b/JMayer.Example.WindowsService/BSM/BSM.cs
index 22209e3..7010bc3 100644
--- a/JMayer.Example.WindowsService/BSM/BSM.cs
+++ b/JMayer.Example.WindowsService/BSM/BSM.cs
@@ -38,6 +38,11 @@ public class BSM : ITypeB
///
public const string Delete = "DEL";
+ ///
+ /// The constant for the element separator.
+ ///
+ public const char ElementSeparator = '/';
+
///
/// The constant for the end of BSM.
///
@@ -81,22 +86,22 @@ public BSM(BSM copy)
{
ChangeOfStatus = copy.ChangeOfStatus;
- if (copy.BaggageTagDetails != null)
+ if (copy.BaggageTagDetails is not null)
{
BaggageTagDetails = new BaggageTagDetails(copy.BaggageTagDetails);
}
- if (copy.OutboundFlight != null)
+ if (copy.OutboundFlight is not null)
{
OutboundFlight = new OutboundFlight(copy.OutboundFlight);
}
- if (copy.PassengerName != null)
+ if (copy.PassengerName is not null)
{
PassengerName = new PassengerName(copy.PassengerName);
}
- if (copy.VersionSupplementaryData != null)
+ if (copy.VersionSupplementaryData is not null)
{
VersionSupplementaryData = new VersionSupplementaryData(copy.VersionSupplementaryData);
}
@@ -111,11 +116,11 @@ private static string GetChangeOfStatus(string bsm)
{
string changeOfStatus = bsm.Substring(0, 3);
- if (changeOfStatus == Change)
+ if (changeOfStatus is Change)
{
return Change;
}
- else if (changeOfStatus == Delete)
+ else if (changeOfStatus is Delete)
{
return Delete;
}
@@ -149,7 +154,7 @@ public void Parse(string typeBString)
int startIndex = typeBString.IndexOf('.', totalBytesProcessed);
//Dot was not found so exit.
- if (startIndex == -1)
+ if (startIndex is -1)
{
break;
}
@@ -157,7 +162,7 @@ public void Parse(string typeBString)
int endIndex = typeBString.IndexOf('.', startIndex + 1);
//If the next dot is not found then assume this is the last line.
- if (endIndex == -1)
+ if (endIndex is -1)
{
endIndex = typeBString.Length;
}
@@ -195,22 +200,22 @@ public string ToTypeB()
{
string dotElements = string.Empty;
- if (OutboundFlight != null)
+ if (OutboundFlight is not null)
{
dotElements += OutboundFlight.ToTypeB();
}
- if (BaggageTagDetails != null)
+ if (BaggageTagDetails is not null)
{
dotElements += BaggageTagDetails.ToTypeB();
}
- if (PassengerName != null)
+ if (PassengerName is not null)
{
dotElements += PassengerName.ToTypeB();
}
- if (VersionSupplementaryData != null)
+ if (VersionSupplementaryData is not null)
{
dotElements += VersionSupplementaryData.ToTypeB();
}
diff --git a/JMayer.Example.WindowsService/BSM/BSMEqualityComparer.cs b/JMayer.Example.WindowsService/BSM/BSMEqualityComparer.cs
index 8e68531..69d7062 100644
--- a/JMayer.Example.WindowsService/BSM/BSMEqualityComparer.cs
+++ b/JMayer.Example.WindowsService/BSM/BSMEqualityComparer.cs
@@ -10,7 +10,7 @@ public class BSMEqualityComparer : IEqualityComparer
///
public bool Equals(BSM? x, BSM? y)
{
- if (x == null || y == null)
+ if (x is null || y is null)
{
return false;
}
diff --git a/JMayer.Example.WindowsService/BSM/BSMGenerator.cs b/JMayer.Example.WindowsService/BSM/BSMGenerator.cs
index fd128b4..fd4ab2a 100644
--- a/JMayer.Example.WindowsService/BSM/BSMGenerator.cs
+++ b/JMayer.Example.WindowsService/BSM/BSMGenerator.cs
@@ -167,10 +167,7 @@ public class BSMGenerator
///
/// The default constructor.
///
- public BSMGenerator()
- {
- SetRandomDestination();
- }
+ public BSMGenerator() => SetRandomDestination();
///
/// The method returns the next BSM.
@@ -263,8 +260,6 @@ private void IncrementPassengerCount()
///
/// The method sets a random destination.
///
- private void SetRandomDestination()
- {
- _destinationIndex = new Random(DateTime.Now.Second).Next(0, _destinations.Length - 1);
- }
+ private void SetRandomDestination()
+ => _destinationIndex = new Random(DateTime.Now.Second).Next(0, _destinations.Length - 1);
}
diff --git a/JMayer.Example.WindowsService/BSM/BSMPDU.cs b/JMayer.Example.WindowsService/BSM/BSMPDU.cs
index 9fd1fcc..27d6fbc 100644
--- a/JMayer.Example.WindowsService/BSM/BSMPDU.cs
+++ b/JMayer.Example.WindowsService/BSM/BSMPDU.cs
@@ -15,32 +15,29 @@ public class BSMPDU : PDU
public BSM BSM { get; init; } = new();
///
- public override byte[] ToBytes()
- {
- return Encoding.ASCII.GetBytes(BSM.ToTypeB());
- }
+ public override byte[] ToBytes() => Encoding.ASCII.GetBytes(BSM.ToTypeB());
///
public override List Validate()
{
List validationResults = [];
- if (BSM.BaggageTagDetails != null)
+ if (BSM.BaggageTagDetails is not null)
{
Validator.TryValidateObject(BSM.BaggageTagDetails, new ValidationContext(BSM.BaggageTagDetails), validationResults, validateAllProperties: true);
}
- if (BSM.OutboundFlight != null)
+ if (BSM.OutboundFlight is not null)
{
Validator.TryValidateObject(BSM.OutboundFlight, new ValidationContext(BSM.OutboundFlight), validationResults, validateAllProperties: true);
}
- if (BSM.PassengerName != null)
+ if (BSM.PassengerName is not null)
{
Validator.TryValidateObject(BSM.PassengerName, new ValidationContext(BSM.PassengerName), validationResults, validateAllProperties: true);
}
- if (BSM.VersionSupplementaryData != null)
+ if (BSM.VersionSupplementaryData is not null)
{
Validator.TryValidateObject(BSM.VersionSupplementaryData, new ValidationContext(BSM.VersionSupplementaryData), validationResults, validateAllProperties: true);
}
diff --git a/JMayer.Example.WindowsService/BSM/BSMParser.cs b/JMayer.Example.WindowsService/BSM/BSMParser.cs
index a34597c..4780f4c 100644
--- a/JMayer.Example.WindowsService/BSM/BSMParser.cs
+++ b/JMayer.Example.WindowsService/BSM/BSMParser.cs
@@ -21,7 +21,7 @@ protected override PDUParserResult SubClassParse(byte[] bytes)
int startIndex = bytesAsString.IndexOf(BSM.StartOfBSM, totalBytesProcessed);
//Start was not found so exit.
- if (startIndex == -1)
+ if (startIndex is -1)
{
break;
}
@@ -29,7 +29,7 @@ protected override PDUParserResult SubClassParse(byte[] bytes)
int endIndex = bytesAsString.IndexOf(BSM.EndOfBSM, startIndex);
//End was not found or start is actually the end, exit.
- if (endIndex == -1 || startIndex == endIndex)
+ if (endIndex is -1 || startIndex == endIndex)
{
break;
}
diff --git a/JMayer.Example.WindowsService/BSM/BaggageTagDetailEqualityComparer.cs b/JMayer.Example.WindowsService/BSM/BaggageTagDetailEqualityComparer.cs
index 59e5741..1b1f254 100644
--- a/JMayer.Example.WindowsService/BSM/BaggageTagDetailEqualityComparer.cs
+++ b/JMayer.Example.WindowsService/BSM/BaggageTagDetailEqualityComparer.cs
@@ -10,11 +10,11 @@ public class BaggageTagDetailEqualityComparer : IEqualityComparer
public bool Equals(BaggageTagDetails? x, BaggageTagDetails? y)
{
- if (x == null && y == null)
+ if (x is null && y is null)
{
return true;
}
- else if (x != null && y != null)
+ else if (x is not null && y is not null)
{
if (x.Count != y.Count)
{
@@ -24,7 +24,7 @@ public bool Equals(BaggageTagDetails? x, BaggageTagDetails? y)
{
foreach (string tag in x.BaggageTagNumbers)
{
- if (!y.BaggageTagNumbers.Contains(tag))
+ if (y.BaggageTagNumbers.Contains(tag) is false)
{
return false;
}
@@ -40,8 +40,5 @@ public bool Equals(BaggageTagDetails? x, BaggageTagDetails? y)
}
///
- public int GetHashCode([DisallowNull] BaggageTagDetails obj)
- {
- throw new NotImplementedException();
- }
+ public int GetHashCode([DisallowNull] BaggageTagDetails obj) => obj.GetHashCode();
}
diff --git a/JMayer.Example.WindowsService/BSM/BaggageTagDetails.cs b/JMayer.Example.WindowsService/BSM/BaggageTagDetails.cs
index 99838cc..e604d12 100644
--- a/JMayer.Example.WindowsService/BSM/BaggageTagDetails.cs
+++ b/JMayer.Example.WindowsService/BSM/BaggageTagDetails.cs
@@ -10,10 +10,7 @@ public class BaggageTagDetails : ITypeB
///
/// The property gets the number of baggage tag numbers.
///
- public int Count
- {
- get => BaggageTagNumbers.Count;
- }
+ public int Count => BaggageTagNumbers.Count;
///
/// The property gets a list of baggage tag numbers.
@@ -30,6 +27,11 @@ public int Count
///
public const string DotNElement = ".N";
+ ///
+ /// The constant for the maximum character length of the .N element.
+ ///
+ private const int DotnMaximumCharacterLength = 13;
+
///
/// The default constructor.
///
@@ -45,32 +47,41 @@ public BaggageTagDetails() { }
public void Parse(string typeBString)
{
//Remove the identifier and new line.
- typeBString = typeBString.Replace($"{DotNElement}/", string.Empty);
+ typeBString = typeBString.Replace($"{DotNElement}{BSM.ElementSeparator}", string.Empty);
typeBString = typeBString.Replace(Environment.NewLine, string.Empty);
- if (typeBString.Length is 13)
+ if (typeBString.Length is not DotnMaximumCharacterLength)
+ {
+ return;
+ }
+
+ if (long.TryParse(typeBString.AsSpan(0, 10), out long iataNumber) is false)
+ {
+ return;
+ }
+
+ if (int.TryParse(typeBString.AsSpan(10, 3), out int length) is false)
+ {
+ return;
+ }
+
+ for (int index = 0; index < length; index++)
{
- if (long.TryParse(typeBString.AsSpan(0, 10), out long iataNumber) && int.TryParse(typeBString.AsSpan(10, 3), out int length))
- {
- for (int index = 0; index < length; index++)
- {
- string iataString = (iataNumber + index).ToString().PadLeft(10, '0');
- BaggageTagNumbers.Add(iataString);
- }
- }
+ string iataString = (iataNumber + index).ToString().PadLeft(10, '0');
+ BaggageTagNumbers.Add(iataString);
}
}
///
public string ToTypeB()
{
- if (Count == 0)
+ if (Count is 0)
{
return string.Empty;
}
else
{
- return $"{DotNElement}/{BaggageTagNumbers[0]}{Count:D3}{Environment.NewLine}";
+ return $"{DotNElement}{BSM.ElementSeparator}{BaggageTagNumbers[0]}{Count:D3}{Environment.NewLine}";
}
}
}
diff --git a/JMayer.Example.WindowsService/BSM/OutboundFlight.cs b/JMayer.Example.WindowsService/BSM/OutboundFlight.cs
index d07e097..544c6d3 100644
--- a/JMayer.Example.WindowsService/BSM/OutboundFlight.cs
+++ b/JMayer.Example.WindowsService/BSM/OutboundFlight.cs
@@ -48,6 +48,11 @@ public class OutboundFlight : ITypeB
[RegularExpression("^([0-9]{4})|([0-9]{4}[A-Z]{1})$", ErrorMessage = "The flight number must be 4 digits and optionally a capital letter.")]
public string FlightNumber { get; set; } = string.Empty;
+ ///
+ /// The constant for the minimum character length for the airline/flight number element.
+ ///
+ private const int MiniumumFlightElementCharacterLength = 6;
+
///
/// The default constructor.
///
@@ -70,37 +75,37 @@ public OutboundFlight(OutboundFlight copy)
public void Parse(string typeBString)
{
//Remove the identifier so the elements can be broken apart with Split().
- typeBString = typeBString.Replace($"{DotFElement}/", string.Empty);
+ typeBString = typeBString.Replace($"{DotFElement}{BSM.ElementSeparator}", string.Empty);
typeBString = typeBString.Replace(Environment.NewLine, string.Empty);
- string[] elements = typeBString.Split('/');
+ string[] elements = typeBString.Split(BSM.ElementSeparator);
//Handle parsing the airline and flight number.
- if (elements.Length > 0 && !string.IsNullOrEmpty(elements[0]))
+ if (elements.Length > 0 && string.IsNullOrEmpty(elements[0]) is false)
{
string airlineAndFlight = elements[0];
- if (airlineAndFlight.Length >= 6)
+ if (airlineAndFlight.Length >= MiniumumFlightElementCharacterLength)
{
Airline = airlineAndFlight.Substring(0, 2);
- FlightNumber = airlineAndFlight.Substring(2, airlineAndFlight.Length - 2);
+ FlightNumber = airlineAndFlight.Substring(2);
}
}
//Handle parsing the flight date.
- if (elements.Length > 1 && !string.IsNullOrEmpty(elements[1]))
+ if (elements.Length > 1 && string.IsNullOrEmpty(elements[1]) is false)
{
FlightDate = elements[1];
}
//Handle parsing the destination.
- if (elements.Length > 2 && !string.IsNullOrEmpty(elements[2]))
+ if (elements.Length > 2 && string.IsNullOrEmpty(elements[2]) is false)
{
Destination = elements[2];
}
//Handle parsing the class of travel.
- if (elements.Length > 3 && !string.IsNullOrEmpty(elements[3]))
+ if (elements.Length > 3 && string.IsNullOrEmpty(elements[3]) is false)
{
ClassOfTravel = elements[3];
}
@@ -109,17 +114,17 @@ public void Parse(string typeBString)
///
public string ToTypeB()
{
- if (!string.IsNullOrEmpty(ClassOfTravel))
+ if (string.IsNullOrEmpty(ClassOfTravel) is false)
{
- return $"{DotFElement}/{Airline}{FlightNumber}/{FlightDate}/{Destination}/{ClassOfTravel}{Environment.NewLine}";
+ return $"{DotFElement}{BSM.ElementSeparator}{Airline}{FlightNumber}{BSM.ElementSeparator}{FlightDate}{BSM.ElementSeparator}{Destination}{BSM.ElementSeparator}{ClassOfTravel}{Environment.NewLine}";
}
- else if (!string.IsNullOrEmpty(Destination))
+ else if (string.IsNullOrEmpty(Destination) is false)
{
- return $"{DotFElement}/{Airline}{FlightNumber}/{FlightDate}/{Destination}{Environment.NewLine}";
+ return $"{DotFElement}{BSM.ElementSeparator}{Airline}{FlightNumber}{BSM.ElementSeparator}{FlightDate}{BSM.ElementSeparator}{Destination}{Environment.NewLine}";
}
else
{
- return $"{DotFElement}/{Airline}{FlightNumber}/{FlightDate}{Environment.NewLine}";
+ return $"{DotFElement}{BSM.ElementSeparator}{Airline}{FlightNumber}{BSM.ElementSeparator}{FlightDate}{Environment.NewLine}";
}
}
}
diff --git a/JMayer.Example.WindowsService/BSM/OutboundFlightEqualityComparer.cs b/JMayer.Example.WindowsService/BSM/OutboundFlightEqualityComparer.cs
index 0715ea0..0deb4ad 100644
--- a/JMayer.Example.WindowsService/BSM/OutboundFlightEqualityComparer.cs
+++ b/JMayer.Example.WindowsService/BSM/OutboundFlightEqualityComparer.cs
@@ -10,11 +10,11 @@ public class OutboundFlightEqualityComparer : IEqualityComparer
///
public bool Equals(OutboundFlight? x, OutboundFlight? y)
{
- if (x == null && y == null)
+ if (x is null && y is null)
{
return true;
}
- else if (x != null && y != null)
+ else if (x is not null && y is not null)
{
return x.Airline == y.Airline
&& x.ClassOfTravel == y.ClassOfTravel
@@ -29,8 +29,5 @@ public bool Equals(OutboundFlight? x, OutboundFlight? y)
}
///
- public int GetHashCode([DisallowNull] OutboundFlight obj)
- {
- throw new NotImplementedException();
- }
+ public int GetHashCode([DisallowNull] OutboundFlight obj) => obj.GetHashCode();
}
diff --git a/JMayer.Example.WindowsService/BSM/PassengerName.cs b/JMayer.Example.WindowsService/BSM/PassengerName.cs
index b8501a0..0e395b5 100644
--- a/JMayer.Example.WindowsService/BSM/PassengerName.cs
+++ b/JMayer.Example.WindowsService/BSM/PassengerName.cs
@@ -43,13 +43,13 @@ public PassengerName(PassengerName copy)
public void Parse(string typeBString)
{
//Remove the identifier so the elements can be broken apart with Split().
- typeBString = typeBString.Replace($"{DotPElement}/", string.Empty);
+ typeBString = typeBString.Replace($"{DotPElement}{BSM.ElementSeparator}", string.Empty);
typeBString = typeBString.Replace(Environment.NewLine , string.Empty);
- string[] elements = typeBString.Split('/');
+ string[] elements = typeBString.Split(BSM.ElementSeparator);
//Handle parsing the surname.
- if (elements.Length > 0 && !string.IsNullOrEmpty(elements[0]))
+ if (elements.Length > 0 && string.IsNullOrEmpty(elements[0]) is false)
{
//The number of given names can be infront of the surname as either a 1 or 2 digit number
//so remove the number if it exists.
@@ -72,7 +72,7 @@ public void Parse(string typeBString)
{
for (int index = 1; index < elements.Length; index++)
{
- if (!string.IsNullOrEmpty(elements[index]))
+ if (string.IsNullOrEmpty(elements[index]) is false)
{
GivenNames.Add(elements[index]);
}
@@ -87,9 +87,9 @@ public string ToTypeB()
foreach (string givenName in GivenNames)
{
- givenNames += $"/{givenName}";
+ givenNames += $"{BSM.ElementSeparator}{givenName}";
}
- return $"{DotPElement}/{GivenNames.Count}{SurName}{givenNames}{Environment.NewLine}";
+ return $"{DotPElement}{BSM.ElementSeparator}{GivenNames.Count}{SurName}{givenNames}{Environment.NewLine}";
}
}
diff --git a/JMayer.Example.WindowsService/BSM/PassengerNameEqualityComparer.cs b/JMayer.Example.WindowsService/BSM/PassengerNameEqualityComparer.cs
index 23a59db..511ece9 100644
--- a/JMayer.Example.WindowsService/BSM/PassengerNameEqualityComparer.cs
+++ b/JMayer.Example.WindowsService/BSM/PassengerNameEqualityComparer.cs
@@ -10,11 +10,11 @@ public class PassengerNameEqualityComparer : IEqualityComparer
///
public bool Equals(PassengerName? x, PassengerName? y)
{
- if (x == null && y == null)
+ if (x is null && y is null)
{
return true;
}
- else if (x != null && y != null)
+ else if (x is not null && y is not null)
{
if (x.SurName != y.SurName || x.GivenNames.Count != y.GivenNames.Count)
{
@@ -24,7 +24,7 @@ public bool Equals(PassengerName? x, PassengerName? y)
{
foreach (string givenName in x.GivenNames)
{
- if (!y.GivenNames.Contains(givenName))
+ if (y.GivenNames.Contains(givenName) is false)
{
return false;
}
@@ -40,8 +40,5 @@ public bool Equals(PassengerName? x, PassengerName? y)
}
///
- public int GetHashCode([DisallowNull] PassengerName obj)
- {
- throw new NotImplementedException();
- }
+ public int GetHashCode([DisallowNull] PassengerName obj) => obj.GetHashCode();
}
diff --git a/JMayer.Example.WindowsService/BSM/VersionSupplementaryData.cs b/JMayer.Example.WindowsService/BSM/VersionSupplementaryData.cs
index 3171c56..6359375 100644
--- a/JMayer.Example.WindowsService/BSM/VersionSupplementaryData.cs
+++ b/JMayer.Example.WindowsService/BSM/VersionSupplementaryData.cs
@@ -33,6 +33,11 @@ public class VersionSupplementaryData : ITypeB
///
public const string DotVElement = ".V";
+ ///
+ /// The constant for the minimum character length for the .V element.
+ ///
+ private const int DotvMinimumCharacterLength = 5;
+
///
/// The constant for the local baggage source indicator.
///
@@ -73,12 +78,12 @@ public VersionSupplementaryData(VersionSupplementaryData copy)
public void Parse(string typeBString)
{
//Remove the identifier so the elements can be broken apart with Split().
- typeBString = typeBString.Replace($"{DotVElement}/", string.Empty);
+ typeBString = typeBString.Replace($"{DotVElement}{BSM.ElementSeparator}", string.Empty);
typeBString = typeBString.Replace(Environment.NewLine, string.Empty);
- string[] elements = typeBString.Split('/');
+ string[] elements = typeBString.Split(BSM.ElementSeparator);
- if (elements.Length > 0 && elements[0].Length is 5)
+ if (elements.Length > 0 && elements[0].Length is DotvMinimumCharacterLength)
{
if (int.TryParse(elements[0].AsSpan(0, 1), out int dataDictionaryVersionNumber))
{
@@ -91,5 +96,5 @@ public void Parse(string typeBString)
}
///
- public string ToTypeB() => $"{DotVElement}/{DataDictionaryVersionNumber}{BaggageSourceIndicator}{AirportCode}{Environment.NewLine}";
+ public string ToTypeB() => $"{DotVElement}{BSM.ElementSeparator}{DataDictionaryVersionNumber}{BaggageSourceIndicator}{AirportCode}{Environment.NewLine}";
}
diff --git a/JMayer.Example.WindowsService/BSM/VersionSupplementaryDataEqualityComparer.cs b/JMayer.Example.WindowsService/BSM/VersionSupplementaryDataEqualityComparer.cs
index 0f6c3d5..a1ff10f 100644
--- a/JMayer.Example.WindowsService/BSM/VersionSupplementaryDataEqualityComparer.cs
+++ b/JMayer.Example.WindowsService/BSM/VersionSupplementaryDataEqualityComparer.cs
@@ -10,11 +10,11 @@ public class VersionSupplementaryDataEqualityComparer : IEqualityComparer
public bool Equals(VersionSupplementaryData? x, VersionSupplementaryData? y)
{
- if (x == null && y == null)
+ if (x is null && y is null)
{
return true;
}
- else if (x != null && y != null)
+ else if (x is not null && y is not null)
{
return x.AirportCode == y.AirportCode
&& x.BaggageSourceIndicator == y.BaggageSourceIndicator
@@ -27,8 +27,5 @@ public bool Equals(VersionSupplementaryData? x, VersionSupplementaryData? y)
}
///
- public int GetHashCode([DisallowNull] VersionSupplementaryData obj)
- {
- return obj.GetHashCode();
- }
+ public int GetHashCode([DisallowNull] VersionSupplementaryData obj) => obj.GetHashCode();
}
diff --git a/JMayer.Example.WindowsService/BSMClientWorker.cs b/JMayer.Example.WindowsService/BSMClientWorker.cs
index a670454..65129d2 100644
--- a/JMayer.Example.WindowsService/BSMClientWorker.cs
+++ b/JMayer.Example.WindowsService/BSMClientWorker.cs
@@ -19,6 +19,11 @@ internal class BSMClientWorker : BackgroundService
///
private readonly IClient _client;
+ ///
+ /// The constant for the local host.
+ ///
+ private const string LocalHost = "127.0.0.1";
+
///
/// The dependency injection constructor.
///
@@ -37,13 +42,13 @@ public BSMClientWorker(ILogger logger, IClient client
/// A Task object for the async.
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
- while (!stoppingToken.IsCancellationRequested)
+ while (stoppingToken.IsCancellationRequested is false)
{
- if (!_client.IsConnected)
+ if (_client.IsConnected is false)
{
try
{
- await _client.ConnectAsync("127.0.0.1", BSMServerConnectionWorker.Port, stoppingToken);
+ await _client.ConnectAsync(LocalHost, BSMServerConnectionWorker.Port, stoppingToken);
_logger.LogInformation("The client connected to the BSM server.");
}
catch (Exception ex)
@@ -68,7 +73,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}
}
- await Task.Delay(1000);
+ await Task.Delay(1000, stoppingToken);
}
}
diff --git a/JMayer.Example.WindowsService/BSMServerConnectionWorker.cs b/JMayer.Example.WindowsService/BSMServerConnectionWorker.cs
index dac55d1..da125b9 100644
--- a/JMayer.Example.WindowsService/BSMServerConnectionWorker.cs
+++ b/JMayer.Example.WindowsService/BSMServerConnectionWorker.cs
@@ -46,10 +46,10 @@ public BSMServerConnectionWorker(ILogger logger, ISer
/// A Task object for the async.
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
- while (!stoppingToken.IsCancellationRequested)
+ while (stoppingToken.IsCancellationRequested is false)
{
//Start the server if not ready.
- if (!_server.IsReady)
+ if (_server.IsReady is false)
{
try
{
diff --git a/JMayer.Example.WindowsService/BSMServerOutputWorker.cs b/JMayer.Example.WindowsService/BSMServerOutputWorker.cs
index 7ccadd7..cdf171c 100644
--- a/JMayer.Example.WindowsService/BSMServerOutputWorker.cs
+++ b/JMayer.Example.WindowsService/BSMServerOutputWorker.cs
@@ -43,40 +43,42 @@ public BSMServerOutputWorker(BSMGenerator bsmGenerator, ILoggerA Task object for the async.
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
- while (!stoppingToken.IsCancellationRequested)
+ while (stoppingToken.IsCancellationRequested is false)
{
- if (_server.IsReady && _server.ConnectionCount > 0)
+ if (_server.IsReady is false || _server.ConnectionCount is 0)
{
- //Generate a BSM & sends it to the remote clients.
- try
- {
- BSMPDU pdu = new()
- {
- BSM = _bsmGenerator.Generate(),
- };
- await _server.SendToAllAsync(pdu, stoppingToken);
- _logger.LogInformation("The BSM server sent a BSM to the remote clients. {BSM}", pdu.BSM.ToTypeB());
- }
- catch (Exception ex)
+ await Task.Delay(5_000, stoppingToken);
+ }
+
+ //Generate a BSM & sends it to the remote clients.
+ try
+ {
+ BSMPDU pdu = new()
{
- _logger.LogError(ex, "The BSM server failed to send the BSM to the remote clients.");
- }
+ BSM = _bsmGenerator.Generate(),
+ };
+ await _server.SendToAllAsync(pdu, stoppingToken);
+ _logger.LogInformation("The BSM server sent a BSM to the remote clients. {BSM}", pdu.BSM.ToTypeB());
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "The BSM server failed to send the BSM to the remote clients.");
+ }
- //Manage stale remote clients.
- List ids = _server.GetStaleRemoteConnections();
+ //Manage stale remote clients.
+ List ids = _server.GetStaleRemoteConnections();
- if (ids.Count > 0)
- {
- _logger.LogInformation("The BSM server detected stale remote clients; will attempt to disconnect.");
+ if (ids.Count > 0)
+ {
+ _logger.LogInformation("The BSM server detected stale remote clients; will attempt to disconnect.");
- foreach (Guid id in ids)
+ foreach (Guid id in ids)
+ {
+ try
{
- try
- {
- _server.Disconnect(id);
- }
- catch { }
+ _server.Disconnect(id);
}
+ catch { }
}
}
diff --git a/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj b/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
index 177d515..7e1e4dc 100644
--- a/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
+++ b/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
@@ -9,8 +9,11 @@
-
+
+
+
+
From 8db8807f4aed2be52e261bb84eff5efbc57d2f55 Mon Sep 17 00:00:00 2001
From: jmayer913 <72579603+jmayer913@users.noreply.github.com>
Date: Tue, 23 Dec 2025 12:51:49 -0500
Subject: [PATCH 3/3] Switched to package reference
---
JMayer.Example.WindowsService.sln | 6 ------
.../JMayer.Example.WindowsService.csproj | 5 +----
2 files changed, 1 insertion(+), 10 deletions(-)
diff --git a/JMayer.Example.WindowsService.sln b/JMayer.Example.WindowsService.sln
index 565f801..4d39097 100644
--- a/JMayer.Example.WindowsService.sln
+++ b/JMayer.Example.WindowsService.sln
@@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JMayer.Example.WindowsServi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TestProject\TestProject.csproj", "{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JMayer.Net", "..\JMayer-Net-Library\JMayer.Net\JMayer.Net.csproj", "{199CC9E1-812C-35A6-C5C7-25E9AA074F07}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -23,10 +21,6 @@ Global
{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}.Release|Any CPU.Build.0 = Release|Any CPU
- {199CC9E1-812C-35A6-C5C7-25E9AA074F07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {199CC9E1-812C-35A6-C5C7-25E9AA074F07}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {199CC9E1-812C-35A6-C5C7-25E9AA074F07}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {199CC9E1-812C-35A6-C5C7-25E9AA074F07}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj b/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
index 7e1e4dc..8357c30 100644
--- a/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
+++ b/JMayer.Example.WindowsService/JMayer.Example.WindowsService.csproj
@@ -9,11 +9,8 @@
+
-
-
-
-