forked from connamara/quickfixn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSessionID.cs
executable file
·160 lines (136 loc) · 5.18 KB
/
SessionID.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
namespace QuickFix
{
/// <summary>
/// Identifies a session. Only supports a company ID (target, sender)
/// 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 SenderCompID
{
get { return senderCompID_; }
}
public string SenderSubID
{
get { return senderSubID_; }
}
public string SenderLocationID
{
get { return senderLocationID_; }
}
public string TargetCompID
{
get { return targetCompID_; }
}
public string TargetSubID
{
get { return targetSubID_; }
}
public string TargetLocationID
{
get { return targetLocationID_; }
}
/// <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_; }
}
/// <summary>
/// Returns whether session version is FIXT 1.1 or newer
/// </summary>
public bool IsFIXT
{
get { return isFIXT_; }
}
#endregion
#region Public Members
public const string NOT_SET = "";
#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_;
#endregion
public SessionID(string beginString, string senderCompID, string senderSubID, string senderLocationID, string targetCompID, string targetSubID, string targetLocationID, string sessionQualifier)
{
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");
id_ = beginString_
+ ":"
+ senderCompID_
+ (IsSet(senderSubID_) ? "/" + senderSubID_ : "")
+ (IsSet(senderLocationID_) ? "/" + senderLocationID_ : "")
+ "->"
+ targetCompID_
+ (IsSet(targetSubID_) ? "/" + targetSubID_ : "")
+ (IsSet(targetLocationID_) ? "/" + targetLocationID_ : "");
if (null != sessionQualifier_ && 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 targetCompID, string sessionQualifier)
: this(beginString, senderCompID, NOT_SET, NOT_SET, targetCompID, NOT_SET, NOT_SET, sessionQualifier)
{ }
public static bool IsSet(string value)
{
return value != null && value != NOT_SET;
}
public override string ToString()
{
return id_;
}
public override int GetHashCode()
{
return id_.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
SessionID rhs = (SessionID)obj;
return id_.Equals(rhs.id_);
}
}
}