/***********************************************************************************************/ /* We're ready to write the rt element we have tabled up. This method writes the 'heading' */ /* and controls the writing of the hierarchical data for each hierarchy. */ /***********************************************************************************************/ private void WriteRtElement(XmlTextReader inFile, XmlTextWriter xmlOutput, RTClass group) { int i = 0, owningOrd = 0; int BaseModNum = 0, BaseClassNum = 0; if (group.owningGuid != "") { if (group.ownFlid != 0 || (group.owningGuid != "" && group.ownFlid == 0)) { if (oOrdList.TryGetValue(group.owningGuid + group.ownFlid.ToString(), out owningOrd) != true) { owningOrd = 0; oOrdList.Add(group.owningGuid + group.ownFlid.ToString(), owningOrd); } owningOrd++; oOrdList[group.owningGuid + group.ownFlid.ToString()] = owningOrd; xmlOutput.WriteStartElement("rt"); xmlOutput.WriteAttributeString("class", group.ClassName); xmlOutput.WriteAttributeString("guid", group.Guid); xmlOutput.WriteAttributeString("ownerguid", group.owningGuid); // The following are removed in data migration to 7000010, so why bother // putting them out to begin with? If there are too many objects, removing // them can lead to running out of memory. (See LT-11241.) //xmlOutput.WriteAttributeString("owningflid", group.ownFlid.ToString()); //xmlOutput.WriteAttributeString("owningord", owningOrd.ToString()); } else { throw new Exception("How can class " + group.ClassName + " have an owningGuid but no ownFlid?"); } } else { xmlOutput.WriteStartElement("rt"); xmlOutput.WriteAttributeString("class", group.ClassName); xmlOutput.WriteAttributeString("guid", group.Guid); } for (i = group.hierarchy.Count - 1; i >= 0; i--) { BaseModNum = int.Parse(group.hierarchy[i].ToString().Length < 4 ? "0" : group.hierarchy[i].ToString().Substring(0, 1)); BaseClassNum = int.Parse(group.hierarchy[i].ToString().Length == 4 ? group.hierarchy[i].ToString().Substring(1, 3) : group.hierarchy[i].ToString().Substring(0)); modList.TryGetValue(BaseModNum, out dicClass); dicClass.TryGetValue(BaseClassNum, out hClass); WriteProjectGroup(group.hierarchy[i], hClass.ClassName, xmlOutput, group); } xmlOutput.WriteEndElement(); // rt }
/***********************************************************************************************/ /* We're ready to write the rt element we have tabled up. This method writes the 'heading' */ /* and controls the writing of the hierarchical data for each hierarchy. */ /***********************************************************************************************/ private void WriteRtElement(XmlTextReader inFile, XmlTextWriter xmlOutput, RTClass group) { int i = 0, owningOrd = 0; int BaseModNum =0, BaseClassNum = 0; if (group.owningGuid != "") { if (group.ownFlid != 0 || (group.owningGuid != "" && group.ownFlid == 0)) { if (oOrdList.TryGetValue(group.owningGuid + group.ownFlid.ToString(), out owningOrd) != true) { owningOrd = 0; oOrdList.Add(group.owningGuid + group.ownFlid.ToString(), owningOrd); } owningOrd++; oOrdList[group.owningGuid + group.ownFlid.ToString()] = owningOrd; xmlOutput.WriteStartElement("rt"); xmlOutput.WriteAttributeString("class", group.ClassName); xmlOutput.WriteAttributeString("guid", group.Guid); xmlOutput.WriteAttributeString("ownerguid", group.owningGuid); // The following are removed in data migration to 7000010, so why bother // putting them out to begin with? If there are too many objects, removing // them can lead to running out of memory. (See LT-11241.) //xmlOutput.WriteAttributeString("owningflid", group.ownFlid.ToString()); //xmlOutput.WriteAttributeString("owningord", owningOrd.ToString()); } else { throw new Exception("How can class " + group.ClassName + " have an owningGuid but no ownFlid?"); } } else { xmlOutput.WriteStartElement("rt"); xmlOutput.WriteAttributeString("class", group.ClassName); xmlOutput.WriteAttributeString("guid", group.Guid); } for (i=group.hierarchy.Count-1; i >= 0; i--) { BaseModNum = int.Parse(group.hierarchy[i].ToString().Length < 4 ? "0" : group.hierarchy[i].ToString().Substring(0,1)); BaseClassNum = int.Parse(group.hierarchy[i].ToString().Length == 4 ? group.hierarchy[i].ToString().Substring(1,3) : group.hierarchy[i].ToString().Substring(0)); modList.TryGetValue(BaseModNum, out dicClass); dicClass.TryGetValue(BaseClassNum, out hClass); WriteProjectGroup(group.hierarchy[i], hClass.ClassName, xmlOutput, group); } xmlOutput.WriteEndElement(); // rt }
/**********************************************************************************************/ /* Process the end statements of an element. */ /**********************************************************************************************/ private void ProcessEndElement(XmlTextReader inFile, XmlTextWriter xmlOutput) { string elemHold = GetElementName(inFile.Name); if (GetElementNumber(inFile.Name) != "") { nodeValue = int.Parse(GetElementNumber(inFile.Name)); } if (ClosedElem == true) { PopToElement(inFile.Name); ClosedElem = false; StartElem = false; } else if (stackClasses.Count > 0 && stackClasses.Peek().ClassName == elemHold) { guidStack.Pop(); stackClasses.Pop(); if (stackClasses.Count > 0) currentRT = stackClasses.Peek(); StartClass = false; if (stackClasses.Count == 0) { if (listClasses.Count >= 1) // Write out whatever elements are tabled up. { foreach (RTClass group in listClasses) { WriteRtElement(inFile, xmlOutput, group); } } listClasses.Clear(); StartClass = false; } } else if (elemHold == "FwDatabase") // write the last closing element in the XML file { if (listClasses.Count != 0) { throw new Exception("End of fwDatabase tag received, but still items that haven't been printed."); } } else if (elemHold == "LangProject") // Write the LangProject class { WriteRtElement(inFile, xmlOutput, langProjClass); } else if (elemHold != "AdditionalFields") //It's not a close class, FwDatabase or time. close it. { if (stackClasses.Count == 0) currentRT = langProjClass; if (currentRT.elementList.TryGetValue(nodeValue, out elemDEntry) != true) { throw new Exception("This is an ending element for " + elemHold + " but the element list for class " + nodeValue.ToString() + " doesn't exist"); } if (elemHold.Length >= 6 && elemHold.Substring(0, 6) == "Custom") elemDEntry.Add(@"</Custom>"); else elemDEntry.Add(@"</" + elemHold + @">"); PopToElement(inFile.Name); StartElem = false; } }
/*********************************************************************/ /* create the new Rt object for the class. */ /*********************************************************************/ private void CreateRtElement(XmlTextReader inFile, XmlTextWriter xmlOutput) { string stackClass = "", stackNum = "", baseClassName = holdNode; int modNum = 0, fieldNum = 0, classNum = 0; StartElem = false; if (holdNode != "LangProject") { RTClass clas = new RTClass(); stackClasses.Push(clas); listClasses.Add(clas); currentRT = clas; } else currentRT = langProjClass; if (stackElements.Count > 0) { stackClass = GetElementName(stackElements.Peek()); stackNum = (GetElementNumber(stackElements.Peek())).PadLeft(3, '0'); modNum = int.Parse(stackNum.Substring(0, 1)); classNum = int.Parse(stackNum.Substring(1)); modList.TryGetValue(modNum, out dicClass); dicClass.TryGetValue(classNum, out hClass); hClass.fields.TryGetValue(stackClass, out fieldNum); if (stackNum != "000" && fieldNum != 0) currentRT.ownFlid = int.Parse((stackNum + (fieldNum.ToString().PadLeft(3, '0'))).TrimStart('0')); currentRT.owningGuid = guidStack.Peek(); } // Build Hierarchy do { classList.TryGetValue(baseClassName, out hClass); classNum = hClass.ClassNum; currentRT.hierarchy.Add(int.Parse(hClass.ModNum + classNum.ToString().PadLeft(3, '0'))); if (baseClassName !="CmObject") { classList.TryGetValue(baseClassName, out hClass); baseClassName = hClass.BaseClassName; } } while (currentRT.hierarchy[currentRT.hierarchy.Count-1] != 0); StartClass = true; currentRT.ClassName = holdNode; for (int i = 0; i < inFile.AttributeCount; i++) { inFile.MoveToAttribute(i); if (inFile.Name == "id") { currentRT.Guid = inFile.Value.Substring(1); guidStack.Push(currentRT.Guid); } else { throw new Exception("Attribute " + inFile.Name + " exists for " + holdNode); } } }
private void ProcessElement(XmlTextReader inFile, XmlTextWriter xmlOutput) { string saveGuid = ""; if (holdNode == "CustomField" || holdNode == "AdditionalFields") return; else if (holdNode == "FwDatabase") // write the root element { xmlOutput.WriteStartElement("languageproject"); WriteXMLAttribute("version", holdVersion, xmlOutput); if (holdVersion == null) { throw new Exception("The version attribute was not found in the root node of the model file " + m_ModelName); } // Make an initial pass to process the Custom Fields // Flag will be false if there aren't any. if (ProcessCustomFields() == true) { WriteCustomHeaders(xmlOutput); } } else if (inFile.GetAttribute("id") != null) // write an rt element { if (stackElements.Count > 0) { if (stackClasses.Count == 0) currentRT = langProjClass; PopPastSubentries(); inFile.MoveToAttribute("id"); //inFile.Value; // "I983B657C-9F1E-4A96-999A-CE200EA01302") if (stackElements.Count > 0 && currentRT.elementList.TryGetValue(int.Parse(GetElementNumber(stackElements.Peek())), out elemDEntry) != true) { elemDEntry = new StringCollection(); currentRT.elementList.Add(int.Parse(GetElementNumber(stackElements.Peek())), elemDEntry); } elemDEntry.Add("<objsur t=\"o\" guid=\"" + inFile.Value.Substring(1) + "\"/>"); } CreateRtElement(inFile, xmlOutput); } else if (holdNode == "Link") // write a link element { inFile.MoveToAttribute("target"); saveGuid = inFile.Value.Substring(1); PopPastSubentries(); if (currentRT.elementList.TryGetValue(int.Parse(GetElementNumber(stackElements.Peek())), out elemDEntry) != true) { elemDEntry = new StringCollection(); currentRT.elementList.Add(int.Parse(GetElementNumber(stackElements.Peek())), elemDEntry); } elemDEntry.Add("<objsur t=\"r\" guid=\"" + saveGuid + "\"/>"); } else if (holdNode == "Run" && inFile.GetAttribute("ws") == null) // Make sure runs have WS { WriteElement(inFile, xmlOutput, "", "ws=\"en\""); // write the element, guessing it should be English } else if (stackClasses.Count > 0 && holdNode.Length >= 6 && holdNode.Substring(0,6) == "Custom") // write a custom data element { WriteElement(inFile, xmlOutput, GetNewCustomName(inFile), ""); // write the next element in the class } else // Class Sub-element { WriteElement(inFile, xmlOutput, "", ""); // write the next element in the class } }
/***********************************************************************************************/ /* We're passed in the name of the hierarchy to write. We write properties associated with it. */ /***********************************************************************************************/ private void WriteProjectGroup(int hierNum, string hierName, XmlTextWriter xmlOutput, RTClass group) { //write all the elements associated with this base class if (group.elementList.ContainsKey(hierNum)) { xmlOutput.WriteStartElement(hierName); foreach (string s in group.elementList[hierNum]) { string trimmed; if (s.StartsWith("<Run ") && (trimmed = s.TrimEnd()).EndsWith(">") && trimmed.Length != s.Length) { xmlOutput.WriteRaw(s.Substring(0, trimmed.Length - 1) + " xml:space=\"preserve\"" + s.Substring(trimmed.Length - 1)); } else xmlOutput.WriteRaw(s); } xmlOutput.WriteEndElement(); } else { xmlOutput.WriteRaw("<" + hierName + @"/>"); } }
/**********************************************************************************************/ /* Process the end statements of an element. */ /**********************************************************************************************/ private void ProcessEndElement(XmlTextReader inFile, XmlTextWriter xmlOutput) { string elemHold = GetElementName(inFile.Name); if (GetElementNumber(inFile.Name) != "") { nodeValue = int.Parse(GetElementNumber(inFile.Name)); } if (ClosedElem == true) { PopToElement(inFile.Name); ClosedElem = false; StartElem = false; } else if (stackClasses.Count > 0 && stackClasses.Peek().ClassName == elemHold) { guidStack.Pop(); stackClasses.Pop(); if (stackClasses.Count > 0) { currentRT = stackClasses.Peek(); } StartClass = false; if (stackClasses.Count == 0) { if (listClasses.Count >= 1) // Write out whatever elements are tabled up. { foreach (RTClass group in listClasses) { WriteRtElement(inFile, xmlOutput, group); } } listClasses.Clear(); StartClass = false; } } else if (elemHold == "FwDatabase") // write the last closing element in the XML file { if (listClasses.Count != 0) { throw new Exception("End of fwDatabase tag received, but still items that haven't been printed."); } } else if (elemHold == "LangProject") // Write the LangProject class { WriteRtElement(inFile, xmlOutput, langProjClass); } else if (elemHold != "AdditionalFields") //It's not a close class, FwDatabase or time. close it. { if (stackClasses.Count == 0) { currentRT = langProjClass; } if (currentRT.elementList.TryGetValue(nodeValue, out elemDEntry) != true) { throw new Exception("This is an ending element for " + elemHold + " but the element list for class " + nodeValue.ToString() + " doesn't exist"); } if (elemHold.Length >= 6 && elemHold.Substring(0, 6) == "Custom") { elemDEntry.Add(@"</Custom>"); } else { elemDEntry.Add(@"</" + elemHold + @">"); } PopToElement(inFile.Name); StartElem = false; } }
/*********************************************************************/ /* create the new Rt object for the class. */ /*********************************************************************/ private void CreateRtElement(XmlTextReader inFile, XmlTextWriter xmlOutput) { string stackClass = "", stackNum = "", baseClassName = holdNode; int modNum = 0, fieldNum = 0, classNum = 0; StartElem = false; if (holdNode != "LangProject") { RTClass clas = new RTClass(); stackClasses.Push(clas); listClasses.Add(clas); currentRT = clas; } else { currentRT = langProjClass; } if (stackElements.Count > 0) { stackClass = GetElementName(stackElements.Peek()); stackNum = (GetElementNumber(stackElements.Peek())).PadLeft(3, '0'); modNum = int.Parse(stackNum.Substring(0, 1)); classNum = int.Parse(stackNum.Substring(1)); modList.TryGetValue(modNum, out dicClass); dicClass.TryGetValue(classNum, out hClass); hClass.fields.TryGetValue(stackClass, out fieldNum); if (stackNum != "000" && fieldNum != 0) { currentRT.ownFlid = int.Parse((stackNum + (fieldNum.ToString().PadLeft(3, '0'))).TrimStart('0')); } currentRT.owningGuid = guidStack.Peek(); } // Build Hierarchy do { classList.TryGetValue(baseClassName, out hClass); classNum = hClass.ClassNum; currentRT.hierarchy.Add(int.Parse(hClass.ModNum + classNum.ToString().PadLeft(3, '0'))); if (baseClassName != "CmObject") { classList.TryGetValue(baseClassName, out hClass); baseClassName = hClass.BaseClassName; } }while (currentRT.hierarchy[currentRT.hierarchy.Count - 1] != 0); StartClass = true; currentRT.ClassName = holdNode; for (int i = 0; i < inFile.AttributeCount; i++) { inFile.MoveToAttribute(i); if (inFile.Name == "id") { currentRT.Guid = inFile.Value.Substring(1); guidStack.Push(currentRT.Guid); } else { throw new Exception("Attribute " + inFile.Name + " exists for " + holdNode); } } }
private void ProcessElement(XmlTextReader inFile, XmlTextWriter xmlOutput) { string saveGuid = ""; if (holdNode == "CustomField" || holdNode == "AdditionalFields") { return; } else if (holdNode == "FwDatabase") // write the root element { xmlOutput.WriteStartElement("languageproject"); WriteXMLAttribute("version", holdVersion, xmlOutput); if (holdVersion == null) { throw new Exception("The version attribute was not found in the root node of the model file " + m_ModelName); } // Make an initial pass to process the Custom Fields // Flag will be false if there aren't any. if (ProcessCustomFields() == true) { WriteCustomHeaders(xmlOutput); } } else if (inFile.GetAttribute("id") != null) // write an rt element { if (stackElements.Count > 0) { if (stackClasses.Count == 0) { currentRT = langProjClass; } PopPastSubentries(); inFile.MoveToAttribute("id"); //inFile.Value; // "I983B657C-9F1E-4A96-999A-CE200EA01302") if (stackElements.Count > 0 && currentRT.elementList.TryGetValue(int.Parse(GetElementNumber(stackElements.Peek())), out elemDEntry) != true) { elemDEntry = new StringCollection(); currentRT.elementList.Add(int.Parse(GetElementNumber(stackElements.Peek())), elemDEntry); } elemDEntry.Add("<objsur t=\"o\" guid=\"" + inFile.Value.Substring(1) + "\"/>"); } CreateRtElement(inFile, xmlOutput); } else if (holdNode == "Link") // write a link element { inFile.MoveToAttribute("target"); saveGuid = inFile.Value.Substring(1); PopPastSubentries(); if (currentRT.elementList.TryGetValue(int.Parse(GetElementNumber(stackElements.Peek())), out elemDEntry) != true) { elemDEntry = new StringCollection(); currentRT.elementList.Add(int.Parse(GetElementNumber(stackElements.Peek())), elemDEntry); } elemDEntry.Add("<objsur t=\"r\" guid=\"" + saveGuid + "\"/>"); } else if (holdNode == "Run" && inFile.GetAttribute("ws") == null) // Make sure runs have WS { WriteElement(inFile, xmlOutput, "", "ws=\"en\""); // write the element, guessing it should be English } else if (stackClasses.Count > 0 && holdNode.Length >= 6 && holdNode.Substring(0, 6) == "Custom") // write a custom data element { WriteElement(inFile, xmlOutput, GetNewCustomName(inFile), ""); // write the next element in the class } else // Class Sub-element { WriteElement(inFile, xmlOutput, "", ""); // write the next element in the class } }
/***********************************************************************************************/ /* We're passed in the name of the hierarchy to write. We write properties associated with it. */ /***********************************************************************************************/ private void WriteProjectGroup(int hierNum, string hierName, XmlTextWriter xmlOutput, RTClass group) { //write all the elements associated with this base class if (group.elementList.ContainsKey(hierNum)) { xmlOutput.WriteStartElement(hierName); foreach (string s in group.elementList[hierNum]) { string trimmed; if (s.StartsWith("<Run ") && (trimmed = s.TrimEnd()).EndsWith(">") && trimmed.Length != s.Length) { xmlOutput.WriteRaw(s.Substring(0, trimmed.Length - 1) + " xml:space=\"preserve\"" + s.Substring(trimmed.Length - 1)); } else { xmlOutput.WriteRaw(s); } } xmlOutput.WriteEndElement(); } else { xmlOutput.WriteRaw("<" + hierName + @"/>"); } }