Esempio n. 1
0
        ///<summary>
        /// Registers a single node.
        /// When we resolve later, we'll be able to use this node as a source.
        ///</summary>
        public static void Register(TydCollection node)
        {
            if (!initialized)
            {
                throw new Exception("Used Tyd.Inheritance when it was not initialized.");
            }

            //If the node has no handle, and no source, we can ignore it since it's not connected to inheritance at all.
            var nodeHandle = node.AttributeHandle;
            var nodeSource = node.AttributeSource;

            if (nodeHandle == null && nodeSource == null)
            {
                return;
            }

            //Ensure we're don't have two nodes of the same handle
            if (nodeHandle != null && nodesByHandle.ContainsKey(nodeHandle))
            {
                throw new Exception("Tyd error: Multiple Tyd nodes with the same handle " + nodeHandle + ".");
            }

            //Make an inheritance node for the Tyd node
            var newNode = new InheritanceNode(node);

            nodesUnresolved.Add(newNode);
            if (nodeHandle != null)
            {
                nodesByHandle.Add(nodeHandle, newNode);
            }
        }
Esempio n. 2
0
        ///<summary>
        /// Registers a single node.
        /// When we resolve later, we'll be able to use this node as a source.
        ///</summary>
        public static void Register(TydCollection colNode)
        {
            //If the node has no handle, and no source, we can ignore it since it's not connected to inheritance at all.
            var nodeHandle = colNode.AttributeHandle;
            var nodeSource = colNode.AttributeSource;

            if (nodeHandle == null && nodeSource == null)
            {
                return;
            }

            //Ensure we're don't have two _nodes of the same handle
            if (nodeHandle != null && nodesByHandle.ContainsKey(nodeHandle))
            {
                throw new Exception(string.Format("Tyd error: Multiple Tyd _nodes with the same handle {0}.", nodeHandle));
            }

            //Make an inheritance node for the Tyd node
            var newNode = new InheritanceNode(colNode);

            nodesUnresolved.Add(newNode);
            if (nodeHandle != null)
            {
                nodesByHandle.Add(nodeHandle, newNode);
            }
        }
Esempio n. 3
0
        private static void CheckForDuplicateNodes(TydCollection originalNode)
        {
            //This is needed despite another check elsewhere
            //Because the source-data-combination process wipes out duplicate Tyd data

            tempUsedNodeNames.Clear();

            for (int i = 0; i < originalNode.Count; i++)
            {
                var node = originalNode[i];

                if (node.Name == null)
                {
                    continue;
                }

                if (tempUsedNodeNames.Contains(node.Name))
                {
                    throw new FormatException("Tyd error: Duplicate Tyd node name " + node.Name + " in this Tyd block: " + originalNode);
                }
                else
                {
                    tempUsedNodeNames.Add(node.Name);
                }
            }

            tempUsedNodeNames.Clear();
        }
Esempio n. 4
0
        private static bool IsSimpleCollection(TydCollection l)
        {
            var c  = 0;
            var c2 = 0;

            for (var i = 0; i < l.Nodes.Count; i++)
            {
                var node = l.Nodes[i] as TydString;
                if (node != null)
                {
                    if (node.Value != null)
                    {
                        if (node.Value.Contains("\n"))
                        {
                            return(false);
                        }
                        c += node.Value.Length;
                    }
                    if (node.Name != null)
                    {
                        c += node.Name.Length;
                    }
                    c2++;
                }
                else
                {
                    return(false);
                }
            }
            return(c2 < 2 || c < 64);
        }
Esempio n. 5
0
 protected void CopyDataFrom(TydCollection other)
 {
     other.DocIndexEnd = DocIndexEnd;
     other._attributes = other._attributes == null ? null : other._attributes.ToDictionary(x => x.Key, x => x.Value);
     for (var i = 0; i < _nodes.Count; i++)
     {
         other.AddChild(_nodes[i].DeepClone());
     }
 }
Esempio n. 6
0
 protected void CopyDataFrom(TydCollection other)
 {
     other.docIndexEnd = docIndexEnd;
     other.attClass    = attClass;
     other.attHandle   = attHandle;
     other.attSource   = attSource;
     other.attAbstract = attAbstract;
     for (int i = 0; i < nodes.Count; i++)
     {
         other.AddChild(nodes[i].DeepClone());
     }
 }
