diff --git a/PROMS/DataLoader/ConfigInfo.cs b/PROMS/DataLoader/ConfigInfo.cs index d788cbf2..51fb8122 100644 --- a/PROMS/DataLoader/ConfigInfo.cs +++ b/PROMS/DataLoader/ConfigInfo.cs @@ -64,12 +64,48 @@ namespace DataLoader break; } XmlAttribute xa = nxml.Attributes.Append(xmldoc.CreateAttribute(aname.Replace(' ', '_'))); - xa.Value = avalue; + //added by jcb 20131216 + //aname = SanitizeXmlString(aname); + //XmlAttribute xa = nxml.Attributes.Append(xmldoc.CreateAttribute(aname)); + //end added by jcb 20131216 + xa.Value = avalue; return true; } return false; } + //added by jcb 20131216 + public string SanitizeXmlString(string xml) + { + if (xml == null) + throw new ArgumentNullException("xml"); + xml = xml.Replace(' ', '_').Replace("/", "_fslash_").Replace("(", "_lparen_").Replace((char)0xA0, '_').Replace((char)0x20, '_').Replace(":", "_colon_"); + StringBuilder buffer = new StringBuilder(xml.Length); + foreach (char c in xml) + { + if (IsLegalXmlChar(c)) + buffer.Append(c); + } + return buffer.ToString(); + } + + /// + /// Whether a given character is allowed by XML 1.0. + /// + public bool IsLegalXmlChar(int character) + { + return + ( + character == 0x9 /* == '\t' == 9 */ || + character == 0xA /* == '\n' == 10 */ || + character == 0xD /* == '\r' == 13 */ || + (character >= 0x20 && character <= 0xD7FF) || + (character >= 0xE000 && character <= 0xFFFD) || + (character >= 0x10000 && character <= 0x10FFFF) + ); + } + //end added by jcb 20131216 + public int ItemCount { get { return xmldoc.DocumentElement.ChildNodes.Count; } diff --git a/PROMS/DataLoader/Sections.cs b/PROMS/DataLoader/Sections.cs index c946007a..9840e765 100644 --- a/PROMS/DataLoader/Sections.cs +++ b/PROMS/DataLoader/Sections.cs @@ -612,21 +612,22 @@ namespace DataLoader if (cont != null) { // ContentsParts.Add can use 'fromtype', item - fromtype here = 2, section - if (cont.ContentParts.Contains(2)) - { - foreach (ContentPart part in cont.ContentParts) - { - if (part.FromType == 2) - { - Item ii = Item.Get(part.ItemID); - ii.MyContent.ContentParts.Add(2, secitem); - ii.Save(); - break; - } - } - } - else - cont.ContentParts.Add(2, secitem); + AddPartRecursive(cont, 2, secitem); + //if (cont.ContentParts.Contains(2)) + //{ + // foreach (ContentPart part in cont.ContentParts) + // { + // if (part.FromType == 2) + // { + // Item ii = Item.Get(part.ItemID); + // ii.MyContent.ContentParts.Add(2, secitem); + // ii.Save(); + // break; + // } + // } + //} + //else + // cont.ContentParts.Add(2, secitem); if (cont.MyZContent.OldStepSequence == null || cont.MyZContent.OldStepSequence == "") cont.MyZContent.OldStepSequence = ProcNumber; if (!cont.IsSavable) ErrorRpt.ErrorReport(cont); cont.Save(); @@ -669,7 +670,7 @@ namespace DataLoader // 5 = RNO // 6 = step // 7 = table - + //isautogen = false; //needed for bge if (!isautogen) { // Process the Data Table - First look for High Level Steps @@ -700,13 +701,48 @@ namespace DataLoader return secitem; } + private void AddPartRecursive(Content cont, int fromType, Item secitem) + { + if (cont.ContentParts.Contains(fromType)) + { + foreach (ContentPart part in cont.ContentParts) + { + if (part.FromType == fromType) + { + Item ii = Item.Get(part.ItemID); + AddPartRecursive(ii.MyContent, fromType, secitem); + ii.Save(); + break; + } + } + } + else + cont.ContentParts.Add(fromType, secitem); + } + private static Dictionary ApplesToOranges; + private static void ResetApplesToOranges() + { + ApplesToOranges = new Dictionary(); + } private string AddApplicability(string recnum) { - //if (recnum == "00002491") - // System.Threading.Thread.Sleep(1000); if (!MyProcAPL.ContainsKey(recnum)) return null; string apple = MyProcAPL[recnum]; + return LookupOrange(apple); + + } + private string LookupOrange(string apple) + { + if (!ApplesToOranges.ContainsKey(apple)) + { + ApplesToOranges.Add(apple, AddApplicability1(apple)); + Console.WriteLine("Apple: '{0}' - Orange: '{1}'", apple, ApplesToOranges[apple]); + } + return ApplesToOranges[apple]; + } + private string AddApplicability1(string apple) + { if (apple == "40000000") return "0"; UInt32 mask = 0; @@ -714,9 +750,11 @@ namespace DataLoader mask |= (uint)(1 << (i - 1)); UInt32 val = UInt32.Parse(apple, System.Globalization.NumberStyles.HexNumber); //UInt32 val = UInt32.Parse(apple); - val &= mask; if (val == 0) return null; + val &= mask; + if (val == 0) + return "0"; if (val == mask) return null; int j = 1; @@ -733,7 +771,6 @@ namespace DataLoader val = val >> 1; } return sb.ToString(); - } private void LoadSection(DataSet ds, OleDbDataAdapter da, string FileName) {