Skip to content

Commit

Permalink
cleanup/nullable-ize HttpServer/Session/Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gbirchmeier committed Feb 1, 2024
1 parent 7183cd2 commit 613d40d
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 369 deletions.
15 changes: 12 additions & 3 deletions QuickFIXn/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ private string EnableSessions(HttpListenerRequest request, StringBuilder pageBui

private string RefreshSession(HttpListenerRequest request, StringBuilder pageBuilder)
{
SessionID sessionId = new SessionID(request.QueryString["beginstring"], request.QueryString["sendercompid"], request.QueryString["targetcompid"]);
SessionID sessionId = new SessionID(
request.QueryString["beginstring"] ?? "",
request.QueryString["sendercompid"] ?? "",
request.QueryString["targetcompid"] ?? "");
Session? sessionDetails = Session.LookupSession(sessionId);
if (sessionDetails == null) throw new Exception("Session not found");
bool confirm = false;
Expand Down Expand Up @@ -248,7 +251,10 @@ private string ResetSessions(HttpListenerRequest request, StringBuilder pageBuil

private string ResetSession(HttpListenerRequest request, StringBuilder pageBuilder)
{
SessionID sessionId = new SessionID(request.QueryString["beginstring"], request.QueryString["sendercompid"], request.QueryString["targetcompid"]);
SessionID sessionId = new SessionID(
request.QueryString["beginstring"] ?? "",
request.QueryString["sendercompid"] ?? "",
request.QueryString["targetcompid"] ?? "");
Session? sessionDetails = Session.LookupSession(sessionId);
if (sessionDetails == null) throw new Exception("Session not found");

Expand Down Expand Up @@ -326,7 +332,10 @@ private string ProcessRoot(HttpListenerRequest request, StringBuilder pageBuilde

private string SessionDetails(HttpListenerRequest request, StringBuilder pageBuilder)
{
SessionID sessionId = new SessionID(request.QueryString["beginstring"], request.QueryString["sendercompid"], request.QueryString["targetcompid"]);
SessionID sessionId = new SessionID(
request.QueryString["beginstring"] ?? "",
request.QueryString["sendercompid"] ?? "",
request.QueryString["targetcompid"] ?? "");
Session? sessionDetails = Session.LookupSession(sessionId);
if (sessionDetails == null) throw new Exception("Session not found");

Expand Down
131 changes: 40 additions & 91 deletions QuickFIXn/SessionID.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#nullable enable
using System;

namespace QuickFix
Expand All @@ -8,64 +8,36 @@ namespace QuickFix
/// and a session qualifier. Sessions are also identified by FIX version so
/// that it's possible to have multiple sessions to the same counterparty
/// but using different FIX versions (and/or session qualifiers).
///
/// </summary>
public class SessionID
{
#region Properties

public string BeginString
{
get { return beginString_; }
}
public string BeginString { get; }

public string SenderCompID
{
get { return senderCompID_; }
}
public string SenderCompID { get; }

public string SenderSubID
{
get { return senderSubID_; }
}
public string SenderSubID { get; }

public string SenderLocationID
{
get { return senderLocationID_; }
}
public string SenderLocationID { get; }

public string TargetCompID
{
get { return targetCompID_; }
}
public string TargetCompID { get; }

public string TargetSubID
{
get { return targetSubID_; }
}
public string TargetSubID { get; }

public string TargetLocationID
{
get { return targetLocationID_; }
}
public string TargetLocationID { get; }

/// <summary>
/// Session qualifier can be used to identify different sessions
/// for the same target company ID. Session qualifiers can only be used
/// with initiated sessions. They cannot be used with accepted sessions.
/// </summary>
public string SessionQualifier
{
get { return sessionQualifier_; }
}
public string? SessionQualifier { get; }

/// <summary>
/// Returns whether session version is FIXT 1.1 or newer
/// </summary>
public bool IsFIXT
{
get { return isFIXT_; }
}
public bool IsFIXT { get; }

#endregion

Expand All @@ -74,87 +46,64 @@ public bool IsFIXT
#endregion

#region Private Members
private string id_;
private string beginString_;
private string senderCompID_;
private string senderSubID_;
private string senderLocationID_;
private string targetCompID_;
private string targetSubID_;
private string targetLocationID_;
private string sessionQualifier_;
private bool isFIXT_;
private readonly string _id;

#endregion

public SessionID(string beginString, string senderCompID, string senderSubID, string senderLocationID, string targetCompID, string targetSubID, string targetLocationID, string sessionQualifier)
public SessionID(string beginString, string senderCompId, string senderSubId, string senderLocationId, string targetCompId, string targetSubId, string targetLocationId, string? sessionQualifier = NOT_SET)
{
if (beginString == null)
throw new ArgumentNullException("beginString");
if (senderCompID == null)
throw new ArgumentNullException("senderCompID");
if (targetCompID == null)
throw new ArgumentNullException("targetCompID");
beginString_ = beginString;
senderCompID_ = senderCompID;
senderSubID_ = senderSubID;
senderLocationID_ = senderLocationID;
targetCompID_ = targetCompID;
targetSubID_ = targetSubID;
targetLocationID_ = targetLocationID;
sessionQualifier_ = sessionQualifier;
isFIXT_ = beginString_.StartsWith("FIXT", StringComparison.Ordinal);

id_ = beginString_
BeginString = beginString ?? throw new ArgumentNullException(nameof(beginString));
SenderCompID = senderCompId ?? throw new ArgumentNullException(nameof(senderCompId));
SenderSubID = senderSubId;
SenderLocationID = senderLocationId;
TargetCompID = targetCompId ?? throw new ArgumentNullException(nameof(targetCompId));
TargetSubID = targetSubId;
TargetLocationID = targetLocationId;
SessionQualifier = sessionQualifier;
IsFIXT = BeginString.StartsWith("FIXT", StringComparison.Ordinal);

_id = BeginString
+ ":"
+ senderCompID_
+ (IsSet(senderSubID_) ? "/" + senderSubID_ : "")
+ (IsSet(senderLocationID_) ? "/" + senderLocationID_ : "")
+ SenderCompID
+ (IsSet(SenderSubID) ? "/" + SenderSubID : "")
+ (IsSet(SenderLocationID) ? "/" + SenderLocationID : "")
+ "->"
+ targetCompID_
+ (IsSet(targetSubID_) ? "/" + targetSubID_ : "")
+ (IsSet(targetLocationID_) ? "/" + targetLocationID_ : "");
if (null != sessionQualifier_ && sessionQualifier_.Length > 0)
id_ += ":" + sessionQualifier_;
+ TargetCompID
+ (IsSet(TargetSubID) ? "/" + TargetSubID : "")
+ (IsSet(TargetLocationID) ? "/" + TargetLocationID : "");
if (SessionQualifier is not null && SessionQualifier.Length > 0)
_id += ":" + SessionQualifier;
}

public SessionID(string beginString, string senderCompID, string targetCompID)
: this(beginString, senderCompID, targetCompID, NOT_SET)
{ }

public SessionID(string beginString, string senderCompID, string senderSubID, string targetCompID, string targetSubID)
: this(beginString, senderCompID, senderSubID, NOT_SET, targetCompID, targetSubID, NOT_SET, NOT_SET)
{ }

public SessionID(string beginString, string senderCompID, string senderSubID, string senderLocationID, string targetCompID, string targetSubID, string targetLocationID)
: this(beginString, senderCompID, senderSubID, senderLocationID, targetCompID, targetSubID, targetLocationID, NOT_SET)
public SessionID(string beginString, string senderCompId, string senderSubId, string targetCompId, string targetSubId)
: this(beginString, senderCompId, senderSubId, senderLocationId: NOT_SET, targetCompId, targetSubId, targetLocationId: NOT_SET)
{ }

public SessionID(string beginString, string senderCompID, string targetCompID, string sessionQualifier)
: this(beginString, senderCompID, NOT_SET, NOT_SET, targetCompID, NOT_SET, NOT_SET, sessionQualifier)
public SessionID(string beginString, string senderCompId, string targetCompId, string sessionQualifier = NOT_SET)
: this(beginString, senderCompId, senderSubId: NOT_SET, senderLocationId: NOT_SET, targetCompId, targetSubId: NOT_SET, targetLocationId: NOT_SET, sessionQualifier)
{ }

public static bool IsSet(string value)
public static bool IsSet(string? value)
{
return value != null && value != NOT_SET;
}

public override string ToString()
{
return id_;
return _id;
}

public override int GetHashCode()
{
return id_.GetHashCode();
return _id.GetHashCode();
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
SessionID rhs = (SessionID)obj;
return id_.Equals(rhs.id_);
return _id.Equals(rhs._id);
}
}
}
Loading

0 comments on commit 613d40d

Please sign in to comment.