Exemplo n.º 1
0
        private bool OnProcessCreateTermLink()
        {
            // Determine the source term
            if (this.clientTermOtherInstance.ServerObjectIsNull.Value)
            {
                throw new InvalidOperationException("Source term not found for " + this.localTerm.ToString());
            }

            this.SetClientWorkingLanguageToDefault();

            this.exceptionHandlingScope = new ExceptionHandlingScope(this.ClientContext);
            using (this.exceptionHandlingScope.StartScope())
            {
                using (this.exceptionHandlingScope.StartTry())
                {
                    TermContainerUploader parentUploader = (TermContainerUploader)this.GetParentUploader();

                    this.clientTerm = parentUploader.ClientTermContainer.ReuseTerm(this.clientTermOtherInstance,
                                                                                   reuseBranch: false);

                    this.ClientContext.Load(this.clientTerm,
                                            ts => ts.Id,
                                            ts => ts.Name
                                            );

                    this.ClientTermStore.CommitAll();
                }
                using (this.exceptionHandlingScope.StartCatch())
                {
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        private bool OnProcessCreateNormalTerm()
        {
            this.SetClientWorkingLanguageToDefault();

            this.exceptionHandlingScope = new ExceptionHandlingScope(this.ClientContext);
            using (this.exceptionHandlingScope.StartScope())
            {
                using (this.exceptionHandlingScope.StartTry())
                {
                    TermContainerUploader parentUploader = (TermContainerUploader)this.GetParentUploader();

                    Guid id = this.localTerm.Id;
                    if (id == Guid.Empty)
                    {
                        id = this.Controller.ClientConnector.GetNewGuid();
                    }

                    this.clientTerm = parentUploader.ClientTermContainer.CreateTerm(this.localTerm.Name,
                                                                                    this.localTerm.DefaultLanguageLcid, id);

                    this.ClientContext.Load(this.clientTerm,
                                            ts => ts.Id,
                                            ts => ts.Name
                                            );

                    this.ClientTermStore.CommitAll();
                }
                using (this.exceptionHandlingScope.StartCatch())
                {
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        protected override bool IsPlacedCorrectly()
        {
            if (this.FindByName)
            {
                Debug.Assert(this.FoundClientObject);

                // When finding by name, the term cannot be "elsewhere"
                return(true);
            }
            else
            {
                // Does it have the right parent?
                TermContainerUploader parentUploader = (TermContainerUploader)this.GetParentUploader();

                if (parentUploader.Kind == LocalTaxonomyItemKind.TermSet)
                {
                    // The parent should be the term set, so Term.Parent should be null
                    return(this.clientTerm.Parent.ServerObjectIsNull.Value == true);
                }
                else
                {
                    // The parent should be a term
                    if (this.clientTerm.Parent.ServerObjectIsNull.Value == true)
                    {
                        return(false); // parent is the term set
                    }
                    return(this.clientTerm.Parent.Id == parentUploader.ClientTermContainer.Id);
                }
            }
        }
Exemplo n.º 4
0
        protected override bool OnProcessUpdateProperties()
        {
            if (this.localTerm.TermKind == LocalTermKind.NormalTerm)
            {
                // If TermKind=NormalTerm, then this instance is intended to be the source term.
                // If it's not, we need to fix that.
                if (!this.clientTerm.IsSourceTerm)
                {
                    this.clientTerm.SourceTerm.ReassignSourceTerm(this.clientTerm);
                }
            }

            string customSortOrder = this.localTerm.CustomSortOrder.AsTextForServer;

            this.UpdateIfChanged(
                () => this.clientTerm.CustomSortOrder != customSortOrder,
                () => this.clientTerm.CustomSortOrder = customSortOrder
                );

            bool isAvailableForTagging = this.localTerm.IsAvailableForTagging;

            this.UpdateIfChanged(
                () => this.clientTerm.IsAvailableForTagging != isAvailableForTagging,
                () => this.clientTerm.IsAvailableForTagging = isAvailableForTagging
                );

            TermContainerUploader.UpdatePropertyBag(
                this.clientTerm.LocalCustomProperties,
                (name) => this.clientTerm.DeleteLocalCustomProperty(name),
                (name, value) => this.clientTerm.SetLocalCustomProperty(name, value),
                this.localTerm.LocalCustomProperties);

            if (this.localTerm.TermKind == LocalTermKind.NormalTerm)
            {
                bool isDeprecated = this.localTerm.IsDeprecated;
                this.UpdateIfChanged(
                    () => this.clientTerm.IsDeprecated != isDeprecated,
                    () => this.clientTerm.Deprecate(isDeprecated)
                    );

                string owner = this.localTerm.Owner;
                this.UpdateIfChanged(
                    () => this.clientTerm.Owner != owner,
                    () => this.clientTerm.Owner = owner
                    );

                TermContainerUploader.UpdatePropertyBag(
                    this.clientTerm.CustomProperties,
                    (name) => this.clientTerm.DeleteCustomProperty(name),
                    (name, value) => this.clientTerm.SetCustomProperty(name, value),
                    this.localTerm.CustomProperties);

                this.UpdateLabels();
                this.UpdateDescriptions();
            }

            return(true);
        }
Exemplo n.º 5
0
        protected override bool OnProcessUpdateProperties()
        {
            this.SetClientWorkingLanguageToDefault();

            // (localized names handled below)
            string nameWithDefaultLcid = this.localTermSet.Name;

            this.UpdateIfChanged(
                () => this.clientTermSet.Name != nameWithDefaultLcid,
                () => this.clientTermSet.Name = nameWithDefaultLcid
                );

            string contact = this.localTermSet.Contact;

            this.UpdateIfChanged(
                () => this.clientTermSet.Contact != contact,
                () => this.clientTermSet.Contact = contact
                );

            string customSortOrder = this.localTermSet.CustomSortOrder.AsTextForServer;

            this.UpdateIfChanged(
                () => this.clientTermSet.CustomSortOrder != customSortOrder,
                () => this.clientTermSet.CustomSortOrder = customSortOrder
                );

            string description = this.localTermSet.Description;

            this.UpdateIfChanged(
                () => this.clientTermSet.Description != description,
                () => this.clientTermSet.Description = description
                );

            bool isAvailableForTagging = this.localTermSet.IsAvailableForTagging;

            this.UpdateIfChanged(
                () => this.clientTermSet.IsAvailableForTagging != isAvailableForTagging,
                () => this.clientTermSet.IsAvailableForTagging = isAvailableForTagging
                );

            bool isOpenForTermCreation = this.localTermSet.IsOpenForTermCreation;

            this.UpdateIfChanged(
                () => this.clientTermSet.IsOpenForTermCreation != isOpenForTermCreation,
                () => this.clientTermSet.IsOpenForTermCreation = isOpenForTermCreation
                );

            string owner = this.localTermSet.Owner;

            this.UpdateIfChanged(
                () => this.clientTermSet.Owner != owner,
                () => this.clientTermSet.Owner = owner
                );

            bool changedWorkingLanguage = false;

            foreach (var localizedNameQuery in this.localizedNameQueries)
            {
                string localizedName = this.localTermSet.GetNameWithDefault(localizedNameQuery.Lcid);
                if (localizedNameQuery.Name != localizedName)
                {
                    this.ClientTermStore.WorkingLanguage = localizedNameQuery.Lcid;
                    changedWorkingLanguage  = true;
                    this.clientTermSet.Name = localizedName;
                }
            }
            if (changedWorkingLanguage)
            {
                this.ClientTermStore.WorkingLanguage = this.Controller.DefaultLanguageLcid;
            }

            TermContainerUploader.UpdatePropertyBag(
                this.clientTermSet.CustomProperties,
                (name) => this.clientTermSet.DeleteCustomProperty(name),
                (name, value) => this.clientTermSet.SetCustomProperty(name, value),
                this.localTermSet.CustomProperties);

            this.UpdateStakeholders();

            return(true);
        }
Exemplo n.º 6
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);
        }