示例#1
0
 /// <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);
     }
 }
示例#2
0
        /// <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);
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// The Export method is invoked to export the contents
        /// of a VersaFix data dictionary out to a file 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="path">
        /// The file the dictionary's data is to be saved to.
        /// </param>
        public void Export(FixDictionary dictionary, string path)
        {
            FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);

            Export(dictionary, fs);
            fs.Close();
        }
示例#4
0
        /// <summary>
        /// This implementation of the Export method serializes the
        /// specified dictionary out to a stream that has already been
        /// opened by the caller.
        /// </summary>
        /// <param name="dictionary">
        /// The dictionary that is to be exported.
        /// </param>
        /// <param name="stream">
        /// The stream that the XML data is to be written to.
        /// </param>
        public void Export(FixDictionary dictionary, Stream stream)
        {
            XmlDictionary xmlDictionary = new XmlDictionary();

            // REC: Populate the XML dictionary with all of the
            // elements from the supplied FixDictionary instance:
            PopulateMetadata(dictionary, xmlDictionary);
            PopulateHeader(xmlDictionary, dictionary);
            PopulateTrailer(xmlDictionary, dictionary);
            PopulateMessages(xmlDictionary, dictionary);
            PopulateFields(xmlDictionary, dictionary);
            PopulateDataTypes(xmlDictionary, dictionary);
            PopulateBlocks(xmlDictionary, dictionary);
            PopulateEnums(xmlDictionary, dictionary);

            // REC: After the XML serializable representation of
            // the dictionary has been populated, use the serializer
            // to export its contents out to the specified stream:
            XmlSerializer     xs         = new XmlSerializer(typeof(XmlDictionary));
            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);
        }
示例#5
0
 /// <summary>
 /// The PopulateMetadata method populates the metadata properties
 /// of a VersaFix FIX data dictionary with the properties that are
 /// found in an instance of an XML representation of a dictionary.
 /// </summary>
 /// <param name="source">
 /// The source dictionary to read the properties from.
 /// </param>
 /// <param name="target">
 /// The target dictionary to add the properties to.
 /// </param>
 private static void PopulateMetadata(XmlDictionary source, FixDictionary target)
 {
     foreach (XmlFixDxProperty xmlProperty in source.Properties.Elements)
     {
         target.Properties.Add(xmlProperty.Name, xmlProperty.Value);
     }
 }
示例#6
0
 /// <summary>
 /// The PopulateTrailer method populates the trailer section
 /// of the supplied VFX dictionary with all of the trailer
 /// elements that are found in the supplied XML dictionary.
 /// </summary>
 /// <param name="source">
 /// The source dictionary for the trailer elements.
 /// </param>
 /// <param name="target">
 /// The target dictionary for the converted elements.
 /// </param>
 private static void PopulateTrailer(XmlDictionary source, FixDictionary target)
 {
     foreach (IFixDxElement dxElement in TranslateElements(source.Trailer.Elements))
     {
         target.Trailer.Add(dxElement);
     }
 }
示例#7
0
        /// <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);
                }
            }
        }
示例#8
0
 /// <summary>
 /// The PopulateDataTypes method populates the data types
 /// section of the supplied VFX dictionary with all of the
 /// data types that are found in the XML dictionary.
 /// </summary>
 /// <param name="source">
 /// The XML dictionary to read the data types from.
 /// </param>
 /// <param name="target">
 /// The VFX dictionary to write the data types to.
 /// </param>
 private static void PopulateDataTypes(XmlDictionary source, FixDictionary target)
 {
     foreach (XmlFixDxDataType xmlDataType in source.DataTypes.Entries)
     {
         FixDxDataType fixDataType = new FixDxDataType(xmlDataType.TypeName, xmlDataType.TypeBase);
         target.DataTypes.Add(fixDataType);
     }
 }
示例#9
0
        public FixDictionary Create()
        {
            FixDictionary result = new FixDictionary();

            result.Properties.Add("Type", "Not Specified");
            result.Properties.Add("Fix.Major", "Not Specified");
            result.Properties.Add("Fix.Minor", "Not Specified");

            return(result);
        }
示例#10
0
        /// <summary>
        /// The Clone method is invoked to construct a completely
        /// new instance/copy of an instance of a dictionary.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            FixDictionary result = new FixDictionary();

            // REC: Copy all of the metadata properties into the
            // new instance of the dictionary:
            foreach (string key in _mapProperties.Keys)
            {
                result.Properties.Add(key, _mapProperties[key]);
            }

            // REC: Clone all of the header elements in this dictionary
            // and add them to the result dictionary:
            foreach (IFixDxElement hdrElement in _hdrCollection)
            {
                result.Header.Add(CloneElement(hdrElement));
            }

            // REC: Clone all of the field entries in this dictionary
            // and add them to the result dictionary:
            foreach (FixDxField dxField in _fldElements)
            {
                result.AddField(CloneField(dxField));
            }

            // REC: Clone all of the block entries in this dictionary
            // and add them to the result dictionary:
            foreach (FixDxBlock dxBlock in _blkElements)
            {
                result.AddBlock(CloneBlock(dxBlock));
            }

            // REC: Clone all of the message entries in this dictionary
            // and add them to the result dictionary:
            foreach (FixDxMessage dxMessage in _messages)
            {
                result.AddMessage(CloneMessage(dxMessage));
            }

            // REC: Clone all of the enum entries in this dictionary
            // and add them to the result dictionary:
            foreach (FixDxEnumeration dxEnumeration in _enmElements)
            {
                result.AddEnumeration(CloneEnumeration(dxEnumeration));
            }

            // REC: Clone all of the trailer entries in this dictionary
            // and add them to the result dictionary:
            foreach (IFixDxElement trlElement in _trlCollection)
            {
                result.Trailer.Add(CloneElement(trlElement));
            }

            return(result);
        }
