Beispiel #1
0
        void recursiveLinkDA(NodeBase source, NodeBase target, NodeFC fc)
        {
            NodeBase linkedDa = target.LinkChildNodeByName(source);

            // Set FC
            if (linkedDa is NodeData && !(linkedDa is NodeDO))
            {
                (linkedDa as NodeData).SCL_FCDesc = fc.Name;
            }
            // Check DO / DA types
            if (linkedDa != source)
            {
                // We are in a DA once again
                // That means this is a DO and not a DA
                // We have to create DO and add it to the iec model (target)
                // and replace linkedDa with this object
                NodeDO ido = new NodeDO(source.Name);
                ido.IsIecModel = true;
                target.RemoveChildNode(source);
                linkedDa = target.AddChildNode(ido);
            }
            foreach (NodeBase newSource in source.GetChildNodes())
            {
                recursiveLinkDA(newSource, linkedDa, fc);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a logical node (LN) and all of its children, including
        /// FCs, DO's, and DA's
        /// </summary>
        /// <param name="reader"></param>
        /// <returns> a LN node </returns>
        private NodeLN CreateLogicalNode2(XmlReader reader)
        {
            reader.Read();

            var prefix  = reader.GetAttribute("prefix");
            var lnClass = reader.GetAttribute("lnClass");
            var inst    = reader.GetAttribute("inst");
            var type    = reader.GetAttribute("lnType");

            // LN name is a combination of prefix, lnCLass, and inst
            var name = !String.IsNullOrWhiteSpace(prefix) ? String.Concat(prefix, lnClass, inst) : String.Concat(lnClass, inst);

            NodeLN logicalNode = new NodeLN(name);

            logicalNode.TypeId = type;

            Hashtable functionalConstraints = new Hashtable();
            NodeBase  nodeType;

            try
            {
                nodeType = _nodeTypes.Single(nt => nt.Name.Equals(type));
            }
            catch (Exception e)
            {
                logger.LogError("SCL Parser: LN type template not found: " + type.ToString() + ", for Node: " + name.ToString() + ", Exception: " + e.Message);
                return(null);
            }

            // for each DO in the LNodeType
            foreach (var dataObject in nodeType.GetChildNodes())
            {
                NodeBase doType = null;
                try
                {
                    doType = _dataObjectTypes.Single(dot => dot.Name.Equals((dataObject as NodeDO).SCL_Type));
                }
                catch (Exception e)
                {
                    logger.LogError("SCL Parser: DO type template not found: " + (dataObject as NodeDO).SCL_Type + ", for LN type: " + nodeType.Name + ", in node: " + name.ToString() + ", Exception: " + e.Message);
                    continue;
                }

                // for each DA in the DOType
                foreach (var dataAttribute in doType.GetChildNodes())
                {
                    var fc = (dataAttribute as NodeData).SCL_FCDesc;
                    (dataAttribute as NodeData).SCL_DOName = dataObject.Name;
                    NodeData newNode = new NodeData(dataAttribute.Name);
                    newNode.SCL_Type   = (dataAttribute as NodeData).SCL_Type;
                    newNode.SCL_BType  = (dataAttribute as NodeData).SCL_BType;
                    newNode.SCL_DOName = (dataAttribute as NodeData).SCL_DOName;
                    newNode.SCL_FCDesc = (dataAttribute as NodeData).SCL_FCDesc;

                    // when the type is specified (ie. when it's a struct), get the struct child nodes
                    if (!String.IsNullOrWhiteSpace(newNode.SCL_Type))
                    {
                        var dataType =
                            _dataAttributeTypes.Single(dat => dat.Name.Equals((newNode.SCL_Type)));
                        foreach (NodeBase child in dataType.GetChildNodes())
                        {
                            var tempChild = new NodeData(child.Name);
                            tempChild.SCL_BType = (child as NodeData).SCL_BType;
                            if (!String.IsNullOrWhiteSpace((child as NodeData).SCL_Type))
                            {
                                var subDataType = _dataAttributeTypes.Single(dat => dat.Name.Equals((child as NodeData).SCL_Type));
                                foreach (NodeBase subChild in subDataType.GetChildNodes())
                                {
                                    var tempSubChild = new NodeData(subChild.Name);
                                    tempSubChild.SCL_BType = (subChild as NodeData).SCL_BType;
                                    tempChild.AddChildNode(subChild);
                                }
                            }
                            newNode.AddChildNode(tempChild);
                        }
                    }
                    if (!functionalConstraints.ContainsKey(fc))
                    {
                        NodeFC nodeFC = new NodeFC(fc);
                        nodeFC.ForceAddChildNode(newNode);
                        functionalConstraints.Add(fc, nodeFC);
                    }
                    else
                    {
                        (functionalConstraints[fc] as NodeBase).ForceAddChildNode(newNode);
                    }
                }
            }

            // for each hashtable element
            foreach (var key in functionalConstraints.Keys)
            {
                var doList = new List <NodeDO>();

                // for each data attribute of the functional constraint
                foreach (var da in (functionalConstraints[key] as NodeBase).GetChildNodes())
                {
                    var doName = (da as NodeData).SCL_DOName;
                    if (doList.Exists(x => x.Name.Equals(doName)))
                    {
                        doList.Single(x => x.Name.Equals(doName)).AddChildNode(da);
                    }
                    else
                    {
                        var temp = new NodeDO(doName);
                        temp.AddChildNode(da);
                        doList.Add(temp);
                    }
                }

                var nodeFC = new NodeFC(key as string);
                foreach (NodeDO x in doList)
                {
                    nodeFC.AddChildNode(x);
                }
                nodeFC.SortImmediateChildren(); // alphabetical
                logicalNode.AddChildNode(nodeFC);
            }

            logicalNode.SortImmediateChildren(); // alphabetical

            return(logicalNode);
        }