Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup/nullable-ize StreamFactory, HttpServer, SessionID, SessionSchedule, SessionSettings, Settings #827

Merged
merged 3 commits into from
Feb 1, 2024
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
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
2 changes: 1 addition & 1 deletion QuickFIXn/SessionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SessionFactory(
IMessageFactory? messageFactory = null)
{
// TODO: for V2, consider ONLY instantiating MessageFactory in the Create() method,
// and removing instance var messageFactory_ altogether.
// and removing instance var _messageFactory altogether.
// This makes sense because we can't distinguish FIX50 versions here in this constructor,
// and thus can't create the right FIX-Version factory because we don't know what
// session to use to look up the BeginString and DefaultApplVerID.
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
Loading