示例#11
0
        /// <summary>
        /// The PopulateDataTypes method populates the data types
        /// section of the supplied XML dictionary with all of the
        /// data type definitions that are in the FIX dictionary.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XML dictionary to be populated.
        /// </param>
        /// <param name="fixDictionary">
        /// The FIX dictionary to retrieve the data from.
        /// </param>
        private static void PopulateDataTypes(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            foreach (FixDxDataType fixDataType in fixDictionary.DataTypes)
            {
                XmlFixDxDataType xmlDataType = new XmlFixDxDataType();
                xmlDataType.TypeName = fixDataType.Name;
                xmlDataType.TypeBase = fixDataType.BaseType;

                xmlDictionary.DataTypes.Entries.Add(xmlDataType);
            }
        }
示例#12
0
 /// <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);
         }
     }
 }
示例#13
0
 /// <summary>
 /// Creates a new entry in the registry for an instance
 /// of a FIX dictionary.
 /// </summary>
 /// <param name="name">
 /// The name that the dictionary is registered under.
 /// </param>
 /// <param name="dictionary">
 /// The reference to the dictionary being registered.
 /// </param>
 public void CreateEntry(string name, FixDictionary dictionary)
 {
     _rwLock.AcquireWriterLock(Timeout.Infinite);
     if (!_mapEntries.ContainsKey(name))
     {
         _mapEntries.Add(name, dictionary);
     }
     else
     {
         _mapEntries[name] = dictionary;
     }
     _rwLock.ReleaseWriterLock();
 }
示例#14
0
        /// <summary>
        /// The PopulateMetadata method populates the metadata properties
        /// in an XmlDictionary instance with the corresponding entries from
        /// an instance of a VersaFix dictionary.
        /// </summary>
        /// <param name="source">
        /// The source dictionary for the elements being copied.
        /// </param>
        /// <param name="target">
        /// The target dictionary for the elements to be copied into.
        /// </param>
        private static void PopulateMetadata(FixDictionary source, XmlDictionary target)
        {
            foreach (string key in source.Properties.Keys)
            {
                // REC: Construct an XML representation of the property
                // and add it to the target dictionary:
                XmlFixDxProperty xmlProperty = new XmlFixDxProperty();
                xmlProperty.Name  = key;
                xmlProperty.Value = source.Properties[key];

                target.Properties.Elements.Add(xmlProperty);
            }
        }
示例#15
0
        /// <summary>
        /// The PopulateMessages method populates the message section
        /// of the supplied VFX dictionary with all message definitions
        /// that are found in the supplied XML dictionary.
        /// </summary>
        /// <param name="source">
        /// The source dictionary for the message elements.
        /// </param>
        /// <param name="target">
        /// The target dictionary for the converted elements.
        /// </param>
        private static void PopulateMessages(XmlDictionary source, FixDictionary target)
        {
            foreach (XmlFixDxMessage src in source.Messages.Entries)
            {
                FixDxMessage dst = new FixDxMessage(src.MsgType, src.Name, src.MsgCategory);
                foreach (IFixDxElement dxElement in TranslateElements(src.Elements))
                {
                    dst.Elements.Add(dxElement);
                }

                target.AddMessage(dst);
            }
        }
示例#16
0
        /// <summary>
        /// The PopulateBlocks method populates the blocks section
        /// of the supplied XML dictionary with the corresponding
        /// elements from the supplied FixDictionary instance.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictionary instance that is to be populated.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateBlocks(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            foreach (FixDxBlock dxBlock in fixDictionary.Blocks)
            {
                XmlFixDxBlock xmlBlock = new XmlFixDxBlock();
                xmlBlock.Name  = dxBlock.Name;
                xmlBlock.Type  = dxBlock.Type.ToString();
                xmlBlock.Field = dxBlock.Field;

                xmlBlock.Elements = TranslateElements(dxBlock.Elements).Elements;
                xmlDictionary.Blocks.Entries.Add(xmlBlock);
            }
        }
示例#17
0
 /// <summary>
 /// The Import method is invoked to import a dictionary
 /// from a representation that is contained in a file.
 /// </summary>
 /// <param name="path">
 /// The complete path to the file that contains the
 /// contents of the dictionary.
 /// </param>
 /// <returns>
 /// The FIX dictionary that is read from the stream or
 /// null if the import operation could not complete.
 /// </returns>
 public FixDictionary Import(string path)
 {
     try
     {
         FileStream    fs     = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
         FixDictionary result = Import(fs);
         fs.Close();
         return(result);
     }
     catch (System.Exception)
     {
         return(null);
     }
 }
示例#18
0
        /// <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));
                                }
                            }
                        }
                    }
                }
            }
        }
