Exemplo n.º 1
0
 public static LocalTerm CreateTermLinkUsingId(LocalTerm sourceTerm, bool isPinnedRoot = false)
 {
     if (!sourceTerm.IsSourceTerm)
     {
         throw new InvalidOperationException("Cannot create a link to a term with IsSourceTerm=false");
     }
     return(LocalTerm.CreateTermLinkUsingId(sourceTerm.Id, sourceTerm.DefaultLanguageLcid, sourceTerm.Name, isPinnedRoot));
 }
Exemplo n.º 2
0
        private void ProcessTerm(XElement xmlNode, LocalTermContainer parentTermContainer, List <Guid> parentInOrderList,
                                 bool isTermLink)
        {
            LocalTerm term;

            Guid id = this.GetGuidAttributeValue(xmlNode, TaxmlSpec.IdToken) ?? Guid.Empty;

            if (isTermLink)
            {
                string nameHint           = this.GetAttributeValue(xmlNode, TaxmlSpec.NameHintToken) ?? "";
                string termLinkSourcePath = this.GetAttributeValue(xmlNode, TaxmlSpec.TermLinkSourcePathToken) ?? "";
                if (id == Guid.Empty && string.IsNullOrWhiteSpace(termLinkSourcePath))
                {
                    throw new ParseException(
                              "TermLink elements must have either the ID attribute or the TermLinkSourcePath attribute",
                              xmlNode);
                }

                if (termLinkSourcePath.Length > 0)
                {
                    term = LocalTerm.CreateTermLinkUsingPath(parentTermContainer.DefaultLanguageLcid, termLinkSourcePath);
                }
                else
                {
                    term = LocalTerm.CreateTermLinkUsingId(id, parentTermContainer.DefaultLanguageLcid, nameHint);
                }
            }
            else
            {
                string name = this.GetRequiredAttributeValue(xmlNode, TaxmlSpec.NameToken);
                term = LocalTerm.CreateTerm(id, name, parentTermContainer.DefaultLanguageLcid);
            }

            this.ReadTaxmlComments(xmlNode, term);

            bool?isAvailableForTagging = this.GetBooleanAttributeValue(xmlNode, TaxmlSpec.IsAvailableForTaggingToken);

            if (isAvailableForTagging.HasValue)
            {
                term.IsAvailableForTagging = isAvailableForTagging.Value;
            }

            if (isTermLink)
            {
                bool?isPinnedRoot = this.GetBooleanAttributeValue(xmlNode, TaxmlSpec.IsPinnedRootToken);
                if (isPinnedRoot.HasValue)
                {
                    term.IsPinnedRoot = isPinnedRoot.Value;
                }
            }
            else
            {
                string owner = this.GetAttributeValue(xmlNode, TaxmlSpec.OwnerToken);
                if (owner != null)
                {
                    term.Owner = owner;
                }

                bool?isDeprecated = this.GetBooleanAttributeValue(xmlNode, TaxmlSpec.IsDeprecatedToken);
                if (isDeprecated.HasValue)
                {
                    term.IsDeprecated = isDeprecated.Value;
                }
            }

            bool inOrder = this.GetBooleanAttributeValue(xmlNode, TaxmlSpec.InOrderToken) ?? false;

            if (inOrder)
            {
                if (term.Id == Guid.Empty)
                {
                    throw new ParseException("The InOrder attribute cannot be used when the term ID is empty", xmlNode);
                }
                parentInOrderList.Add(term.Id);
            }

            // Add the term set to the parent term / term set
            parentTermContainer.AddTerm(term);

            var inOrderList = new List <Guid>();

            foreach (XElement childNode in xmlNode.Elements())
            {
                switch (childNode.Name.LocalName)
                {
                case TaxmlSpec.LocalizedDescriptionToken:
                    int descriptionLcid = this.GetLcidFromLanguageAttribute(childNode, term);
                    term.SetDescription(childNode.Value, descriptionLcid);
                    break;

                case TaxmlSpec.CustomPropertyToken:
                    this.ProcessCustomProperty(term.CustomProperties, childNode);
                    break;

                case TaxmlSpec.LocalCustomPropertyToken:
                    this.ProcessCustomProperty(term.LocalCustomProperties, childNode);
                    break;

                case TaxmlSpec.CustomSortOrderToken:
                    this.ProcessCustomSortOrder(term.CustomSortOrder, childNode);
                    break;

                case TaxmlSpec.LabelToken:
                    int  labelLcid         = this.GetLcidFromLanguageAttribute(childNode, term);
                    bool?setAsDefaultLabel = this.GetBooleanAttributeValue(childNode,
                                                                           TaxmlSpec.IsDefaultForLanguageToken);
                    term.AddLabel(childNode.Value, labelLcid, setAsDefaultLabel ?? false);
                    break;

                case TaxmlSpec.TermToken:
                    this.ProcessTerm(childNode, term, inOrderList, isTermLink: false);
                    break;

                case TaxmlSpec.TermLinkToken:
                    this.ProcessTerm(childNode, term, inOrderList, isTermLink: true);
                    break;

                case TaxmlSpec.SyncActionToken:
                    this.ProcessSyncAction(childNode, term);
                    break;

                default:
                    throw new ParseException("Unimplemented XML tag \"" + childNode.Name.LocalName + "\"", childNode);
                }
            }

            this.ProcessInOrderList(term, inOrderList, xmlNode);
        }