Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mainworkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 17 additions & 12 deletions JMayer.Example.WindowsService/BSM/BSM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class BSM : ITypeB
/// </summary>
public const string Delete = "DEL";

/// <summary>
/// The constant for the element separator.
/// </summary>
public const char ElementSeparator = '/';

/// <summary>
/// The constant for the end of BSM.
/// </summary>
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -149,15 +154,15 @@ public void Parse(string typeBString)
int startIndex = typeBString.IndexOf('.', totalBytesProcessed);

//Dot was not found so exit.
if (startIndex == -1)
if (startIndex is -1)
{
break;
}

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;
}
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion JMayer.Example.WindowsService/BSM/BSMEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BSMEqualityComparer : IEqualityComparer<BSM>
/// <inheritdoc/>
public bool Equals(BSM? x, BSM? y)
{
if (x == null || y == null)
if (x is null || y is null)
{
return false;
}
Expand Down
11 changes: 3 additions & 8 deletions JMayer.Example.WindowsService/BSM/BSMGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,7 @@ public class BSMGenerator
/// <summary>
/// The default constructor.
/// </summary>
public BSMGenerator()
{
SetRandomDestination();
}
public BSMGenerator() => SetRandomDestination();

/// <summary>
/// The method returns the next BSM.
Expand Down Expand Up @@ -263,8 +260,6 @@ private void IncrementPassengerCount()
/// <summary>
/// The method sets a random destination.
/// </summary>
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);
}
13 changes: 5 additions & 8 deletions JMayer.Example.WindowsService/BSM/BSMPDU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,29 @@ public class BSMPDU : PDU
public BSM BSM { get; init; } = new();

/// <inheritdoc/>
public override byte[] ToBytes()
{
return Encoding.ASCII.GetBytes(BSM.ToTypeB());
}
public override byte[] ToBytes() => Encoding.ASCII.GetBytes(BSM.ToTypeB());

/// <inheritdoc/>
public override List<ValidationResult> Validate()
{
List<ValidationResult> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions JMayer.Example.WindowsService/BSM/BSMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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;
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class BaggageTagDetailEqualityComparer : IEqualityComparer<BaggageTagDeta
/// <inheritdoc/>
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)
{
Expand All @@ -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;
}
Expand All @@ -40,8 +40,5 @@ public bool Equals(BaggageTagDetails? x, BaggageTagDetails? y)
}

/// <inheritdoc/>
public int GetHashCode([DisallowNull] BaggageTagDetails obj)
{
throw new NotImplementedException();
}
public int GetHashCode([DisallowNull] BaggageTagDetails obj) => obj.GetHashCode();
}
43 changes: 27 additions & 16 deletions JMayer.Example.WindowsService/BSM/BaggageTagDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ public class BaggageTagDetails : ITypeB
/// <summary>
/// The property gets the number of baggage tag numbers.
/// </summary>
public int Count
{
get => BaggageTagNumbers.Count;
}
public int Count => BaggageTagNumbers.Count;

/// <summary>
/// The property gets a list of baggage tag numbers.
Expand All @@ -30,6 +27,11 @@ public int Count
/// </summary>
public const string DotNElement = ".N";

/// <summary>
/// The constant for the maximum character length of the .N element.
/// </summary>
private const int DotnMaximumCharacterLength = 13;

/// <summary>
/// The default constructor.
/// </summary>
Expand All @@ -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);
}
}

/// <inheritdoc/>
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}";
}
}
}
31 changes: 18 additions & 13 deletions JMayer.Example.WindowsService/BSM/OutboundFlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// The constant for the minimum character length for the airline/flight number element.
/// </summary>
private const int MiniumumFlightElementCharacterLength = 6;

/// <summary>
/// The default constructor.
/// </summary>
Expand All @@ -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];
}
Expand All @@ -109,17 +114,17 @@ public void Parse(string typeBString)
/// <inheritdoc/>
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}";
}
}
}
Loading