Beispiel #1
0
        /// <summary>
        /// Unused
        /// </summary>
        /// <param name="reader"></param>
        /// <returns> a LN node </returns>
        private NodeLN CreateLogicalNode(XmlReader reader)
        {
            reader.Read();

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

            //var fcs = CreateFunctionalConstraints(type);

            name = !String.IsNullOrWhiteSpace(prefix) ? String.Concat(prefix, lnClass, inst) : String.Concat(lnClass, inst);

            var logicalNode = new NodeLN(name);

            logicalNode.TypeId = type;

            //foreach (var key in fcs.Keys)
            //{
            //    NodeFC fc = new NodeFC(key.ToString());

            //    logicalNode.AddChildNode(fcs[key] as NodeBase);
            //}

            while (reader.Read())
            {
                if (reader.IsStartElement() && reader.Name.Equals("DOI"))
                {
                    logicalNode.AddChildNode(CreateDigitalObject(reader.ReadSubtree()));
                }
            }
            logicalNode.SortImmediateChildren();
            return(logicalNode);
        }
Beispiel #2
0
        void createModelNodes(NodeLN ln, LogicalDevice ldevice)
        {
            LogicalNode lnode = new LogicalNode(ln.Name, ldevice);

            ln.SCLServerModelObject = lnode;

            foreach (NodeBase nb in ln.GetChildNodes())
            {
                if (nb is NodeDO)
                {
                    createData(nb, lnode);
                }
                else if (nb is NodeRCB)
                {
                    IEC61850.Common.ReportOptions  rptOptions = (IEC61850.Common.ReportOptions)(nb.FindChildNode("OptFlds") as NodeData).DataValue;
                    IEC61850.Common.TriggerOptions trgOptions = (IEC61850.Common.TriggerOptions)(nb.FindChildNode("TrgOps") as NodeData).DataValue;
                    string rptId   = (string)(nb.FindChildNode("RptID") as NodeData).DataValue;
                    string datSet  = (string)(nb.FindChildNode("DatSet") as NodeData).DataValue;
                    uint   confRev = (uint)(nb.FindChildNode("ConfRev") as NodeData).DataValue;
                    uint   bufTm   = (uint)(nb.FindChildNode("BufTm") as NodeData).DataValue;
                    uint   intgPd  = (uint)(nb.FindChildNode("IntgPd") as NodeData).DataValue;

                    datSet = datSet == "" ? null : datSet;

                    IEC61850.Server.ReportControlBlock rcb =
                        new IEC61850.Server.ReportControlBlock(nb.Name, lnode, rptId, (nb as NodeRCB).isBuffered, datSet, confRev, trgOptions, rptOptions, bufTm, intgPd);
                    nb.SCLServerModelObject = rcb;
                }
            }
        }
Beispiel #3
0
 private void CreateLogicalNodeTypes(List <NodeBase> list, IEnumerable <XElement> elements, XNamespace ns)
 {
     foreach (XElement el in elements)
     {
         NodeLN logicalNode = new NodeLN(el.Attribute("id").Value);
         CreateDataObjects(logicalNode, el.Elements(ns + "DO"), ns);
         list.Add(logicalNode);
     }
 }
Beispiel #4
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 void CreateLogicalNodesIEC(NodeBase ld, IEnumerable <XElement> elements, XNamespace ns)
        {
            foreach (XElement ln in elements)
            {
                XAttribute a      = ln.Attribute("prefix");
                string     prefix = a != null ? a.Value : "";
                a = ln.Attribute("lnClass");
                string lnClass = a != null ? a.Value : "";
                a = ln.Attribute("inst");
                string inst = a != null ? a.Value : "";
                a = ln.Attribute("lnType");
                string type = a != null ? a.Value : "";

                // 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;

                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);
                    continue;
                }

                // for each DO in the LNodeType
                foreach (var dataObject in nodeType.GetChildNodes())
                {
                    try
                    {
                        NodeBase doType      = _dataObjectTypes.Single(dot => dot.Name.Equals((dataObject as NodeDO).SCL_Type));
                        NodeBase ndataObject = logicalNode.AddChildNode(new NodeDO(dataObject.Name));
                        CreateSDO_DA(ndataObject, doType);
                    }
                    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;
                    }
                }
                ld.AddChildNode(logicalNode);

                CreateDataSets(logicalNode, ln.Elements(ns + "DataSet"), ns);

                CreateReports(logicalNode, ln.Elements(ns + "ReportControl"), ns);

                logicalNode.SortImmediateChildren(); // alphabetical
            }
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private NodeLN CreateLogicalNodeType(XmlReader reader)
        {
            reader.Read();
            var logicalNode = new NodeLN(reader.GetAttribute("id"));

            while (reader.Read())
            {
                if (reader.IsStartElement() && reader.Name.Equals("DO"))
                {
                    logicalNode.AddChildNode(CreateDigitalObject(reader.ReadSubtree()));
                }
            }
            return(logicalNode);
        }