Esempio n. 7
0
        private static bool AppendNodeIntro(TydCollection node, StringBuilder sb, int indent)
        {
            bool appendedSomething = false;

            if (node.Name != null)
            {
                AppendWithWhitespace(node.Name, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AttributeAbstract)
            {
                AppendWithWhitespace(Constants.AttributeStartChar + Constants.AbstractAttributeName, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AttributeNoInherit)
            {
                AppendWithWhitespace(Constants.AttributeStartChar + Constants.NoInheritAttributeName, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AttributeHandle != null)
            {
                AppendWithWhitespace(Constants.AttributeStartChar + Constants.HandleAttributeName + " " + node.AttributeHandle, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AttributeSource != null)
            {
                AppendWithWhitespace(Constants.AttributeStartChar + Constants.SourceAttributeName + " " + node.AttributeSource, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AdditionalAttributes != null &&
                node.AdditionalAttributes.Count > 0)
            {
                foreach (KeyValuePair <string, string> pair in node.AdditionalAttributes)
                {
                    AppendWithWhitespace(Constants.AttributeStartChar + pair.Key + " " + pair.Value, sb, indent, appendedSomething);
                }

                appendedSomething = true;
            }

            return(appendedSomething);
        }
        protected void CopyDataFrom(TydCollection other)
        {
            other.docIndexEnd  = docIndexEnd;
            other.attHandle    = attHandle;
            other.attSource    = attSource;
            other.attAbstract  = attAbstract;
            other.attNoInherit = attNoInherit;
            for (int i = 0; i < nodes.Count; i++)
            {
                other.AddChild(nodes[i].DeepClone());
            }

            // Copy additional attribute
            if (attAdditional != null)
            {
                other.attAdditional = new List <KeyValuePair <string, string> >(attAdditional);
            }
        }
Esempio n. 9
0
        private static bool AppendNodeIntro(TydCollection node, StringBuilder sb, int indent)
        {
            var appendedSomething = false;

            if (node.Name != null)
            {
                AppendWithWhitespace(node.Name, sb, ref appendedSomething, indent);
            }

            foreach (var attribute in node.GetAttributes())
            {
                if (attribute.Value != null)
                {
                    AppendWithWhitespace(Constants.AttributeStartChar + attribute.Key + " " + StringContentWriteable(attribute.Value, false), sb, ref appendedSomething, indent);
                }
                else
                {
                    AppendWithWhitespace(Constants.AttributeStartChar + attribute.Key, sb, ref appendedSomething, indent);
                }
            }

            return(appendedSomething);
        }
Esempio n. 10
0
        private static bool AppendNodeIntro(TydCollection node, StringBuilder sb, int indent)
        {
            bool appendedSomething = false;

            if (node.Name != null)
            {
                AppendWithWhitespace(node.Name, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AttributeAbstract)
            {
                AppendWithWhitespace(Constants.AttributeStartChar + Constants.AbstractAttributeName, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AttributeNoInherit)
            {
                AppendWithWhitespace(Constants.AttributeStartChar + Constants.NoInheritAttributeName, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AttributeHandle != null)
            {
                AppendWithWhitespace(Constants.AttributeStartChar + Constants.HandleAttributeName + " " + node.AttributeHandle, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            if (node.AttributeSource != null)
            {
                AppendWithWhitespace(Constants.AttributeStartChar + Constants.SourceAttributeName + " " + node.AttributeSource, sb, indent, appendedSomething);
                appendedSomething = true;
            }

            return(appendedSomething);
        }
Esempio n. 11
0
        ///<summary>
        /// Copies all child nodes from source into heir, recursively.
        /// -If a node appears only in source or only in heir, it is included.
        /// -If a list appears in both source and heir, source's entries are appended to heir's entries.
        /// -If a non-list node appears in both source and heir, heir's node is overwritten.
        ///</summary>
        private static void ApplyInheritance(TydNode source, TydNode heir)
        {
            try
            {
                //They're either strings or nulls: We just keep the existing heir's value
                if (source is TydString)
                {
                    return;
                }

                //Heir has noinherit attribute: Skip this inheritance
                {
                    TydCollection heirCol = heir as TydCollection;
                    if (heirCol != null && heirCol.AttributeNoInherit)
                    {
                        return;
                    }
                }

                //They're tables: Combine all children of source and heir. Unique-name source nodes are prepended
                {
                    TydTable sourceObj = source as TydTable;
                    if (sourceObj != null)
                    {
                        TydTable heirTable = (TydTable)heir;
                        for (int i = 0; i < sourceObj.Count; i++)
                        {
                            var sourceChild       = sourceObj[i];
                            var heirMatchingChild = heirTable[sourceChild.Name];

                            if (heirMatchingChild != null)
                            {
                                ApplyInheritance(sourceChild, heirMatchingChild);
                            }
                            else
                            {
                                heirTable.InsertChild(sourceChild, 0); //Does this need to be DeepClone?
                            }
                        }
                        return;
                    }
                }

                //They're lists: Prepend source's children before heir's children
                {
                    TydList sourceList = source as TydList;
                    if (sourceList != null)
                    {
                        TydList heirList = (TydList)heir;
                        for (int i = 0; i < sourceList.Count; i++)
                        {
                            //Insert at i so the nodes stay in the same order from source to heir
                            heirList.InsertChild(sourceList[i], i); //Does this need to be DeepClone?
                        }
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("ApplyInheritance exception: " + e + ".\nsource: (" + source + ")\n" + TydToText.Write(source) + "\ntarget: (" + heir + ")\n" + TydToText.Write(heir));
            }
        }
Esempio n. 12
0
            private List <InheritanceNode> heirs = null; // Nodes which inherit from me.

            public InheritanceNode(TydCollection tydNode)
            {
                this.tydNode = tydNode;
            }