Exemple #1
0
        /// <summary>
        /// The TranslateElements method iterates over a list of objects
        /// from an entity in the XML representation of a dictionary and
        /// translates them into a collection of VFX dictionary types.
        /// </summary>
        /// <param name="elements">
        /// The list of objects from an entity in the XML representation
        /// of a VersaFix dictionary.
        /// </param>
        /// <returns>
        /// An instance of FixDxCollection that has been populated with
        /// the VersaFix dictionary types that correspond to the objects
        /// in the list of XML elements.
        /// </returns>
        private static FixDxCollection TranslateElements(List <object> elements)
        {
            FixDxCollection result = new FixDxCollection();

            foreach (object element in elements)
            {
                if (element is XmlFixDxFieldReference)
                {
                    XmlFixDxFieldReference src = element as XmlFixDxFieldReference;
                    result.Add(new FixDxFieldReference(src.Name, src.Required));
                }
                else if (element is XmlFixDxGroupReference)
                {
                    XmlFixDxGroupReference src = element as XmlFixDxGroupReference;
                    FixDxGroupReference    dst = new FixDxGroupReference(src.Name, src.Required);

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

                    result.Add(dst);
                }
                else if (element is XmlFixDxBlockReference)
                {
                    XmlFixDxBlockReference src = element as XmlFixDxBlockReference;
                    result.Add(new FixDxBlockReference(src.Name, src.Required));
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// The Expand method iterates over all of the elements in
        /// a collection of dictionary elements and expands any of
        /// them that reference collections of other elements.
        /// </summary>
        /// <param name="source">
        /// The collection of elements to expand.
        /// </param>
        /// <returns>
        /// A new instance of a collection of dictionary elements
        /// with all expandable references in the source collection
        /// having been recursively expanded.
        /// </returns>
        public FixDxCollection Expand(FixDxCollection source)
        {
            FixDxCollection result = new FixDxCollection();

            foreach (IFixDxElement dxEntry in source)
            {
                if (dxEntry is FixDxBlockReference)
                {
                    FixDxBlockReference blockReference = dxEntry as FixDxBlockReference;
                    if (blockReference != null)
                    {
                        if (_mapBlocksByName.ContainsKey(blockReference.Name))
                        {
                            FixDxBlock      blockEntry    = _mapBlocksByName[blockReference.Name];
                            FixDxCollection blockElements = Expand(blockEntry.Elements);
                            foreach (IFixDxElement blockElement in blockElements)
                            {
                                if (blockElement is FixDxFieldReference)
                                {
                                    FixDxFieldReference reference = blockElement as FixDxFieldReference;
                                    result.Add(reference);
                                }
                                else if (blockElement is FixDxBlockReference)
                                {
                                    FixDxBlockReference reference = blockElement as FixDxBlockReference;
                                    result.Add(reference);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (dxEntry is FixDxGroupReference)
                    {
                        FixDxGroupReference srcReference = dxEntry as FixDxGroupReference;
                        FixDxGroupReference dstReference = new FixDxGroupReference(srcReference.Name, srcReference.Required);
                        foreach (IFixDxElement srcElement in Expand(srcReference.Elements))
                        {
                            dstReference.Elements.Add(srcElement);
                        }

                        result.Add(dstReference);
                    }
                    else if (dxEntry is FixDxFieldReference)
                    {
                        FixDxFieldReference element = dxEntry as FixDxFieldReference;
                        result.Add(element);
                    }
                }
            }

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// The AddBlock method adds an instance of a FIX component
        /// block to the dictionary. If there is already an instance
        /// of a component block with the same name, an operation is
        /// not allowed and an ArgumentException is thrown.
        /// </summary>
        /// <param name="dxBlock">
        /// The FIX component block definition that is to be added.
        /// </param>
        public void AddBlock(FixDxBlock dxBlock)
        {
            if (_mapBlocksByName.ContainsKey(dxBlock.Name))
            {
                string error = string.Format("Dictionary already contains a block named {0}.", dxBlock.Name);
                throw new ArgumentException(error);
            }

            _mapBlocksByName.Add(dxBlock.Name, dxBlock);
            _blkElements.Add(dxBlock);
        }
Exemple #4
0
        /// <summary>
        /// The AddMessage method adds a new instance of a
        /// message definition to the dictionary.
        /// </summary>
        /// <param name="dxMessage">
        /// The FIX message definition that is to be added
        /// to the dictionary.
        /// </param>
        public void AddMessage(FixDxMessage dxMessage)
        {
            if (_mapMessagesByName.ContainsKey(dxMessage.Name))
            {
                string error = string.Format("Dictionary already contains a message named {0}.", dxMessage.Name);
                throw new ArgumentException(error);
            }

            if (_mapMessagesByType.ContainsKey(dxMessage.MsgType))
            {
                string error = string.Format("Dictionary already contains a message type {0}.", dxMessage.MsgType);
                throw new ArgumentException(error);
            }

            _messages.Add(dxMessage);
            _mapMessagesByType.Add(dxMessage.MsgType, dxMessage);
            _mapMessagesByName.Add(dxMessage.Name, dxMessage);
        }
Exemple #5
0
        /// <summary>
        /// The AddEnumeration method adds an instance of an
        /// enumeration to the dictionary. Enumerations are keyed
        /// by their unique identifier, so if the enumeration that
        /// is being added collides with one that is already in the
        /// dictionary, the operation will fail.
        /// </summary>
        /// <param name="enumeration">
        /// The enumeration to be added to the dictionary.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Thrown if the enumeration's name is null or blank or
        /// if there is already an enumeration with the specified
        /// name in the dictionary.
        /// </exception>
        public void AddEnumeration(FixDxEnumeration enumeration)
        {
            if (!string.IsNullOrEmpty(enumeration.Name))
            {
                if (!_mapEnumerations.ContainsKey(enumeration.Name))
                {
                    _mapEnumerations.Add(enumeration.Name, enumeration);
                }
                else
                {
                    string error = string.Format("Dictionary already contains an enumeration named {0}.", enumeration.Name);
                    throw new ArgumentException(error);
                }

                _enmElements.Add(enumeration);
            }
            else
            {
                throw new ArgumentException("The enumeration's name is not specified.");
            }
        }
Exemple #6
0
        /// <summary>
        /// The AddField method attempts to add an instance of
        /// a FIX field definition to the dictionary. If there
        /// is already an entry in the dictionary that has the
        /// same identifying criteria the ArgumentException is
        /// thrown and the method fails; It's not possible for
        /// the dictionary to replace a redundant field, since
        /// there may be an entry in the name-based index that
        /// corresponds to a field with a *different* tag.
        /// </summary>
        /// <param name="dxField">
        /// The FIX field definition that is to be added.
        /// </param>
        public void AddField(FixDxField dxField)
        {
            if (_mapFieldsByTag.ContainsKey(dxField.Tag))
            {
                string error = string.Format("Dictionary already contains a field with tag {0}.", dxField.Tag);
                throw new ArgumentException(error);
            }

            if (_mapFieldsByName.ContainsKey(dxField.Name))
            {
                string error = string.Format("Dictionary already contains a field named {0}.", dxField.Name);
                throw new ArgumentException(error);
            }

            _mapFieldsByTag.Add(dxField.Tag, dxField);
            _mapFieldsByName.Add(dxField.Name, dxField);

            _fields.Add(dxField);

            _fldElements.Add(dxField);
        }
Exemple #7
0
        /// <summary>
        /// The Resolve method attempts to resolve all of the
        /// element references in a collection to the entries
        /// that correspond to them.
        /// </summary>
        /// <param name="elements">
        /// The collection of dictionary elements to resolve.
        /// </param>
        /// <returns>
        /// The resulting collection of resolved elements.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// Thrown if any elements in the collection that is
        /// supplied to the method cannot be resolved.
        /// </exception>
        public FixDxCollection Resolve(FixDxCollection elements)
        {
            FixDxCollection result = new FixDxCollection();

            // REC: Iterate over all of the elements in the collection
            // and determine how to resolve each of them:
            foreach (IFixDxElement dxElement in elements)
            {
                if (dxElement is FixDxFieldReference)
                {
                    FixDxFieldReference fieldReference = dxElement as FixDxFieldReference;
                    result.Add(ResolveFieldReference(fieldReference));
                }
                else if (dxElement is FixDxGroupReference)
                {
                    FixDxGroupReference groupReference = dxElement as FixDxGroupReference;
                    result.Add(ResolveGroupReference(groupReference));
                }
                else if (dxElement is FixDxBlockReference)
                {
                    FixDxBlockReference blockReference = dxElement as FixDxBlockReference;
                    // REC: Determine what type of block the reference
                    // is referring to (component or repeating):
                    if (string.IsNullOrEmpty(blockReference.Name))
                    {
                        string error = "The supplied block reference's name is null or empty.";
                        throw new ArgumentException(error);
                    }
                    else if (!_mapBlocksByName.ContainsKey(blockReference.Name))
                    {
                        string error = string.Format("The block reference {0} couldn't be resolved.", blockReference.Name);
                        throw new ArgumentException(error);
                    }
                    else
                    {
                        FixDxBlock dxBlock = _mapBlocksByName[blockReference.Name];
                        if (dxBlock.Type == FixDxBlockTypes.Component)
                        {
                            foreach (IFixDxElement element in Resolve(Expand(dxBlock.Elements)))
                            {
                                result.Add(element);
                            }
                        }
                        else if (dxBlock.Type == FixDxBlockTypes.Repeating)
                        {
                            // REC: Attempt to resolve the field that the repeating
                            // block references as the start field for the group:
                            if (string.IsNullOrEmpty(dxBlock.Field))
                            {
                                string error = string.Format("Repeating Block {0}'s start field is null or empty.", dxBlock.Field);
                                throw new ArgumentException(error);
                            }
                            else if (!_mapFieldsByName.ContainsKey(dxBlock.Field))
                            {
                                string error = string.Format("Repeating block {0}'s start field can't be resolved.", dxBlock.Field);
                                throw new ArgumentException(error);
                            }
                            else
                            {
                                FixDxField         dxField = _mapFieldsByName[dxBlock.Field];
                                FixDxResolvedGroup dxGroup = new FixDxResolvedGroup(dxField.Tag, dxField.Name, false);
                                foreach (IFixDxElement element in Resolve(Expand(dxBlock.Elements)))
                                {
                                    dxGroup.Elements.Add(element);
                                }

                                result.Add(dxGroup);
                            }
                        }
                    }
                }
            }

            // REC: Patch from RC - sanity check all elements in the result
            // to ensure that there are no unresolved references.
            foreach (IFixDxElement e in result)
            {
                if (e is FixDxFieldReference || e is FixDxGroupReference || e is FixDxFieldReference)
                {
                    throw new Exception("unresolved references exist in the resolved collection");
                }
            }

            return(result);
        }