示例#19
0
        /// <summary>
        /// The PopulateEnums method populates the enumerations
        /// section of the supplied XmlDictionary with all the
        /// enumerations from the supplied FixDictionary.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictionary instance being populated.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateEnums(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            foreach (FixDxEnumeration dxEnumeration in fixDictionary.Enums)
            {
                XmlFixDxEnumeration xmlEnumeration = new XmlFixDxEnumeration();
                xmlEnumeration.Name = dxEnumeration.Name;
                foreach (FixDxEnumerator dxEnumerator in dxEnumeration.Enumerators)
                {
                    XmlFixDxEnumerator xmlEnumerator = new XmlFixDxEnumerator();
                    xmlEnumerator.value       = dxEnumerator.Value;
                    xmlEnumerator.Description = dxEnumerator.Description;
                    xmlEnumeration.Enumerators.Add(xmlEnumerator);
                }

                xmlDictionary.Enums.Entries.Add(xmlEnumeration);
            }
        }
示例#20
0
        /// <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);
                }
            }
        }
示例#21
0
        /// <summary>
        /// The PopulateBlocks method populates the blocks section
        /// of the supplied VFX dictionary with all of the blocks
        /// that are defined in the supplied XML dictionary.
        /// </summary>
        /// <param name="source">
        /// The source dictionary for the block elements.
        /// </param>
        /// <param name="target">
        /// The target dictionary for the converted elements.
        /// </param>
        private static void PopulateBlocks(XmlDictionary source, FixDictionary target)
        {
            foreach (XmlFixDxBlock src in source.Blocks.Entries)
            {
                FixDxBlock dst = new FixDxBlock(src.Name);
                dst.Type     = (FixDxBlockTypes)Enum.Parse(typeof(FixDxBlockTypes), src.Type);
                dst.Field    = src.Field;
                dst.Category = src.Category;

                foreach (IFixDxElement element in TranslateElements(src.Elements))
                {
                    dst.Elements.Add(element);
                }

                target.AddBlock(dst);
            }
        }
示例#22
0
 /// <summary>
 /// The PopulateEnums method populates the enumerations section
 /// of the supplied VFX dictionary with all of the enumerations
 /// that are defined in the supplied XML dictionary.
 /// </summary>
 /// <param name="source">
 /// The source dictionary for the enumeration elements.
 /// </param>
 /// <param name="target">
 /// The target dictionary for the converted elements.
 /// </param>
 private static void PopulateEnums(XmlDictionary source, FixDictionary target)
 {
     foreach (XmlFixDxEnumeration src in source.Enums.Entries)
     {
         FixDxEnumeration dst = new FixDxEnumeration(src.Name);
         foreach (object element in src.Enumerators)
         {
             if (element is XmlFixDxEnumerator)
             {
                 XmlFixDxEnumerator srcEnum = element as XmlFixDxEnumerator;
                 FixDxEnumerator    dstEnum = new FixDxEnumerator(srcEnum.value, srcEnum.Description);
                 dst.Enumerators.Add(dstEnum);
             }
         }
         target.AddEnumeration(dst);
     }
 }
示例#23
0
 /// <summary>
 /// The PopulateFields method populates the fields section
 /// of the supplied VFX dictionary with all of the fields
 /// that are found in the supplied XML dictionary.
 /// </summary>
 /// <param name="source">
 /// The source dictionary for the field elements.
 /// </param>
 /// <param name="target">
 /// The target dictionary for the converted elements.
 /// </param>
 private static void PopulateFields(XmlDictionary source, FixDictionary target)
 {
     foreach (XmlFixDxField src in source.Fields.Entries)
     {
         if (src.LengthField == null)
         {
             FixDxField dst = new FixDxField(src.Tag, src.Name, src.Type);
             dst.Enumeration = src.Enumeration;
             target.AddField(dst);
         }
         else
         {
             FixDxField dst = new FixDxField(src.Tag, src.Name, src.Type, src.LengthField);
             dst.Enumeration = src.Enumeration;
             target.AddField(dst);
         }
     }
 }
示例#24
0
        /// <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);
                }
            }
        }
示例#25
0
        /// <summary>
        /// The Import method deserializes an XML representation of
        /// a VersaFix dictionary from a file and converts it into a
        /// corresponding instance of FixDictionary.
        /// </summary>
        /// <param name="path">
        /// The path to the XML file that contains the dictionary.
        /// </param>
        /// <returns>
        /// The resulting VersaFix dictionary instance.
        /// </returns>
        public static FixDictionary Import(string path)
        {
            FixDictionary result = null;
            FileStream    stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);

            try
            {
                result = Import(stream);
                stream.Close();
            }
            catch (System.Exception)
            {
                stream.Close();
                throw;
            }

            return(result);
        }
