From f17a7d9b06c6ee272716581bc4035812e521ee04 Mon Sep 17 00:00:00 2001 From: Rich Date: Wed, 16 Sep 2009 16:17:38 +0000 Subject: [PATCH] Updates to inheritance logic --- .../VEPROMS.CSLA.Library/Format/vlnFormat.cs | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs b/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs index bc2e7f39..50d72a82 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs @@ -58,6 +58,8 @@ namespace VEPROMS.CSLA.Library if (xn != null) return xn; //if (path.Contains("Font")) Console.WriteLine("vlnFormatDocument.LookupSingleNode {0},{1}", xmlNode.Name == "Step" ? "Step." + xmlNode.Attributes["Type"].Value : xmlNode.Name, path); if (xmlNode.Name == "Step") xn = LookupSingleStepNode(xmlNode, path); // Check for Step Inheritance + if (xmlNode.ParentNode.Name == "Step") + xn = LookupSingleStepNode(xmlNode.ParentNode, xmlNode.Name + "/" + path); // Check for Step Inheritance if (xn != null) return xn; if (path.StartsWith("Font")) return LookupSingleFontNode(xmlNode, path); // Then do Font Inheritance return InheritLookup(xmlNode, path, false); @@ -92,20 +94,23 @@ namespace VEPROMS.CSLA.Library { //if (path.Contains("Font")) Console.WriteLine("vlnFormatDocument.LookupSingleStepNode -> Loop {0},{1}", xmlNode.Name == "Step" ? "Step." + xmlNode.Attributes["Type"].Value : xmlNode.Name, path); tmpNode = xmlNode; + // RHM 20090831 Try doing a lookup of the parent. If no parent, go back to the original and do an inheritance lookup XmlAttribute attr = xmlNode.Attributes["ParentType"]; - if (attr == null) // Cannot find ParentType so do an InheritanceLookup - return InheritLookup(xmlNode, path, false); - xmlNode = xmlNode.ParentNode.SelectSingleNode(string.Format("Step[@Type='{0}']", xmlNode.Attributes["ParentType"].InnerText)); - if (xmlNode == null && path.StartsWith("Font")) - { - //if (path.Contains("Font")) Console.WriteLine("vlnFormatDocument.LookupSingleStepNode -> Font {0},{1}", tmpNode.Name == "Step" ? "Step." + tmpNode.Attributes["Type"].Value : tmpNode.Name, path); - return LookupSingleFontNode(tmpNode, path); - } - if (xmlNode == null) - { - //if (path.Contains("Font")) Console.WriteLine("vlnFormatDocument.LookupSingleStepNode -> Font {0},{1}", tmpNode2.Name == "Step" ? "Step." + tmpNode2.Attributes["Type"].Value : tmpNode2.Name, path); + if (attr == null || attr.Value == string.Empty) // Cannot find ParentType so do an InheritanceLookup return InheritLookup(tmpNode2, path, true); - } + //return InheritLookup(xmlNode, path, false); + xmlNode = xmlNode.ParentNode.SelectSingleNode(string.Format("Step[@Type='{0}']", xmlNode.Attributes["ParentType"].InnerText)); + // Based upon our current data - the following conditions are never met. + //if (xmlNode == null && path.StartsWith("Font")) + //{ + // //if (path.Contains("Font")) Console.WriteLine("vlnFormatDocument.LookupSingleStepNode -> Font {0},{1}", tmpNode.Name == "Step" ? "Step." + tmpNode.Attributes["Type"].Value : tmpNode.Name, path); + // return LookupSingleFontNode(tmpNode, path); + //} + //if (xmlNode == null) + //{ + // //if (path.Contains("Font")) Console.WriteLine("vlnFormatDocument.LookupSingleStepNode -> Font {0},{1}", tmpNode2.Name == "Step" ? "Step." + tmpNode2.Attributes["Type"].Value : tmpNode2.Name, path); + // return InheritLookup(tmpNode2, path, true); + //} xn = xmlNode.SelectSingleNode(path); } return xn; @@ -380,7 +385,15 @@ namespace VEPROMS.CSLA.Library else if (xn.Value == "")// No value specified - Use zero value if it is defined - GetName returns a null if it is not defined ll = new LazyLoad>(Enum.GetName(typeof(T), 0) != null ? (Nullable) Enum.Parse(typeof(T), "0") : null); else - ll = new LazyLoad>((Nullable)Enum.Parse(typeof(T), xn.InnerText)); + try + { + ll = new LazyLoad>((Nullable)Enum.Parse(typeof(T), xn.InnerText)); + } + catch (Exception ex) + { + Console.WriteLine("{0} - '{1}'", ex.Message, xn.InnerText); + ll = new LazyLoad(null); + } } return ll.Value; }