private static void ReadComplexListStore( XmlReader reader, ManagedItemStore managedItemStore, Dictionary<string /* Term Name */, Term> templateTerms, List<string> complexListTermsToProcess) { string termName = string.Empty; using (reader) { reader.MoveToContent(); //Positioned at 'ComplexLists' element. reader.Read(); //Positioned at first ComplexList term or end element if no terms. while (reader.NodeType != XmlNodeType.EndElement) { termName = Term.GetTermName(reader); if (complexListTermsToProcess.Contains(termName)) { //Note - we use the current template definition as a filter for the reported terms. if (templateTerms.ContainsKey(termName)) { List<string> templateFieldNames = new List<string>(); ComplexList complexList = templateTerms[termName] as ComplexList; foreach (ComplexListField complexListField in complexList.Fields) { templateFieldNames.Add(complexListField.Name); } TermStore termStore = ComplexList.CreateStore(termName, reader.ReadSubtree(), templateFieldNames); managedItemStore.AddTerm(termStore); } else { //Not found in the current template. using (reader.ReadSubtree()) { } } complexListTermsToProcess.Remove(termName); if (complexListTermsToProcess.Count == 0) { //All of the DataStoreDefinition terms have been processed, so quit early. break; } } else { //Not found in the DataStoreDefinition. using (reader.ReadSubtree()) { } } reader.Read(); //Position the reader just past the term node. } } }
private static void ReadTermStore( string templateName, Guid managedItemID, XmlReader reader, ManagedItemStore managedItemStore, Dictionary<string /* Term Name */, Term> templateTerms, List<string> basicTermsToProcess) { string termName = string.Empty; bool attachmentsProcessed = false; using (reader) { reader.MoveToContent(); //Positioned at 'Terms' element. reader.Read(); //Positioned at first term or end element if no terms. while (reader.NodeType != XmlNodeType.EndElement) { termName = Term.GetTermName(reader); if (basicTermsToProcess.Contains(termName)) { //Note - we use the current template definition as a filter for the reported terms. if (templateTerms.ContainsKey(termName)) { TermStore termStore = null; switch (reader.Name) { case XMLNames._E_Text: termStore = TextTerm.CreateStore(termName, reader.ReadSubtree()); break; case XMLNames._E_Date: termStore = Term.CreateStore(termName, reader.ReadSubtree(), TermType.Date); break; case XMLNames._E_MSO: termStore = MSOTerm.CreateStore(termName, reader.ReadSubtree()); break; case XMLNames._E_Renewal: termStore = RenewalTerm.CreateStore(termName, reader.ReadSubtree()); break; case XMLNames._E_Facility: termStore = FacilityTerm.CreateStore(termName, reader.ReadSubtree()); break; case XMLNames._E_PickList: termStore = PickListTerm.CreateStore(termName, reader.ReadSubtree()); break; case XMLNames._E_External: termStore = ExternalTerm.CreateStore(termName, templateTerms[termName] as ExternalTerm, managedItemID); break; case XMLNames._E_Link: using (reader.ReadSubtree()) { } break; //This will not be processed by older ManagedItems. case XMLNames._E_PlaceHolderAttachments: attachmentsProcessed = true; termStore = Attachment.CreateStore(termName, managedItemID); break; default: throw new Exception(string.Format("In ReadTermStore: unable to identify term type '{0}'", reader.Name)); } if (termStore != null) managedItemStore.AddTerm(termStore); } else { //Not found in the current template. using (reader.ReadSubtree()) { } } basicTermsToProcess.Remove(termName); if (basicTermsToProcess.Count == 0) { //All of the DataStoreDefinition terms have been processed, so quit early. break; } } else { //Not found in the DataStoreDefinition. using (reader.ReadSubtree()) { } } reader.Read(); //Position the reader just past the term node. } } termName = XMLNames._A_Attachments; if (!attachmentsProcessed && basicTermsToProcess.Contains(termName)) { TermStore termStore = Attachment.CreateStore(termName, managedItemID); if (termStore != null) managedItemStore.AddTerm(termStore); } }