//See onGatewayStatusMessage or MarketDataSnapshotFullRefresh for example of parsing a group public void parseMessage(QuickFix.Message message, QuickFix.SessionID sessionID) { try { updateDisplay(message.GetType().FullName); QuickFix.SenderSubID senderID = new SenderSubID(); QuickFix.TargetSubID targetID = new TargetSubID(); QuickFix.OnBehalfOfSubID oboID = new OnBehalfOfSubID(); if (message.getHeader().isSetField(senderID)) { updateDisplay(string.Format("SenderSubID: {0}", message.getHeader().getField(senderID))); } if (message.getHeader().isSetField(targetID)) { updateDisplay(string.Format("TargetSubID: {0}", message.getHeader().getField(targetID))); } if (message.getHeader().isSetField(oboID)) { updateDisplay(string.Format("OnBehalfOfSubID: {0}", message.getHeader().getField(oboID))); } foreach (QuickFix.Field f in message) { updateDisplay(string.Format("TAG: {0} = {1}", f.getField(), f)); } } catch (Exception ex) { updateDisplay(ex.ToString()); } }
public static string ToString(this Message msg, bool parse = false) { if (!parse) { return(msg.ToString()); } StringBuilder stringBuilder = new StringBuilder(); var ObjRef = msg.GetType(); stringBuilder.AppendLine(ObjRef.Name); foreach (var property in ObjRef.GetProperties()) { try { object upValue = property.GetValue(msg); object value = property.PropertyType.GetProperty("Obj").GetValue(upValue); //Check and fiil static fileds used like enum var StaticFiels = property.PropertyType .GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) .Where(p => p.IsLiteral && !p.IsInitOnly).GroupBy(p => p.GetRawConstantValue(), v => v.Name) .ToDictionary(group => group.Key, group => group.Aggregate( (res, add) => $"{add} or {res}")); if (StaticFiels.Count > 0 && StaticFiels.ContainsKey(value)) { value = $"{value} ({StaticFiels[value]})"; } stringBuilder.AppendLine($"\t{property.Name}: {value}"); } catch (Exception e) { } } return(stringBuilder.ToString()); }