示例#26
0
        /// <summary>
        /// The PopulateTrailer method populates the trailer elements
        /// in an XmlDictionary instance with the elements from the
        /// source dictionary.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictionary instance that is being populated.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateTrailer(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            // REC: Iterate over all of the trailer elements in the
            // source dictionary and convert them into instances of
            // their corresponding XML serializable types:
            foreach (IFixDxElement dxElement in fixDictionary.Trailer)
            {
                if (dxElement is FixDxFieldReference)
                {
                    FixDxFieldReference    fieldReference = dxElement as FixDxFieldReference;
                    XmlFixDxFieldReference xmlReference   = new XmlFixDxFieldReference();
                    xmlReference.Name     = fieldReference.Name;
                    xmlReference.Required = fieldReference.Required;

                    xmlDictionary.Trailer.Elements.Add(xmlReference);
                }
                else if (dxElement is FixDxBlockReference)
                {
                    FixDxBlockReference    blockReference = dxElement as FixDxBlockReference;
                    XmlFixDxBlockReference xmlReference   = new XmlFixDxBlockReference();
                    xmlReference.Name     = blockReference.Name;
                    xmlReference.Required = blockReference.Required;

                    xmlDictionary.Trailer.Elements.Add(xmlReference);
                }
                else if (dxElement is FixDxGroupReference)
                {
                    FixDxGroupReference    groupReference = dxElement as FixDxGroupReference;
                    XmlFixDxGroupReference xmlReference   = new XmlFixDxGroupReference();
                    xmlReference.Name     = groupReference.Name;
                    xmlReference.Required = groupReference.Required;

                    XmlFixDxElements xmlElements = TranslateElements(groupReference.Elements);
                    foreach (object xmlElement in xmlElements.Elements)
                    {
                        xmlReference.Elements.Add(xmlElement);
                    }

                    xmlDictionary.Trailer.Elements.Add(xmlReference);
                }
            }
        }
示例#27
0
        /// <summary>
        /// This implementation of the Export method serializes the 
        /// specified dictionary out to the specified file.
        /// </summary>
        /// <param name="dx">
        /// The dictionary that is to be exported.
        /// </param>
        /// <param name="path">
        /// The fully qualified path to the XML file the dictionary
        /// is to be exported to.
        /// </param>
        public void Export(FixDictionary dx, string path)
        {
            FileStream stream = null;

            try
            {
                stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
                Export(dx, stream);
                stream.Close();
            }
            catch (System.Exception)
            {
                if (stream != null)
                {
                    stream.Close();
                }

                throw;
            }
        }
示例#28
0
        /// <summary>
        /// This implementation of the Export method serializes the
        /// specified dictionary out to the specified file.
        /// </summary>
        /// <param name="dx">
        /// The dictionary that is to be exported.
        /// </param>
        /// <param name="path">
        /// The fully qualified path to the XML file the dictionary
        /// is to be exported to.
        /// </param>
        public void Export(FixDictionary dx, string path)
        {
            FileStream stream = null;

            try
            {
                stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
                Export(dx, stream);
                stream.Close();
            }
            catch (System.Exception)
            {
                if (stream != null)
                {
                    stream.Close();
                }

                throw;
            }
        }
示例#29
0
        /// <summary>
        /// The PopulateMessages method populates the messages in
        /// an XmlDictionary instance with the message definitions
        /// from the source dictionary.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictionary instance that the message definitions
        /// are to be added to.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateMessages(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            // REC: Iterate over all of the message definitions in the
            // source dictionary and convert them to XML serializable
            // representations for the serializable dictionary:
            foreach (FixDxMessage dxMessage in fixDictionary.Messages)
            {
                XmlFixDxMessage xmlMessage = new XmlFixDxMessage();
                xmlMessage.Name        = dxMessage.Name;
                xmlMessage.MsgType     = dxMessage.MsgType;
                xmlMessage.MsgCategory = dxMessage.MsgCategory;

                XmlFixDxElements xmlElements = TranslateElements(dxMessage.Elements);
                foreach (object xmlElement in xmlElements.Elements)
                {
                    xmlMessage.Elements.Add(xmlElement);
                }

                xmlDictionary.Messages.Entries.Add(xmlMessage);
            }
        }
示例#30
0
        /// <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);
                }
            }
        }
示例#31
0
        /// <summary>
        /// The Import method deserializes an XML representation
        /// of a VersaFix dictionary from a stream and converts it
        /// into a corresponding instance of FixDictionary.
        /// </summary>
        /// <param name="stream">
        /// The stream that the XML data is to be read from.
        /// </param>
        /// <returns>
        /// The resulting instance of FixDictionary.
        /// </returns>
        public static FixDictionary Import(Stream stream)
        {
            XmlSerializer xs            = new XmlSerializer(typeof(XmlDictionary));
            XmlDictionary xmlDictionary = xs.Deserialize(stream) as XmlDictionary;

            // REC: Construct a new instance of a VersaFix dictionary
            // that the XML data will be converted into:
            FixDictionary result = new FixDictionary();

            // REC: Populate the VersaFix dictionary instance with all
            // of the elements that were read from the XML stream:
            PopulateMetadata(xmlDictionary, result);
            PopulateHeader(xmlDictionary, result);
            PopulateTrailer(xmlDictionary, result);
            PopulateMessages(xmlDictionary, result);
            PopulateFields(xmlDictionary, result);
            PopulateDataTypes(xmlDictionary, result);
            PopulateBlocks(xmlDictionary, result);
            PopulateEnums(xmlDictionary, result);

            return(result);
        }
