private TaxonomyItemUploader CreateUploader(LocalTaxonomyItem item) { TaxonomyItemUploader uploader; switch (item.Kind) { case LocalTaxonomyItemKind.TermStore: return(null); case LocalTaxonomyItemKind.TermGroup: uploader = new TermGroupUploader((LocalTermGroup)item, this); break; case LocalTaxonomyItemKind.TermSet: uploader = new TermSetUploader((LocalTermSet)item, this); break; case LocalTaxonomyItemKind.Term: uploader = new TermUploader((LocalTerm)item, this); break; default: throw new NotSupportedException(); } this.uploadersByItem.Add(item, uploader); this.queuedUploaders.Add(uploader); return(uploader); }
// If we are creating a reused instance of a term, this locates the source term // (i.e. this.clientTermOtherInstance). private bool LoadClientTermOtherInstanceForTermLink() { if (this.localTerm.TermKind == LocalTermKind.TermLinkUsingId) { // Is the source term something that we're supposed to be creating in this data set? var localTermStore = this.Controller.LocalTermStore; var localSourceTerm = this.localTerm.SourceTerm; if (localSourceTerm != null) { TermUploader sourceTermUploader = (TermUploader)this.Controller.GetUploader(localSourceTerm); if (!sourceTermUploader.FoundClientObject) { this.WaitForBlocker(sourceTermUploader); return(false); } this.clientTermOtherInstance = sourceTermUploader.ClientTerm; } } else { Debug.Assert(this.localTerm.TermKind == LocalTermKind.TermLinkUsingPath); if (this.termLinkSourcePathPartLookups == null) { this.termLinkSourcePathPartLookups = new List <TermLinkSourcePathPartLookup>(); foreach (string partName in this.localTerm.GetTermLinkSourcePathParts()) { this.termLinkSourcePathPartLookups.Add(new TermLinkSourcePathPartLookup(partName)); } // See how far we can get by matching objects from the LocalTermStore LocalTaxonomyItem localParentItem = this.Controller.LocalTermStore; foreach (TermLinkSourcePathPartLookup lookup in this.termLinkSourcePathPartLookups) { LocalTaxonomyItem localItem = localParentItem.ChildItems .FirstOrDefault(x => x.Name == lookup.PartName); if (localItem != null) { lookup.LocalTaxonomyItem = localItem; Debug.Assert(lookup.ItemIsInLocalTermStore); lookup.Uploader = this.Controller.GetUploader(localItem); localParentItem = localItem; } } } // Make sure the local parents have been created/found foreach (TermLinkSourcePathPartLookup lookup in this.termLinkSourcePathPartLookups) { if (!lookup.ItemIsInLocalTermStore) { break; } if (!lookup.Uploader.FoundClientObject) { this.WaitForBlocker(lookup.Uploader); return(false); } lookup.ClientObject = lookup.Uploader.ClientTaxonomyItem; Debug.Assert(lookup.ClientObject != null); } if (this.termLinkSourcePathPartLookups.Any(x => !x.ItemIsInLocalTermStore)) { this.SetClientWorkingLanguageToDefault(); this.termLinkSourcePathExceptionHandlingScope = new ExceptionHandlingScope(this.ClientContext); using (this.termLinkSourcePathExceptionHandlingScope.StartScope()) { using (this.termLinkSourcePathExceptionHandlingScope.StartTry()) { // For anything else, we need to query it ourselves for (int i = 0; i < this.termLinkSourcePathPartLookups.Count; ++i) { TermLinkSourcePathPartLookup lookup = this.termLinkSourcePathPartLookups[i]; if (lookup.ItemIsInLocalTermStore) { continue; } // NOTE: For these queries we don't use CsomHelpers.FlushCachedProperties() // because the objects are outside the LocalTermStore, so we don't need to // worry about the cached copies getting invalidated by the uploaders. if (i == 0) { // Find a Group lookup.ClientObject = this.Controller.ClientTermStore.Groups.GetByName(lookup.PartName); } else if (i == 1) { // Find a TermSet TermGroup clientGroup = (TermGroup)this.termLinkSourcePathPartLookups[0].ClientObject; lookup.ClientObject = clientGroup.TermSets.GetByName(lookup.PartName); } else { // Find a term TermSetItem clientTermContainer = (TermSetItem)this.termLinkSourcePathPartLookups[i - 1].ClientObject; lookup.ClientObject = clientTermContainer.Terms.GetByName(lookup.PartName); } } } using (this.termLinkSourcePathExceptionHandlingScope.StartCatch()) { } } } this.clientTermOtherInstance = (Term)this.termLinkSourcePathPartLookups.Last().ClientObject; Debug.Assert(this.clientTermOtherInstance != null); } return(true); }