Beispiel #6
0
        private void CreateDataSets(NodeLN logicalNode, IEnumerable <XElement> elements, XNamespace ns)
        {
            XAttribute a;
            NodeBase   ld = logicalNode.Parent;

            foreach (XElement el in elements)
            {
                NodeVL nodeVL = new NodeVL(el.Attribute("name").Value);
                logicalNode.AddChildNode(nodeVL);
                foreach (XElement dsMember in el.Elements(ns + "FCDA"))
                {
                    try
                    {
                        a = dsMember.Attribute("prefix");
                        string prefix2 = a != null ? a.Value : "";
                        a = dsMember.Attribute("lnClass");
                        string lnClass2 = a != null ? a.Value : "";
                        a = dsMember.Attribute("lnInst");
                        string lnInst   = a != null ? a.Value : "";
                        string fullName = String.Concat(prefix2, lnClass2, lnInst);
                        a = dsMember.Attribute("ldInst");
                        string ldInst = a != null ? a.Value : "";
                        a = dsMember.Attribute("doName");
                        string doName = a != null ? a.Value : "";
                        a = dsMember.Attribute("fc");
                        string fc = a != null ? a.Value : "";

                        // We are at the LN level, up 2 levels is an ied
                        //NodeIed iec = ld.Parent as NodeIed;

                        string serverLink = ld.Name + "/" + fullName + "." + fc + "." + doName;
                        serverLink = serverLink.Replace('.', '$');
                        string memberName = ld.Name + "/" + fullName + "." + doName;

                        // Cannot be done directly, the data are not yet present (instantiated)
                        // instead, add a temporary object
                        NodeVLM vlm = new NodeVLM(memberName);
                        vlm.SCL_FCDesc     = fc;
                        vlm.SCL_ServerLink = serverLink;
                        nodeVL.AddChildNode(vlm);
                    }
                    catch (Exception e)
                    {
                        Logger.getLogger().LogError("CreateDataSets IEC: " + e.Message);
                    }
                }
            }
        }
Beispiel #7
0
        public void BuildIECModelFromMMSModel()
        {
            iec.DefineNVL  = ied.DefineNVL;
            iec.Revision   = ied.Revision;
            iec.VendorName = ied.VendorName;
            iec.ModelName  = ied.ModelName;

            foreach (NodeLD ld in ied.GetChildNodes())      // LD level
            {
                NodeLD ild = new NodeLD(ld.Name);
                ild.IsIecModel = true;
                ild            = (NodeLD)iec.AddChildNode(ild);
                foreach (NodeLN ln in ld.GetChildNodes())   // LN level
                {
                    NodeLN iln = new NodeLN(ln.Name);
                    iln.IsIecModel = true;
                    iln            = (NodeLN)ild.AddChildNode(iln);
                    foreach (NodeFC fc in ln.GetChildNodes())   // FC level - skipping
                    {
                        if (fc.Name == "RP" || fc.Name == "BR")
                        {
                            continue;
                        }
                        // keep knowing FC for DA
                        foreach (NodeDO dO in fc.GetChildNodes())   // DO level
                        {
                            NodeDO ido = new NodeDO(dO.Name);
                            ido.IsIecModel = true;
                            // AddChildNode returns original object if the same name found (new object is forgotten)
                            ido = (NodeDO)iln.AddChildNode(ido);
                            // At this point, it can happen that we get DO more than once (same DO in several FC)
                            // For DOs, this is ok, FC is not relevant for DOs
                            // Next level is peculiar: can be DO (subDataObject) or a DA
                            // At this point, we will distinguish between DO and DA as follows:
                            // At the first guess, we suppose DA
                            // We will LINK the corresponding DA from MMS tree, and record the FC
                            // If another object with the same name comes in (from another FC branch in MMS tree)
                            // That means that we are not DA but DO (multiple FCs)
                            // And this all has to be done recursively
                            foreach (NodeBase da in dO.GetChildNodes())
                            {
                                recursiveLinkDA(da, ido, fc);
                            }
                        }
                    }
                }
            }
            // Add rcbs to LNs
            foreach (NodeLD ld in urcbs.GetChildNodes())      // LD level
            {
                foreach (NodeRCB urcb in ld.GetChildNodes())
                {
                    NodeBase ln = iec.FindNodeByAddress(ld.Name, urcb.Name.Remove(urcb.Name.IndexOf("$")));
                    if (ln != null)
                    {
                        ln.LinkChildNodeByName(urcb);
                    }
                }
            }
            foreach (NodeLD ld in brcbs.GetChildNodes())      // LD level
            {
                foreach (NodeRCB brcb in ld.GetChildNodes())
                {
                    NodeBase ln = iec.FindNodeByAddress(ld.Name, brcb.Name.Remove(brcb.Name.IndexOf("$")));
                    if (ln != null)
                    {
                        ln.LinkChildNodeByName(brcb);
                    }
                }
            }
            // Add datasets to LNs
            foreach (NodeLD ld in lists.GetChildNodes())      // LD level
            {
                foreach (NodeVL vl in ld.GetChildNodes())
                {
                    NodeBase ln = iec.FindNodeByAddress(ld.Name, vl.Name.Remove(vl.Name.IndexOf("$")));
                    if (ln != null)
                    {
                        ln.LinkChildNodeByName(vl);
                    }
                }
            }
        }
Beispiel #8
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);
        }