コード例 #1
0
        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);
        }
コード例 #2
0
        protected override bool OnProcessCheckExistence()
        {
            this.clientTerm = null;
            this.clientTermOtherInstance                  = null;
            this.descriptionResultsByLcid                 = null;
            this.termLinkSourcePathPartLookups            = null;
            this.termLinkSourcePathExceptionHandlingScope = null;

            TermContainerUploader parentUploader = (TermContainerUploader)this.GetParentUploader();

            if (!parentUploader.FoundClientObject)
            {
                this.WaitForBlocker(parentUploader);
                return(false);
            }

            TermSetUploader termSetUploader = this.GetTermSetUploader();

            if (!termSetUploader.FoundClientObject)
            {
                this.WaitForBlocker(termSetUploader);
                return(false);
            }

            if (this.localTerm.TermKind != LocalTermKind.NormalTerm)
            {
                if (!this.LoadClientTermOtherInstanceForTermLink())
                {
                    return(false);
                }
            }

            if (this.FindByName)
            {
                Debug.Assert(this.localTerm.TermKind == LocalTermKind.NormalTerm ||
                             this.localTerm.TermKind == LocalTermKind.TermLinkUsingPath);

                // TODO: If "elsewhere" isn't needed, then we
                // can get this directly from parentUploader.ClientChildTerms

                CsomHelpers.FlushCachedProperties(parentUploader.ClientTermContainer.Terms);

                this.SetClientWorkingLanguageToDefault();

                this.exceptionHandlingScope = new ExceptionHandlingScope(this.ClientContext);
                using (this.exceptionHandlingScope.StartScope())
                {
                    using (this.exceptionHandlingScope.StartTry())
                    {
                        this.clientTerm = parentUploader.ClientTermContainer.Terms
                                          .GetByName(this.localTerm.Name);

                        this.ClientContext.Load(this.clientTerm,
                                                t => t.Id,
                                                t => t.Name,
                                                t => t.IsReused,
                                                t => t.IsSourceTerm,
                                                t => t.IsPinned,
                                                t => t.IsPinnedRoot,
                                                t => t.CustomProperties,
                                                t => t.LocalCustomProperties,
                                                t => t.Labels.Include(
                                                    label => label.IsDefaultForLanguage,
                                                    label => label.Language,
                                                    label => label.Value
                                                    ),

                                                // For AssignClientChildItems()
                                                // TODO: We can sometimes skip this
                                                t => t.Terms.Include(ct => ct.Id)
                                                );

                        this.descriptionResultsByLcid = new Dictionary <int, ClientResult <string> >();

                        foreach (int lcid in this.Controller.ClientLcids)
                        {
                            CsomHelpers.FlushCachedProperties(this.clientTerm);
                            ClientResult <string> result = this.clientTerm.GetDescription(lcid);
                            this.descriptionResultsByLcid.Add(lcid, result);
                        }
                    }
                    using (this.exceptionHandlingScope.StartCatch())
                    {
                    }
                }
            }
            else
            {
                Debug.Assert(this.localTerm.TermKind == LocalTermKind.NormalTerm ||
                             this.localTerm.TermKind == LocalTermKind.TermLinkUsingId);

                this.SetClientWorkingLanguageToDefault();

                // The term/link is considered "missing" unless it's somewhere in the intended term set,
                // since otherwise it's ambiguous which instance should be moved/deleted/etc
                CsomHelpers.FlushCachedProperties(this.ClientTermStore);
                this.clientTerm = termSetUploader.ClientTermSet.GetTerm(this.localTerm.Id);
                this.ClientContext.Load(this.clientTerm,
                                        t => t.Id,
                                        t => t.Name,
                                        t => t.IsReused,
                                        t => t.IsSourceTerm,
                                        t => t.IsPinned,
                                        t => t.IsPinnedRoot,
                                        t => t.CustomProperties,
                                        t => t.LocalCustomProperties,
                                        t => t.Labels.Include(
                                            label => label.IsDefaultForLanguage,
                                            label => label.Language,
                                            label => label.Value
                                            ),
                                        t => t.Parent.Id,

                                        // For AssignClientChildItems()
                                        // TODO: We can sometimes skip this
                                        t => t.Terms.Include(ct => ct.Id)
                                        );

                // If we didn't find it in this term set, then do an expensive query to find
                // all other instances.
                var scope = new ConditionalScope(this.ClientContext,
                                                 () => this.clientTerm.ServerObjectIsNull.Value,
                                                 allowAllActions: true);
                using (scope.StartScope())
                {
                    if (this.clientTermOtherInstance == null)
                    {
                        using (scope.StartIfTrue())
                        {
                            CsomHelpers.FlushCachedProperties(this.ClientTermStore);
                            this.clientTermOtherInstance = this.ClientTermStore
                                                           .GetTerm(this.localTerm.Id);

                            this.ClientContext.Load(this.clientTermOtherInstance,
                                                    t => t.Id,
                                                    t => t.Name,
                                                    t => t.IsReused,
                                                    t => t.IsSourceTerm,
                                                    t => t.IsPinned,
                                                    t => t.IsPinnedRoot
                                                    );
                        }
                    }

                    using (scope.StartIfFalse())
                    {
                        this.descriptionResultsByLcid = new Dictionary <int, ClientResult <string> >();

                        foreach (int lcid in this.Controller.ClientLcids)
                        {
                            CsomHelpers.FlushCachedProperties(this.clientTerm);
                            ClientResult <string> result = this.clientTerm.GetDescription(lcid);
                            this.descriptionResultsByLcid.Add(lcid, result);
                        }
                    }
                }
            }

            return(true);
        }