示例#32
0
        /// <summary>
        /// The PopulateFields method populates the fields section
        /// of an XmlDictionary instance with the field definitions
        /// from the supplied FixDictionary instance.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictinary instance that the field definitions
        /// are to be added to.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateFields(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            foreach (FixDxField dxField in fixDictionary.Fields)
            {
                XmlFixDxField xmlField = new XmlFixDxField();
                xmlField.Tag         = dxField.Tag;
                xmlField.Name        = dxField.Name;
                xmlField.Type        = dxField.Type;
                xmlField.Enumeration = dxField.Enumeration;

                if (dxField.LengthCoded == true)
                {
                    xmlField.LengthField = dxField.LengthField.ToString();
                }
                else
                {
                    xmlField.LengthField = null;
                }


                xmlDictionary.Fields.Entries.Add(xmlField);
            }
        }
示例#33
0
        /// <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;
        }
示例#34
0
 /// <summary>
 /// The Export method is invoked to export the contents
 /// of a VersaFix data dictionary out to a file 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="path">
 /// The file the dictionary's data is to be saved to.
 /// </param>
 public void Export(FixDictionary dictionary, string path)
 {
     FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
     Export(dictionary, fs);
     fs.Close();
 }
示例#35
0
 /// <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);
     }
 }
示例#36
0
        /// <summary>
        /// The PopulateBlocks method populates the blocks section
        /// of the supplied VFX dictionary with all of the blocks
        /// that are defined in the supplied XML dictionary.
        /// </summary>
        /// <param name="source">
        /// The source dictionary for the block elements.
        /// </param>
        /// <param name="target">
        /// The target dictionary for the converted elements.
        /// </param>
        private static void PopulateBlocks(XmlDictionary source, FixDictionary target)
        {
            foreach (XmlFixDxBlock src in source.Blocks.Entries)
            {
                FixDxBlock dst = new FixDxBlock(src.Name);
                dst.Type = (FixDxBlockTypes)Enum.Parse(typeof(FixDxBlockTypes), src.Type);
                dst.Field = src.Field;
                dst.Category = src.Category;

                foreach (IFixDxElement element in TranslateElements(src.Elements))
                {
                    dst.Elements.Add(element);
                }

                target.AddBlock(dst);
            }
        }
示例#37
0
        /// <summary>
        /// The PopulateMetadata method populates the metadata properties
        /// in an XmlDictionary instance with the corresponding entries from
        /// an instance of a VersaFix dictionary.
        /// </summary>
        /// <param name="source">
        /// The source dictionary for the elements being copied.
        /// </param>
        /// <param name="target">
        /// The target dictionary for the elements to be copied into.
        /// </param>
        private static void PopulateMetadata(FixDictionary source, XmlDictionary target)
        {
            foreach (string key in source.Properties.Keys)
            {
                // REC: Construct an XML representation of the property
                // and add it to the target dictionary:
                XmlFixDxProperty xmlProperty = new XmlFixDxProperty();
                xmlProperty.Name = key;
                xmlProperty.Value = source.Properties[key];

                target.Properties.Elements.Add(xmlProperty);
            }
        }
示例#38
0
        /// <summary>
        /// The Clone method is invoked to construct a completely
        /// new instance/copy of an instance of a dictionary.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            FixDictionary result = new FixDictionary();

            // REC: Copy all of the metadata properties into the
            // new instance of the dictionary:
            foreach (string key in _mapProperties.Keys)
            {
                result.Properties.Add(key, _mapProperties[key]);
            }

            // REC: Clone all of the header elements in this dictionary
            // and add them to the result dictionary:
            foreach (IFixDxElement hdrElement in _hdrCollection)
            {
                result.Header.Add(CloneElement(hdrElement));
            }

            // REC: Clone all of the field entries in this dictionary
            // and add them to the result dictionary:
            foreach (FixDxField dxField in _fldElements)
            {
                result.AddField(CloneField(dxField));
            }

            // REC: Clone all of the block entries in this dictionary
            // and add them to the result dictionary:
            foreach (FixDxBlock dxBlock in _blkElements)
            {
                result.AddBlock(CloneBlock(dxBlock));
            }

            // REC: Clone all of the message entries in this dictionary
            // and add them to the result dictionary:
            foreach (FixDxMessage dxMessage in _messages)
            {
                result.AddMessage(CloneMessage(dxMessage));
            }

            // REC: Clone all of the enum entries in this dictionary
            // and add them to the result dictionary:
            foreach (FixDxEnumeration dxEnumeration in _enmElements)
            {
                result.AddEnumeration(CloneEnumeration(dxEnumeration));
            }

            // REC: Clone all of the trailer entries in this dictionary
            // and add them to the result dictionary:
            foreach (IFixDxElement trlElement in _trlCollection)
            {
                result.Trailer.Add(CloneElement(trlElement));
            }

            return result;
        }
