Skip to content

Commit

Permalink
Merge pull request #1 from jmayer913/v1.0.0/VersionBranch
Browse files Browse the repository at this point in the history
V1.0.0/version branch
  • Loading branch information
jmayer913 committed Aug 17, 2024
2 parents 9183ee1 + dabf735 commit ef03820
Show file tree
Hide file tree
Showing 27 changed files with 2,760 additions and 26 deletions.
8 changes: 7 additions & 1 deletion JMayer.Example.WindowsService.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35208.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JMayer.Example.WindowsService", "JMayer.Example.WindowsService\JMayer.Example.WindowsService.csproj", "{0BC4DB3A-032F-43BA-BC39-380442F0BED0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JMayer.Example.WindowsService", "JMayer.Example.WindowsService\JMayer.Example.WindowsService.csproj", "{0BC4DB3A-032F-43BA-BC39-380442F0BED0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TestProject\TestProject.csproj", "{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{0BC4DB3A-032F-43BA-BC39-380442F0BED0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BC4DB3A-032F-43BA-BC39-380442F0BED0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BC4DB3A-032F-43BA-BC39-380442F0BED0}.Release|Any CPU.Build.0 = Release|Any CPU
{69EB99BC-2876-4339-AAFE-2AB2B406C0BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
35 changes: 35 additions & 0 deletions JMayer.Example.WindowsService/BSM/BMSEqualityComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Diagnostics.CodeAnalysis;

namespace JMayer.Example.WindowsService.BSM;

/// <summary>
/// The class manages comparing two BSM objects.
/// </summary>
public class BMSEqualityComparer : IEqualityComparer<BSM>
{
/// <inheritdoc/>
public bool Equals(BSM? x, BSM? y)
{
if (x == null || y == null)
{
return false;
}

BaggageTagDetailEqualityComparer baggageTagDetailEqualityComparer = new();
OutboundFlightEqualityComparer outboundFlightEqualityComparer = new();
PassengerNameEqualityComparer passengerNameEqualityComparer = new();
VersionSupplementaryDataEqualityComparer versionSupplementaryDataEqualityComparer = new();

return baggageTagDetailEqualityComparer.Equals(x.BaggageTagDetails, y.BaggageTagDetails)
&& x.ChangeOfStatus == y.ChangeOfStatus
&& outboundFlightEqualityComparer.Equals(x.OutboundFlight, y.OutboundFlight)
&& passengerNameEqualityComparer.Equals(x.PassengerName, y.PassengerName)
&& versionSupplementaryDataEqualityComparer.Equals(x.VersionSupplementaryData, y.VersionSupplementaryData);
}

/// <inheritdoc/>
public int GetHashCode([DisallowNull] BSM obj)
{
throw new NotImplementedException();
}
}
186 changes: 186 additions & 0 deletions JMayer.Example.WindowsService/BSM/BSM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
using System.ComponentModel.DataAnnotations;

namespace JMayer.Example.WindowsService.BSM;

/// <summary>
/// The class represents a simplified version of a baggage source message.
/// </summary>
/// <remarks>
/// A baggage source message contains the passenger information, outbound flight information,
/// the baggage checked in at the ticket counter and other data. The outbound system uses this
/// to bind a bag scanned at a scanner to a flight and to an end point in the system.
/// </remarks>
public class BSM : ITypeB
{
/// <summary>
/// The constant for the Add change of status.
/// </summary>
public const string Add = "ADD";

/// <summary>
/// The property gets the baggage tag details.
/// </summary>
public BaggageTagDetails? BaggageTagDetails { get; set; }

/// <summary>
/// The constant for the change change of status.
/// </summary>
public const string Change = "CHG";

/// <summary>
/// The property gets the change of status.
/// </summary>
[Required]
public string ChangeOfStatus { get; set; } = string.Empty;

/// <summary>
/// The constant for the delete change of status.
/// </summary>
public const string Delete = "DEL";

/// <summary>
/// The constant for the end of BSM.
/// </summary>
public const string EndOfBSM = "ENDBSM";

/// <summary>
/// The property gets the outbound flight information.
/// </summary>
public OutboundFlight? OutboundFlight { get; set; }

/// <summary>
/// The property gets the passenger name.
/// </summary>
public PassengerName? PassengerName { get; set; }

/// <summary>
/// The property gets when the BSM was received.
/// </summary>
public DateTime ReceivedOn { get; init; } = DateTime.Now;

/// <summary>
/// The constant for the start of BSM.
/// </summary>
public const string StartOfBSM = "BSM";

/// <summary>
/// The property gets the version supplementary data.
/// </summary>
public VersionSupplementaryData? VersionSupplementaryData { get; set; }

/// <summary>
/// The method returns the change of status from the BSM.
/// </summary>
/// <param name="bsm">The BSM to examine.</param>
/// <returns>The change of status.</returns>
private static string GetChangeOfStatus(string bsm)
{
string changeOfStatus = bsm.Substring(0, 3);

if (changeOfStatus == Change)
{
return Change;
}
else if (changeOfStatus == Delete)
{
return Delete;
}
else
{
return Add;
}
}

/// <inheritdoc/>
public void Parse(string typeBString)
{
//Remove the end identifier because it's no longer needed.
//This needs to be removed before start else you end up with only END.
typeBString = typeBString.Replace($"{EndOfBSM}{Environment.NewLine}", string.Empty);
typeBString = typeBString.Replace(EndOfBSM, string.Empty);

//Remove the start identifier because it's no longer needed.
typeBString = typeBString.Replace($"{StartOfBSM}{Environment.NewLine}", string.Empty);
typeBString = typeBString.Replace(StartOfBSM, string.Empty);

//Get the change of status and then remove it because its no longer needed
ChangeOfStatus = GetChangeOfStatus(typeBString);
typeBString = typeBString.Replace($"{ChangeOfStatus}{Environment.NewLine}", string.Empty);
typeBString = typeBString.Replace(ChangeOfStatus, string.Empty);

int totalBytesProcessed = 0;

do
{
int startIndex = typeBString.IndexOf('.', totalBytesProcessed);

//Dot was not found so exit.
if (startIndex == -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)
{
endIndex = typeBString.Length;
}

string line = typeBString.Substring(startIndex, endIndex - startIndex);

if (line.StartsWith(OutboundFlight.DotFElement))
{
OutboundFlight = new OutboundFlight();
OutboundFlight.Parse(line);
}
else if (line.StartsWith(BaggageTagDetails.DotNElement))
{
BaggageTagDetails = new BaggageTagDetails();
BaggageTagDetails.Parse(line);
}
else if (line.StartsWith(PassengerName.DotPElement))
{
PassengerName = new PassengerName();
PassengerName.Parse(line);
}
else if (line.StartsWith(VersionSupplementaryData.DotVElement))
{
VersionSupplementaryData = new VersionSupplementaryData();
VersionSupplementaryData.Parse(line);
}

totalBytesProcessed += line.Length;

} while (totalBytesProcessed < typeBString.Length);
}

/// <inheritdoc/>
public string ToTypeB()
{
string dotElements = string.Empty;

if (OutboundFlight != null)
{
dotElements += OutboundFlight.ToTypeB();
}

if (BaggageTagDetails != null)
{
dotElements += BaggageTagDetails.ToTypeB();
}

if (PassengerName != null)
{
dotElements += PassengerName.ToTypeB();
}

if (VersionSupplementaryData != null)
{
dotElements += VersionSupplementaryData.ToTypeB();
}

return $"{StartOfBSM}{Environment.NewLine}{ChangeOfStatus}{Environment.NewLine}{dotElements}{EndOfBSM}{Environment.NewLine}";
}
}
Loading

0 comments on commit ef03820

Please sign in to comment.