GetSessionID() public method

public GetSessionID ( Message m ) : SessionID
m Message
return SessionID
		public XElement BuildXML(QuickFix.Message msg,  MsgType msgType, DateTime? logTimeStamp = null, string origChkSum = null)
		{
			//Debug.WriteLine(" ~~~> " + msg.GetType().ToString());
			SessionID sessionID = msg.GetSessionID(msg);

			FIXClassInfo fixClass = null;
			if (msg.GetType() == typeof(QuickFix.Message))
			{
				var classes = fixClasses[msgType.ToString(), Utils.NormalizeFIXNameSpace(sessionID.BeginString)];
				if(classes != null && classes.Count>0)
					fixClass = classes[0];
			}

			//var root = new XElement(msg.GetType().ToString());
			var root = new XElement((fixClass!=null) ? fixClass.type.FullName : msg.GetType().ToString());
			root.Add(new XAttribute("MessageType", msgType.ToString()));
			root.Add(new XAttribute("Session", sessionID.ToString()));
			if(logTimeStamp.HasValue)
				root.Add(new XAttribute("LogTimeStamp", logTimeStamp.Value));	
			
			var header = new XElement(msg.Header.GetType().ToString());
			ProcessFieldMapToXML(header, msg.Header);
			root.Add(header);
			
			var body = new XElement(msg.GetType().ToString() + ".Body");
			ProcessFieldMapToXML(body, msg);
			root.Add(body);
			
			var trailer = new XElement(msg.Trailer.GetType().ToString());
			ProcessFieldMapToXML(trailer, msg.Trailer, origChkSum);
			root.Add(trailer);
			
			return root;
		}
        /*
         * //Sample
         * {
         *      "QuickFix.FIX44.ExecutionReport": {
         *  "MessageType":"QuickFix.FIX44.ExecutionReport",
         *  "Session":"FIX.4.4:BLP->MAP_GPSE_PRD",
         *  "LogTimeStamp":"2019-10-09T14:25:34.187Z",
         *  "Header": {
         *  }
         *  }
         * }
         */

        public string BuildJSON(QuickFix.Message msg, MsgType msgType, DateTime?logTimeStamp = null, string origChkSum = null)
        {
            //JObject jo = JObject.FromObject(fixMsg);
            //jo.Add("feeClass", "A");
            //string sJSON = jo.ToString();


            ////Debug.WriteLine(" ~~~> " + msg.GetType().ToString());
            SessionID sessionID = msg.GetSessionID(msg);

            FIXClassInfo fixClass = null;

            if (msg.GetType() == typeof(QuickFix.Message))
            {
                var classes = fixClasses[msgType.ToString(), Utils.NormalizeFIXNameSpace(sessionID.BeginString)];
                if (classes != null && classes.Count > 0)
                {
                    fixClass = classes[0];
                }
            }

            StringBuilder sb   = new StringBuilder();
            var           root = (fixClass != null) ? fixClass.type.FullName : msg.GetType().ToString();

            sb.Append("{");
            sb.Append($@"""{root}"":");
            sb.Append(FormatJSONPair("MessageType", msg.GetType().ToString()));
            sb.Append(FormatJSONPair("Session", sessionID.ToString()));
            sb.Append(FormatJSONPair("LogTimeStamp", logTimeStamp));

            ProcessFieldMapToJSON("Header", sb, msg.Header);
            ProcessFieldMapToJSON("Body", sb, msg);
            ProcessFieldMapToJSON("Trailer", sb, msg.Trailer, origChkSum);

            sb.Append("}");
            sb.Append("}");

            return(sb.ToString());
        }
Esempio n. 3
0
 /// <summary>
 /// Send to session indicated by header fields in message
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public static bool SendToTarget(Message message)
 {
     SessionID sessionID = message.GetSessionID(message);
     return SendToTarget(message, sessionID);
 }
Esempio n. 4
0
        public void TestGetSetSessionID()
        {
            SessionID sessionID = new SessionID("FIX.4.2", "SENDER", "SENDERSUB", "SENDERLOC", "TARGET", "TARGETSUB", "TARGETLOC");
            Message msg = new Message();

            msg.SetSessionID(sessionID);

            Assert.That(msg.Header.GetString(Tags.BeginString), Is.EqualTo("FIX.4.2"));
            Assert.That(msg.Header.GetString(Tags.SenderCompID), Is.EqualTo("SENDER"));
            Assert.That(msg.Header.GetString(Tags.SenderSubID), Is.EqualTo("SENDERSUB"));
            Assert.That(msg.Header.GetString(Tags.SenderLocationID), Is.EqualTo("SENDERLOC"));
            Assert.That(msg.Header.GetString(Tags.TargetCompID), Is.EqualTo("TARGET"));
            Assert.That(msg.Header.GetString(Tags.TargetSubID), Is.EqualTo("TARGETSUB"));
            Assert.That(msg.Header.GetString(Tags.TargetLocationID), Is.EqualTo("TARGETLOC"));

            SessionID getSessionID = msg.GetSessionID(msg);
            Assert.That(getSessionID.BeginString, Is.EqualTo("FIX.4.2"));
            Assert.That(getSessionID.SenderCompID, Is.EqualTo("SENDER"));
            Assert.That(getSessionID.SenderSubID, Is.EqualTo("SENDERSUB"));
            Assert.That(getSessionID.SenderLocationID, Is.EqualTo("SENDERLOC"));
            Assert.That(getSessionID.TargetCompID, Is.EqualTo("TARGET"));
            Assert.That(getSessionID.TargetSubID, Is.EqualTo("TARGETSUB"));
            Assert.That(getSessionID.TargetLocationID, Is.EqualTo("TARGETLOC"));

            ////
            sessionID = new SessionID("FIX.4.2", "SENDER", "TARGET");
            msg = new Message();

            msg.SetSessionID(sessionID);

            Assert.That(msg.Header.GetString(Tags.BeginString), Is.EqualTo("FIX.4.2"));
            Assert.That(msg.Header.GetString(Tags.SenderCompID), Is.EqualTo("SENDER"));
            Assert.That(msg.Header.IsSetField(Tags.SenderSubID), Is.False);
            Assert.That(msg.Header.IsSetField(Tags.SenderLocationID), Is.False);
            Assert.That(msg.Header.GetString(Tags.TargetCompID), Is.EqualTo("TARGET"));
            Assert.That(msg.Header.IsSetField(Tags.TargetSubID), Is.False);
            Assert.That(msg.Header.IsSetField(Tags.TargetLocationID), Is.False);

            getSessionID = msg.GetSessionID(msg);
            Assert.That(getSessionID.BeginString, Is.EqualTo("FIX.4.2"));
            Assert.That(getSessionID.SenderCompID, Is.EqualTo("SENDER"));
            Assert.That(getSessionID.SenderSubID, Is.EqualTo(""));
            Assert.That(getSessionID.SenderLocationID, Is.EqualTo(""));
            Assert.That(getSessionID.TargetCompID, Is.EqualTo("TARGET"));
            Assert.That(getSessionID.TargetSubID, Is.EqualTo(""));
            Assert.That(getSessionID.TargetLocationID, Is.EqualTo(""));
        }
Esempio n. 5
0
        /// <summary>
        /// Send to session indicated by header fields in message
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool SendToTarget(Message message)
        {
            SessionID sessionID = message.GetSessionID(message);

            return(SendToTarget(message, sessionID));
        }