示例#39
0
 /// <summary>
 /// The PopulateEnums method populates the enumerations section
 /// of the supplied VFX dictionary with all of the enumerations
 /// that are defined in the supplied XML dictionary.
 /// </summary>
 /// <param name="source">
 /// The source dictionary for the enumeration elements.
 /// </param>
 /// <param name="target">
 /// The target dictionary for the converted elements.
 /// </param>
 private static void PopulateEnums(XmlDictionary source, FixDictionary target)
 {
     foreach (XmlFixDxEnumeration src in source.Enums.Entries)
     {
         FixDxEnumeration dst = new FixDxEnumeration(src.Name);
         foreach (object element in src.Enumerators)
         {
             if (element is XmlFixDxEnumerator)
             {
                 XmlFixDxEnumerator srcEnum = element as XmlFixDxEnumerator;
                 FixDxEnumerator dstEnum = new FixDxEnumerator(srcEnum.value, srcEnum.Description);
                 dst.Enumerators.Add(dstEnum);
             }
         }
         target.AddEnumeration(dst);
     }
 }
示例#40
0
 /// <summary>
 /// The PopulateTrailer method populates the trailer section
 /// of the supplied VFX dictionary with all of the trailer 
 /// elements that are found in the supplied XML dictionary.
 /// </summary>
 /// <param name="source">
 /// The source dictionary for the trailer elements.
 /// </param>
 /// <param name="target">
 /// The target dictionary for the converted elements.
 /// </param>
 private static void PopulateTrailer(XmlDictionary source, FixDictionary target)
 {
     foreach (IFixDxElement dxElement in TranslateElements(source.Trailer.Elements))
     {
         target.Trailer.Add(dxElement);
     }
 }
示例#41
0
        /// <summary>
        /// The PopulateDataTypes method populates the data types 
        /// section of the supplied XML dictionary with all of the
        /// data type definitions that are in the FIX dictionary.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XML dictionary to be populated.
        /// </param>
        /// <param name="fixDictionary">
        /// The FIX dictionary to retrieve the data from.
        /// </param>
        private static void PopulateDataTypes(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            foreach (FixDxDataType fixDataType in fixDictionary.DataTypes)
            {
                XmlFixDxDataType xmlDataType = new XmlFixDxDataType();
                xmlDataType.TypeName = fixDataType.Name;
                xmlDataType.TypeBase = fixDataType.BaseType;

                xmlDictionary.DataTypes.Entries.Add(xmlDataType);
            }
        }
示例#42
0
        /// <summary>
        /// The PopulateMessages method populates the message section
        /// of the supplied VFX dictionary with all message definitions
        /// that are found in the supplied XML dictionary.
        /// </summary>
        /// <param name="source">
        /// The source dictionary for the message elements.
        /// </param>
        /// <param name="target">
        /// The target dictionary for the converted elements.
        /// </param>
        private static void PopulateMessages(XmlDictionary source, FixDictionary target)
        {
            foreach (XmlFixDxMessage src in source.Messages.Entries)
            {
                FixDxMessage dst = new FixDxMessage(src.MsgType, src.Name, src.MsgCategory);
                foreach (IFixDxElement dxElement in TranslateElements(src.Elements))
                {
                    dst.Elements.Add(dxElement);
                }

                target.AddMessage(dst);
            }
        }
示例#43
0
        /// <summary>
        /// This implementation of the Export method serializes the
        /// specified dictionary out to a stream that has already been
        /// opened by the caller.
        /// </summary>
        /// <param name="dictionary">
        /// The dictionary that is to be exported.
        /// </param>
        /// <param name="stream">
        /// The stream that the XML data is to be written to.
        /// </param>
        public void Export(FixDictionary dictionary, Stream stream)
        {
            XmlDictionary xmlDictionary = new XmlDictionary();

            // REC: Populate the XML dictionary with all of the
            // elements from the supplied FixDictionary instance:
            PopulateMetadata(dictionary, xmlDictionary);
            PopulateHeader(xmlDictionary, dictionary);
            PopulateTrailer(xmlDictionary, dictionary);
            PopulateMessages(xmlDictionary, dictionary);
            PopulateFields(xmlDictionary, dictionary);
            PopulateDataTypes(xmlDictionary, dictionary);
            PopulateBlocks(xmlDictionary, dictionary);
            PopulateEnums(xmlDictionary, dictionary);

            // REC: After the XML serializable representation of
            // the dictionary has been populated, use the serializer
            // to export its contents out to the specified stream:
            XmlSerializer xs = new XmlSerializer(typeof(XmlDictionary));
            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);
        }
示例#44
0
        /// <summary>
        /// The PopulateEnums method populates the enumerations
        /// section of the supplied XmlDictionary with all the
        /// enumerations from the supplied FixDictionary.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictionary instance being populated.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateEnums(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            foreach (FixDxEnumeration dxEnumeration in fixDictionary.Enums)
            {
                XmlFixDxEnumeration xmlEnumeration = new XmlFixDxEnumeration();
                xmlEnumeration.Name = dxEnumeration.Name;
                foreach (FixDxEnumerator dxEnumerator in dxEnumeration.Enumerators)
                {
                    XmlFixDxEnumerator xmlEnumerator = new XmlFixDxEnumerator();
                    xmlEnumerator.value = dxEnumerator.Value;
                    xmlEnumerator.Description = dxEnumerator.Description;
                    xmlEnumeration.Enumerators.Add(xmlEnumerator);
                }

                xmlDictionary.Enums.Entries.Add(xmlEnumeration);
            }
        }
