protected override bool OnProcessCheckExistence()
        {
            this.clientTermSet        = null;
            this.localizedNameQueries = null;

            TermGroupUploader groupUploader = (TermGroupUploader)this.GetParentUploader();

            if (!groupUploader.FoundClientObject)
            {
                this.WaitForBlocker(groupUploader);
                return(false);
            }
            Debug.Assert(groupUploader.ClientTermGroup != null);

            this.SetClientWorkingLanguageToDefault();

            using (this.Controller.ClientConnector.WorkingLanguageManager.StartUnmanagedScope(this.ClientTermStore))
            {
                this.exceptionHandlingScope = new ExceptionHandlingScope(this.ClientContext);
                using (this.exceptionHandlingScope.StartScope())
                {
                    using (this.exceptionHandlingScope.StartTry())
                    {
                        if (this.FindByName)
                        {
                            CsomHelpers.FlushCachedProperties(groupUploader.ClientTermGroup.TermSets);
                            this.clientTermSet = groupUploader.ClientTermGroup.TermSets
                                                 .GetByName(this.localTermSet.Name);
                        }
                        else
                        {
                            // TODO: If "elsewhere" isn't needed, then we
                            // can get this directly from groupUploader.ClientChildTermSets

                            CsomHelpers.FlushCachedProperties(this.ClientTermStore);
                            this.clientTermSet = this.ClientTermStore
                                                 .GetTermSet(this.localTermSet.Id);
                        }

                        var conditionalScope = new ConditionalScope(this.ClientContext,
                                                                    () => this.clientTermSet.ServerObjectIsNull.Value,
                                                                    allowAllActions: true);

                        using (conditionalScope.StartScope())
                        {
                            using (conditionalScope.StartIfFalse())
                            {
                                // TODO: If SyncAction.DeleteExtraChildItems==false, then we can skip this
                                this.ClientContext.Load(this.clientTermSet,
                                                        ts => ts.Id,
                                                        ts => ts.Name,
                                                        ts => ts.Group.Id,

                                                        ts => ts.CustomProperties,
                                                        ts => ts.Stakeholders,

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

                                this.localizedNameQueries = TermSetLocalizedNameQuery.Load(
                                    this.clientTermSet,
                                    this.Controller.ClientLcids,
                                    this.Controller.DefaultLanguageLcid,
                                    this.ClientTermStore,
                                    this.Controller.ClientConnector
                                    );
                            }
                        }
                    }
                    using (this.exceptionHandlingScope.StartCatch())
                    {
                    }
                }
            }
            return(true);
        }
Esempio n. 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);
        }