/// <summary> /// The ExportTrailer method is invoked to convert all of the /// elements in the trailer section of a VersaFix dictionary /// out to an XML QuickFix dictionary. /// </summary> /// <param name="src"> /// The source dictionary for the trailer elements. /// </param> /// <param name="dst"> /// The target dictionary for the trailer elements. /// </param> private void ExportTrailer(FixDictionary src, XmlQfxDictionary dst) { foreach (IFixDxElement dxElement in src.Trailer) { ExportElement(dxElement, dst.Trailer); } }
/// <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 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 PopulateTrailer method iterates over all of the elements /// that are defined in the trailer section of the QuickFix data /// dictionary and converts them into the trailer section of the /// supplied VersaFix data dictionary. /// </summary> /// <param name="src"> /// The XML representation of the QuickFix dictionary that the /// trailer elements are to be read from. /// </param> /// <param name="dst"> /// The VersaFix dictionary that the trailer elements are to be /// converted out to. /// </param> private void PopulateTrailer(XmlQfxDictionary src, FixDictionary dst) { foreach (object element in src.Trailer) { IFixDxElement dxElement = ConvertElement(element); if (dxElement != null) { dst.Trailer.Add(dxElement); } } }
/// <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)); } } } } } } }
/// <summary> /// The PopulateMessages method is invoked to convert all of /// the message definitions in a QuickFix dictionary into their /// corresponding representations in a VersaFix dictionary. /// </summary> /// <param name="src"> /// The source dictionary for the converted elements. /// </param> /// <param name="dst"> /// The target dictionary for the converted elements. /// </param> private void PopulateMessages(XmlQfxDictionary src, FixDictionary dst) { foreach (object message in src.Messages) { XmlQfxMessage xmlMessage = message as XmlQfxMessage; if (xmlMessage != null) { FixDxMessage dxMessage = new FixDxMessage(xmlMessage.MsgType, xmlMessage.Name, xmlMessage.MsgCategory); foreach (object element in xmlMessage.Elements) { dxMessage.Elements.Add(ConvertElement(element)); } dst.Messages.Add(dxMessage); } } }
/// <summary> /// The ExportBlocks method is invoked to convert all of /// the block 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 block definitions. /// </param> /// <param name="dst"> /// The target dictionary for the block definitions. /// </param> private void ExportBlocks(FixDictionary src, XmlQfxDictionary dst) { foreach (IFixDxElement dxElement in src.Blocks) { FixDxBlock dxBlock = dxElement as FixDxBlock; if (dxBlock != null) { XmlQfxBlock xmlBlock = new XmlQfxBlock(); xmlBlock.Name = dxBlock.Name; foreach (IFixDxElement dxBlockElement in dxBlock.Elements) { ExportElement(dxBlockElement, xmlBlock.Elements); } dst.Blocks.Add(xmlBlock); } } }
/// <summary> /// The ExportMessages method is invoked to convert all of /// the message 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 message definitions. /// </param> /// <param name="dst"> /// The target dictionary for the message definitions. /// </param> private void ExportMessages(FixDictionary src, XmlQfxDictionary dst) { foreach (IFixDxElement dxElement in src.Messages) { FixDxMessage dxMessage = dxElement as FixDxMessage; if (dxMessage != null) { XmlQfxMessage xmlMessage = new XmlQfxMessage(); xmlMessage.Name = dxMessage.Name; xmlMessage.MsgType = dxMessage.MsgType; xmlMessage.MsgCategory = dxMessage.MsgCategory; foreach (IFixDxElement dxMessageElement in dxMessage.Elements) { ExportElement(dxMessageElement, xmlMessage.Elements); } dst.Messages.Add(xmlMessage); } } }
/// <summary> /// The PopulateBlocks method is invoked to convert all of the /// component block definitions in a QuickFix dictionary into /// corresponding component block definitions in an instance of /// a VersaFix dictionary. /// </summary> /// <param name="src"> /// The QuickFix dictionary to copy the blocks from. /// </param> /// <param name="dst"> /// The VersaFix dictionary to copy the blocks into. /// </param> private void PopulateBlocks(XmlQfxDictionary src, FixDictionary dst) { foreach (object block in src.Blocks) { XmlQfxBlock xmlBlock = block as XmlQfxBlock; if (xmlBlock != null) { if (!string.IsNullOrEmpty(xmlBlock.Name)) { FixDxBlock dxBlock = new FixDxBlock(xmlBlock.Name); foreach (object element in xmlBlock.Elements) { IFixDxElement dxElement = ConvertElement(element); if (dxElement != null) { dxBlock.Elements.Add(dxElement); } } dst.Blocks.Add(dxBlock); } } } }
/// <summary> /// The Export method is invoked to export the contents /// of a VersaFix data dictionary out to a stream in a format /// that is compatible with the QuickFix system. /// </summary> /// <param name="dictionary"> /// The data dictionary that is to be exported. /// </param> /// <param name="stream"> /// The stream the dictionary is to be exported to. /// </param> public void Export(FixDictionary dictionary, Stream stream) { // REC: Convert the supplied VersaFix data dictionary // into its corresponding representation as an instance // of an QuickFix data dictionary: XmlQfxDictionary xmlDictionary = new XmlQfxDictionary(); // REC: Pull the metadata elements that correspond // to the QuickFIX attributes for the root element // and assign them to the appropriate fields: xmlDictionary.Type = "FIX"; if (dictionary.Properties.ContainsKey("Type")) { xmlDictionary.Type = dictionary.Properties["Type"]; } xmlDictionary.Major = "0"; if (dictionary.Properties.ContainsKey("Major")) { xmlDictionary.Major = dictionary.Properties["Major"]; } else if (dictionary.Properties.ContainsKey("Fix.Major")) { xmlDictionary.Major = dictionary.Properties["Fix.Major"]; } xmlDictionary.Minor = "0"; if (dictionary.Properties.ContainsKey("Minor")) { xmlDictionary.Minor = dictionary.Properties["Minor"]; } else if (dictionary.Properties.ContainsKey("Fix.Minor")) { xmlDictionary.Minor = dictionary.Properties["Fix.Minor"]; } // REC: Convert the header elements: ExportHeader(dictionary, xmlDictionary); // REC: Convert all of the fields: ExportFields(dictionary, xmlDictionary); // REC: Convert all of the blocks: ExportBlocks(dictionary, xmlDictionary); // REC: Convert all of the messages: ExportMessages(dictionary, xmlDictionary); // REC: Convert the trailer elements: ExportTrailer(dictionary, xmlDictionary); XmlSerializer xs = new XmlSerializer(typeof(XmlQfxDictionary)); XmlWriterSettings xwSettings = new XmlWriterSettings(); xwSettings.Indent = true; xwSettings.OmitXmlDeclaration = true; XmlSerializerNamespaces xsn = new XmlSerializerNamespaces(); xsn.Add("", ""); XmlWriter writer = XmlWriter.Create(stream, xwSettings); xs.Serialize(writer, xmlDictionary, xsn); return; }
/// <summary> /// The Import method is invoked to import a dictionary /// from a representation contained in a stream. /// </summary> /// <param name="stream"> /// The .NET stream that the dictionary representation /// is to be read from. /// </param> /// <returns> /// The FIX dictionary that is read from the stream or /// null if the import operation could not complete. /// </returns> public FixDictionary Import(System.IO.Stream stream) { try { // REC: Create a new serializer that can deserialize // the XmlQfxDictionary type from the stream: XmlSerializer xs = new XmlSerializer(typeof(XmlQfxDictionary)); // REC: Attempt to deserialize the QuickFix dictionary // from the stream into its corresponding representation // as an instance of XmlQfxDictionary: XmlQfxDictionary xmlDictionary = xs.Deserialize(stream) as XmlQfxDictionary; // REC: After the XML details have been deserialized from // the stream, convert them into an instance of the VersaFix // data dictionary class and return that to the caller: FixDictionary result = new FixDictionary(); if (!string.IsNullOrEmpty(xmlDictionary.Type)) { result.Properties.Add("Type", xmlDictionary.Type); } if (!string.IsNullOrEmpty(xmlDictionary.Major)) { result.Properties.Add("Fix.Major", xmlDictionary.Major); } if (!string.IsNullOrEmpty(xmlDictionary.Minor)) { result.Properties.Add("Fix.Minor", xmlDictionary.Minor); } // REC: Populate the dictionary's header elements using all // of the header elements from the QuickFix dictionary: PopulateHeader(xmlDictionary, result); // REC: Populate the dictionary's enumerations using all of // the enumerations from the QuickFix dictionary: PopulateEnums(xmlDictionary, result); // REC: Populate the dictionary's field definitions using all // of the field definitions from the QuickFix dictionary: PopulateFields(xmlDictionary, result); // REC: Populate the dictionary's block definitions using all // of the block definitions from the QuickFix dictionary: PopulateBlocks(xmlDictionary, result); // REC: Populate the dictionary's message definitions // with all of the message definitions that are found // in the QuickFix dictionary: PopulateMessages(xmlDictionary, result); // REC: Populate the dictionary's trailer elements using all // of the trailer elements from the QuickFix dictionary: PopulateTrailer(xmlDictionary, result); return(result); } catch (System.Exception) { return(null); } }