示例#45
0
        /// <summary>
        /// The GenerateTags method is invoked to request that the
        /// system generate a tag definition file, based on the tags
        /// that are discovered in the supplied FIX dictionary.
        /// </summary>
        /// <param name="dxInstance"></param>
        /// <param name="dstPath"></param>
        private void GenerateTags(FixDictionary dxInstance, string dstPath, string dstNamespace)
        {
            StreamWriter mxWriter = new StreamWriter(new FileStream(dstPath, FileMode.Create, FileAccess.Write, FileShare.None));

            mxWriter.WriteLine("//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
            mxWriter.WriteLine("// VERSAFIX FIX ENGINE - FIX TAG DEFINITIONS FILE");
            mxWriter.WriteLine("//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
            mxWriter.WriteLine("using System;");

            mxWriter.WriteLine(string.Format("namespace {0} {{\r\n\r\n", dstNamespace));

            mxWriter.WriteLine(string.Format("\tpublic class Tags {{"));

            foreach (FixDxField dxField in dxInstance.Fields)
            {
                // REC: Ensure that each field name is valid, in terms of being
                // able to represent it as a .NET variable:
                bool isAcceptable = true;
                foreach (char ch in dxField.Name)
                {
                    if (!char.IsLetterOrDigit(ch) && (ch != '_'))
                    {
                        isAcceptable = false;
                        break;
                    }
                }

                if (isAcceptable)
                {
                    mxWriter.WriteLine(string.Format("\t\tpublic static readonly int {0} = {1};\r\n", dxField.Name, dxField.Tag));
                }
                else
                {
                    mxWriter.WriteLine(string.Format("\t\t// PARSER ERROR: Field name does not look acceptable"));
                    mxWriter.WriteLine(string.Format("\t\t// {0} = {1}\r\n", dxField.Name, dxField.Tag));
                }
            }

            mxWriter.WriteLine(string.Format("\t}}"));

            mxWriter.WriteLine(string.Format("}}"));
            mxWriter.Close();
        }
示例#46
0
        /// <summary>
        /// The PopulateBlocks method populates the blocks section
        /// of the supplied XML dictionary with the corresponding
        /// elements from the supplied FixDictionary instance.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictionary instance that is to be populated.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateBlocks(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            foreach (FixDxBlock dxBlock in fixDictionary.Blocks)
            {
                XmlFixDxBlock xmlBlock = new XmlFixDxBlock();
                xmlBlock.Name = dxBlock.Name;
                xmlBlock.Type = dxBlock.Type.ToString();
                xmlBlock.Field = dxBlock.Field;

                xmlBlock.Elements = TranslateElements(dxBlock.Elements).Elements;
                xmlDictionary.Blocks.Entries.Add(xmlBlock);
            }
        }
示例#47
0
 /// <summary>
 /// The PopulateFields method populates the fields section
 /// of the supplied VFX dictionary with all of the fields
 /// that are found in the supplied XML dictionary.
 /// </summary>
 /// <param name="source">
 /// The source dictionary for the field elements.
 /// </param>
 /// <param name="target">
 /// The target dictionary for the converted elements.
 /// </param>
 private static void PopulateFields(XmlDictionary source, FixDictionary target)
 {
     foreach (XmlFixDxField src in source.Fields.Entries)
     {
         if (src.LengthField == null)
         {
             FixDxField dst = new FixDxField(src.Tag, src.Name, src.Type);
             dst.Enumeration = src.Enumeration;
             target.AddField(dst);
         }
         else
         {
             FixDxField dst = new FixDxField(src.Tag, src.Name, src.Type, src.LengthField);
             dst.Enumeration = src.Enumeration;
             target.AddField(dst);
         }
     }
 }
示例#48
0
        /// <summary>
        /// The PopulateTrailer method populates the trailer elements
        /// in an XmlDictionary instance with the elements from the
        /// source dictionary.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictionary instance that is being populated.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateTrailer(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            // REC: Iterate over all of the trailer elements in the
            // source dictionary and convert them into instances of
            // their corresponding XML serializable types:
            foreach (IFixDxElement dxElement in fixDictionary.Trailer)
            {
                if (dxElement is FixDxFieldReference)
                {
                    FixDxFieldReference fieldReference = dxElement as FixDxFieldReference;
                    XmlFixDxFieldReference xmlReference = new XmlFixDxFieldReference();
                    xmlReference.Name = fieldReference.Name;
                    xmlReference.Required = fieldReference.Required;

                    xmlDictionary.Trailer.Elements.Add(xmlReference);
                }
                else if (dxElement is FixDxBlockReference)
                {
                    FixDxBlockReference blockReference = dxElement as FixDxBlockReference;
                    XmlFixDxBlockReference xmlReference = new XmlFixDxBlockReference();
                    xmlReference.Name = blockReference.Name;
                    xmlReference.Required = blockReference.Required;

                    xmlDictionary.Trailer.Elements.Add(xmlReference);
                }
                else if (dxElement is FixDxGroupReference)
                {
                    FixDxGroupReference groupReference = dxElement as FixDxGroupReference;
                    XmlFixDxGroupReference xmlReference = new XmlFixDxGroupReference();
                    xmlReference.Name = groupReference.Name;
                    xmlReference.Required = groupReference.Required;

                    XmlFixDxElements xmlElements = TranslateElements(groupReference.Elements);
                    foreach (object xmlElement in xmlElements.Elements)
                    {
                        xmlReference.Elements.Add(xmlElement);
                    }

                    xmlDictionary.Trailer.Elements.Add(xmlReference);
                }
            }
        }
