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