Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
        private void ExportElement(IFixDxElement dxElement, List <object> dst)
        {
            if (dxElement is FixDxFieldReference)
            {
                FixDxFieldReference dxField = dxElement as FixDxFieldReference;
                if (dxField != null)
                {
                    XmlQfxFieldReference xmlField = new XmlQfxFieldReference();
                    xmlField.Name     = dxField.Name;
                    xmlField.Required = (dxField.Required == true) ? "Y" : "N";
                    dst.Add(xmlField);
                }
            }
            else if (dxElement is FixDxBlockReference)
            {
                FixDxBlockReference dxBlock = dxElement as FixDxBlockReference;
                if (dxBlock != null)
                {
                    XmlQfxBlockReference xmlBlock = new XmlQfxBlockReference();
                    xmlBlock.Name     = dxBlock.Name;
                    xmlBlock.Required = (dxBlock.Required == true) ? "Y" : "N";
                    dst.Add(xmlBlock);
                }
            }
            else if (dxElement is FixDxGroupReference)
            {
                FixDxGroupReference dxGroup = dxElement as FixDxGroupReference;
                if (dxGroup != null)
                {
                    XmlQfxGroupReference xmlGroup = new XmlQfxGroupReference();
                    xmlGroup.Name     = dxGroup.Name;
                    xmlGroup.Required = (dxGroup.Required == true) ? "Y" : "N";

                    foreach (IFixDxElement dxGroupElement in dxGroup.Elements)
                    {
                        ExportElement(dxGroupElement, xmlGroup.Elements);
                    }

                    dst.Add(xmlGroup);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The TranslateElements method converts a collection of
        /// dictionary elements into their corresponding representation
        /// as instances of XML serializable classes. The method only
        /// translates field, group, and block references, since those
        /// are the only elements that should be found in collections
        /// of dictionary elements under normal usage.
        /// </summary>
        /// <param name="dxElements">
        /// The collection of field, group, and block references that
        /// is to be converted to XML serializable classes.
        /// </param>
        /// <returns>
        /// The resulting collection of XML serializable classes.
        /// </returns>
        private static XmlFixDxElements TranslateElements(FixDxCollection dxElements)
        {
            XmlFixDxElements result = new XmlFixDxElements();

            foreach (IFixDxElement dxElement in dxElements)
            {
                if (dxElement is FixDxFieldReference)
                {
                    FixDxFieldReference    dxReference  = dxElement as FixDxFieldReference;
                    XmlFixDxFieldReference xmlReference = new XmlFixDxFieldReference();
                    xmlReference.Name     = dxReference.Name;
                    xmlReference.Required = dxReference.Required;
                    result.Elements.Add(xmlReference);
                }
                else if (dxElement is FixDxGroupReference)
                {
                    FixDxGroupReference    dxReference  = dxElement as FixDxGroupReference;
                    XmlFixDxGroupReference xmlReference = new XmlFixDxGroupReference();
                    xmlReference.Name     = dxReference.Name;
                    xmlReference.Required = dxReference.Required;
                    XmlFixDxElements xmlElements = TranslateElements(dxReference.Elements);
                    foreach (object xmlElement in xmlElements.Elements)
                    {
                        xmlReference.Elements.Add(xmlElement);
                    }
                    result.Elements.Add(xmlReference);
                }
                else if (dxElement is FixDxBlockReference)
                {
                    FixDxBlockReference    dxReference  = dxElement as FixDxBlockReference;
                    XmlFixDxBlockReference xmlReference = new XmlFixDxBlockReference();
                    xmlReference.Name     = dxReference.Name;
                    xmlReference.Required = dxReference.Required;
                    result.Elements.Add(xmlReference);
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// The CloneBlockReference method is invoked to create a copy
 /// of an instance of a component block reference.
 /// </summary>
 /// <param name="source">
 /// The block reference that is to be duplicated.
 /// </param>
 /// <returns>
 /// The resulting clone of the supplied block reference.
 /// </returns>
 private FixDxBlockReference CloneBlockReference(FixDxBlockReference source)
 {
     FixDxBlockReference result = new FixDxBlockReference(source.Name, source.Required);
     return result;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// The ConvertElement method converts an instance of an XML element
        /// from a QuickFix dictionary into its corresponding representation
        /// as an element in a VersaFix dictionary.
        /// </summary>
        /// <param name="xmlElement">
        /// The XML representation of a QuickFix dictionary element that is
        /// to be converted into an instance of a VersaFix element.
        /// </param>
        /// <returns>
        /// The VersaFix dictionary element that results from the conversion
        /// attempt, or null if the conversion could not be carried out.
        /// </returns>
        private IFixDxElement ConvertElement(object xmlElement)
        {
            IFixDxElement result = null;

            if (xmlElement is XmlQfxFieldReference)
            {
                XmlQfxFieldReference xmlField = xmlElement as XmlQfxFieldReference;
                if (xmlField != null)
                {
                    if (!string.IsNullOrEmpty(xmlField.Name))
                    {
                        bool required = false;
                        if (xmlField.Required.CompareTo("Y") == 0)
                        {
                            required = true;
                        }

                        FixDxFieldReference dxField = new FixDxFieldReference(xmlField.Name, required);
                        result = dxField;
                    }
                }
            }
            else if (xmlElement is XmlQfxBlockReference)
            {
                XmlQfxBlockReference xmlBlock = xmlElement as XmlQfxBlockReference;
                if (xmlBlock != null)
                {
                    if (!string.IsNullOrEmpty(xmlBlock.Name))
                    {
                        bool required = false;
                        if (xmlBlock.Required.CompareTo("Y") == 0)
                        {
                            required = true;
                        }

                        FixDxBlockReference dxBlock = new FixDxBlockReference(xmlBlock.Name, required);
                        result = dxBlock;
                    }
                }
            }
            else if (xmlElement is XmlQfxGroupReference)
            {
                XmlQfxGroupReference xmlGroup = xmlElement as XmlQfxGroupReference;
                if (xmlGroup != null)
                {
                    if (!string.IsNullOrEmpty(xmlGroup.Name))
                    {
                        bool required = false;
                        if (xmlGroup.Required.CompareTo("Y") == 0)
                        {
                            required = true;
                        }

                        FixDxGroupReference dxGroup = new FixDxGroupReference(xmlGroup.Name, required);
                        foreach (object element in xmlGroup.Elements)
                        {
                            IFixDxElement dxElement = ConvertElement(element);
                            if (dxElement != null)
                            {
                                dxGroup.Elements.Add(dxElement);
                            }
                        }

                        result = dxGroup;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// The CloneBlockReference method is invoked to create a copy
        /// of an instance of a component block reference.
        /// </summary>
        /// <param name="source">
        /// The block reference that is to be duplicated.
        /// </param>
        /// <returns>
        /// The resulting clone of the supplied block reference.
        /// </returns>
        private FixDxBlockReference CloneBlockReference(FixDxBlockReference source)
        {
            FixDxBlockReference result = new FixDxBlockReference(source.Name, source.Required);

            return(result);
        }
Ejemplo n.º 8
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);
        }