From 2822368d57e7548df870db4462f5ed64e011a052 Mon Sep 17 00:00:00 2001 From: Rich Date: Tue, 25 Oct 2016 12:28:07 +0000 Subject: [PATCH] Fixed the code to add Parent /Child information as needed --- .../VEPROMS.CSLA.Library/Config/ProcConfig.cs | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Config/ProcConfig.cs b/PROMS/VEPROMS.CSLA.Library/Config/ProcConfig.cs index 07642f66..8634ba89 100644 --- a/PROMS/VEPROMS.CSLA.Library/Config/ProcConfig.cs +++ b/PROMS/VEPROMS.CSLA.Library/Config/ProcConfig.cs @@ -49,22 +49,42 @@ namespace VEPROMS.CSLA.Library _Procedure = procedure; string xml = procedure.MyContent.Config; if (xml == string.Empty) - { - if (_Procedure.MyProcedureInfo.MyDocVersion.MultiUnitCount > 1) - { - xml = ""; - for (int i = 1; i <= _Procedure.MyProcedureInfo.MyDocVersion.MultiUnitCount; i++) - { - xml = xml + ""; - } - xml = xml + ""; - } - else xml = ""; - } _Xp = new XMLProperties(xml); + // Correct Slaves nodes for Parent Child + ValidateSlaves(_Xp.XmlContents, _Procedure.MyProcedureInfo.MyDocVersion.MultiUnitCount); if (procedure.MyProcedureInfo.ActiveParent != null) _Xp.LookInAncestor += new XMLPropertiesEvent(Xp_LookInAncestorFolder); } + /// + /// Fix Slaves Nodes for Parent Child + /// + /// At some point it may be better to use a more forrmal structure to indentify which nodes are required and + /// which are optional. + /// + /// XmlDocument + /// Number of slave nodes supported + private static void ValidateSlaves(XmlDocument xd, int unitCount) + { + if (unitCount < 1) return; // No Slave nodes necessary + XmlNode xn = xd.DocumentElement.SelectSingleNode("Slaves"); + if (xn == null)// Missing required Slaves node - Add it. + { + XmlElement xe = xd.CreateElement("Slaves"); + xn = xd.DocumentElement.AppendChild(xe); + } + for (int i = 1; i <= unitCount; i++) + { + XmlNode xnc = xn.SelectSingleNode(string.Format("Slave[@index='{0}']", i)); + if (xnc == null) // Missing Required Slave Node (index=i) - Add it. + { + XmlElement xec = xd.CreateElement("Slave"); + xnc = xn.AppendChild(xec); + XmlAttribute xa = xd.CreateAttribute("index"); + xa.Value = i.ToString(); + xnc.Attributes.Append(xa); + } + } + } private string Xp_LookInAncestorFolder(object sender, XMLPropertiesArgs args) { if (args.AncestorLookup || ParentLookup) @@ -111,20 +131,10 @@ namespace VEPROMS.CSLA.Library _ProcedureInfo = procedureInfo; string xml = procedureInfo.MyContent.Config; if (xml == string.Empty) - { - if (_ProcedureInfo.MyDocVersion.MultiUnitCount > 0) - { - xml = ""; - for (int i = 1; i <= _ProcedureInfo.MyDocVersion.MultiUnitCount; i++) - { - xml = xml + ""; - } - xml = xml + ""; - } - else xml = ""; - } _Xp = new XMLProperties(xml); + // Fix Slaves nodes for Parent Child + ValidateSlaves(_Xp.XmlContents, _ProcedureInfo.MyDocVersion.MultiUnitCount); _Xp.AncestorLookup = true; if (procedureInfo.ActiveParent != null) _Xp.LookInAncestor += new XMLPropertiesEvent(Xp_LookInAncestorFolder); }