示例#49
0
 /// <summary>
 /// The PopulateDataTypes method populates the data types
 /// section of the supplied VFX dictionary with all of the
 /// data types that are found in the XML dictionary.
 /// </summary>
 /// <param name="source">
 /// The XML dictionary to read the data types from.
 /// </param>
 /// <param name="target">
 /// The VFX dictionary to write the data types to.
 /// </param>
 private static void PopulateDataTypes(XmlDictionary source, FixDictionary target)
 {
     foreach (XmlFixDxDataType xmlDataType in source.DataTypes.Entries)
     {
         FixDxDataType fixDataType = new FixDxDataType(xmlDataType.TypeName, xmlDataType.TypeBase);
         target.DataTypes.Add(fixDataType);
     }
 }
示例#50
0
        /// <summary>
        /// The PopulateFields method populates the fields section
        /// of an XmlDictionary instance with the field definitions
        /// from the supplied FixDictionary instance.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictinary instance that the field definitions
        /// are to be added to.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateFields(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            foreach (FixDxField dxField in fixDictionary.Fields)
            {
                XmlFixDxField xmlField = new XmlFixDxField();
                xmlField.Tag = dxField.Tag;
                xmlField.Name = dxField.Name;
                xmlField.Type = dxField.Type;
                xmlField.Enumeration = dxField.Enumeration;

                if (dxField.LengthCoded == true)
                {
                    xmlField.LengthField = dxField.LengthField.ToString();
                }
                else
                {
                    xmlField.LengthField = null;
                }

                xmlDictionary.Fields.Entries.Add(xmlField);

            }
        }
示例#51
0
        /// <summary>
        /// The PopulateMessages method populates the messages in
        /// an XmlDictionary instance with the message definitions
        /// from the source dictionary.
        /// </summary>
        /// <param name="xmlDictionary">
        /// The XmlDictionary instance that the message definitions
        /// are to be added to.
        /// </param>
        /// <param name="fixDictionary">
        /// The FixDictionary instance that is the source of the
        /// elements the XmlDictionary is to be populated with.
        /// </param>
        private static void PopulateMessages(XmlDictionary xmlDictionary, FixDictionary fixDictionary)
        {
            // REC: Iterate over all of the message definitions in the
            // source dictionary and convert them to XML serializable
            // representations for the serializable dictionary:
            foreach (FixDxMessage dxMessage in fixDictionary.Messages)
            {
                XmlFixDxMessage xmlMessage = new XmlFixDxMessage();
                xmlMessage.Name = dxMessage.Name;
                xmlMessage.MsgType = dxMessage.MsgType;
                xmlMessage.MsgCategory = dxMessage.MsgCategory;

                XmlFixDxElements xmlElements = TranslateElements(dxMessage.Elements);
                foreach (object xmlElement in xmlElements.Elements)
                {
                    xmlMessage.Elements.Add(xmlElement);
                }

                xmlDictionary.Messages.Entries.Add(xmlMessage);
            }
        }
示例#52
0
        /// <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);
                }
            }
        }
示例#53
0
        /// <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);
                }
            }
        }
示例#54
0
 /// <summary>
 /// The PopulateMetadata method populates the metadata properties
 /// of a VersaFix FIX data dictionary with the properties that are
 /// found in an instance of an XML representation of a dictionary.
 /// </summary>
 /// <param name="source">
 /// The source dictionary to read the properties from.
 /// </param>
 /// <param name="target">
 /// The target dictionary to add the properties to. 
 /// </param>
 private static void PopulateMetadata(XmlDictionary source, FixDictionary target)
 {
     foreach (XmlFixDxProperty xmlProperty in source.Properties.Elements)
     {
         target.Properties.Add(xmlProperty.Name, xmlProperty.Value);
     }
 }
示例#55
0
        /// <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);
                }
            }
        }
示例#56
0
        /// <summary>
        /// The Import method deserializes an XML representation
        /// of a VersaFix dictionary from a stream and converts it
        /// into a corresponding instance of FixDictionary.
        /// </summary>
        /// <param name="stream">
        /// The stream that the XML data is to be read from.
        /// </param>
        /// <returns>
        /// The resulting instance of FixDictionary.
        /// </returns>
        public static FixDictionary Import(Stream stream)
        {
            XmlSerializer xs = new XmlSerializer(typeof(XmlDictionary));
            XmlDictionary xmlDictionary = xs.Deserialize(stream) as XmlDictionary;

            // REC: Construct a new instance of a VersaFix dictionary
            // that the XML data will be converted into:
            FixDictionary result = new FixDictionary();

            // REC: Populate the VersaFix dictionary instance with all
            // of the elements that were read from the XML stream:
            PopulateMetadata(xmlDictionary, result);
            PopulateHeader(xmlDictionary, result);
            PopulateTrailer(xmlDictionary, result);
            PopulateMessages(xmlDictionary, result);
            PopulateFields(xmlDictionary, result);
            PopulateDataTypes(xmlDictionary, result);
            PopulateBlocks(xmlDictionary, result);
            PopulateEnums(xmlDictionary, result);

            return result;
        }