/// <summary> /// The ExportFields method is invoked to convert all of /// the field elements in an instance of a VersaFix data /// dictionary into corresponding entries in an instance /// of an XML representation of a QuickFix dictionary. /// </summary> /// <param name="src"> /// The source dictionary for the field definitions. /// </param> /// <param name="dst"> /// The target dictionary for the field definitions. /// </param> private void ExportFields(FixDictionary src, XmlQfxDictionary dst) { foreach (IFixDxElement dxElement in src.Fields) { FixDxField dxField = dxElement as FixDxField; if (dxField != null) { XmlQfxField xmlField = new XmlQfxField(); xmlField.Name = dxField.Name; xmlField.Number = dxField.Tag.ToString(); xmlField.Type = dxField.Type; // REC: QuickFix stores the enumerators for each // field inside the field definition, so we have // to check if there is an enumeration associated // with this field and add the enumeration to the // field definition if one is found: FixDxEnumeration dxEnum = src.Enums.GetElement(dxField.Name) as FixDxEnumeration; if (dxEnum != null) { foreach (FixDxEnumerator dxEnumerator in dxEnum.Enumerators) { XmlQfxFieldEnumerator xmlEnumerator = new XmlQfxFieldEnumerator(); xmlEnumerator.Enum = dxEnumerator.Value; xmlEnumerator.Description = dxEnumerator.Description; xmlField.Enumeration.Add(xmlEnumerator); } } dst.Fields.Add(xmlField); } } }
/// <summary> /// The PopulateEnums method iterates over all of the fields that /// are defined in a QuickFix dictionary and converts their inline /// enumeration definitions into discreet enumeration instances in /// the target VersaFix dictionary instance. /// </summary> /// <param name="src"> /// The XML representation of a QuickFix dictionary that the /// enumerations are to be read from. /// </param> /// <param name="dst"> /// The VersaFix dictionary that the enumerations are to be /// written out to. /// </param> private void PopulateEnums(XmlQfxDictionary src, FixDictionary dst) { foreach (object field in src.Fields) { XmlQfxField xmlField = field as XmlQfxField; if (xmlField != null) { if (xmlField.Enumeration.Count > 0) { string xmlName = xmlField.Name; if (!string.IsNullOrEmpty(xmlName)) { FixDxEnumeration dxEnum = new FixDxEnumeration(xmlName); foreach (object enumerator in xmlField.Enumeration) { XmlQfxFieldEnumerator xmlEnumerator = enumerator as XmlQfxFieldEnumerator; if (xmlEnumerator != null) { dxEnum.Enumerators.Add(new FixDxEnumerator(xmlEnumerator.Enum, xmlEnumerator.Description)); } } dst.Enums.Add(dxEnum); } } } } }
/// <summary> /// The PopulateFields method is invoked to convert all of /// the FIX field definitions in an instance of a QuickFix /// dictionary into their corresponding representations as /// elements of a VersaFix dictionary. /// </summary> /// <param name="src"> /// The XML representation of a QuickFix dictionary that the /// fields are to be copied from. /// </param> /// <param name="dst"> /// The VersaFix data dictionary that the field definitions /// are to be copied into. /// </param> private void PopulateFields(XmlQfxDictionary src, FixDictionary dst) { foreach (object field in src.Fields) { XmlQfxField xmlField = field as XmlQfxField; if (xmlField != null) { if (!string.IsNullOrEmpty(xmlField.Name)) { if (!string.IsNullOrEmpty(xmlField.Number)) { int nTag = int.Parse(xmlField.Number); FixDxField dxField = new FixDxField(nTag, xmlField.Name); // REC: Determine if there's an enumeration that corresponds // to the name of this field: if (dst.Enums.GetElement(xmlField.Name) != null) { // REC: If an enumeration exists for this field // then assign it to the VersaFix field: dxField.Enumeration = xmlField.Name; } // REC: Assign the field's data type directly // from the data type in the QuickFix field. dxField.Type = xmlField.Type; dst.Fields.Add(dxField); // REC: The QuickFix dictionaries do not provide // a separate section for data types, so we need // to just copy the data type directly from each // of the QuickFix fields into the data types of // the VersaFix dictionary: if (!string.IsNullOrEmpty(xmlField.Type)) { IFixDxElement exists = dst.DataTypes.GetElement(xmlField.Type); if (exists == null) { dst.DataTypes.Add(new FixDxDataType(xmlField.Type)); } } } } } } }