private void ProcessTermSetGroup(XElement xmlNode, LocalTermStore termStore) { string name = this.GetRequiredAttributeValue(xmlNode, TaxmlSpec.NameToken); if (TaxmlSpec.IsReservedName(name)) { // TODO: Handle system groups here throw new NotImplementedException(); } Guid id = this.GetGuidAttributeValue(xmlNode, TaxmlSpec.IdToken) ?? Guid.Empty; LocalTermGroup termGroup = new LocalTermGroup(id, name, termStore.DefaultLanguageLcid); this.ReadTaxmlComments(xmlNode, termGroup); string description = this.GetAttributeValue(xmlNode, TaxmlSpec.DescriptionToken); if (description != null) { termGroup.Description = description; } // Add the group to the term store termStore.AddTermGroup(termGroup); bool processedDescription = false; foreach (XElement childNode in xmlNode.Elements()) { switch (childNode.Name.LocalName) { case TaxmlSpec.DescriptionToken: if (processedDescription) { throw new ParseException("The description cannot be specified more than once", childNode); } processedDescription = true; termGroup.Description = childNode.Value; break; case TaxmlSpec.TermSetToken: this.ProcessTermSet(childNode, termGroup); break; case TaxmlSpec.SyncActionToken: this.ProcessSyncAction(childNode, termGroup); break; default: throw new ParseException("Unimplemented XML tag \"" + childNode.Name.LocalName + "\"", childNode); } } }
private void ProcessTermSet(XElement xmlNode, LocalTermGroup termGroup) { string name = this.GetRequiredAttributeValue(xmlNode, TaxmlSpec.NameToken); Guid id = this.GetGuidAttributeValue(xmlNode, TaxmlSpec.IdToken) ?? Guid.Empty; if (TaxmlSpec.IsReservedName(name)) { if (id != Guid.Empty) { throw new ParseException( "The \"ID\" attribute may not be used with a reserved name such as \"" + name + "\"", xmlNode); } if (!termGroup.IsSystemGroup) { throw new ParseException( "The reserved TermSet \"" + name + "\" should be used inside the TermSetGroup with name \"" + TaxmlSpec.SystemGroupReservedName + "\".", xmlNode); } if (StringComparer.OrdinalIgnoreCase.Equals(name, TaxmlSpec.OrphanedTermsTermSetReservedName)) { // TODO: Handle system term sets throw new NotImplementedException(); } else if (StringComparer.OrdinalIgnoreCase.Equals(name, TaxmlSpec.KeywordsTermSetReservedName)) { // TODO: Handle system term sets throw new NotImplementedException(); } else { throw new InvalidOperationException("Unrecognized reserved name \"" + name + "\""); } } if (id == null) { id = Guid.NewGuid(); } LocalTermSet termSet = new LocalTermSet(id, name, termGroup.DefaultLanguageLcid); this.ReadTaxmlComments(xmlNode, termSet); bool?isAvailableForTaggning = this.GetBooleanAttributeValue(xmlNode, TaxmlSpec.IsAvailableForTaggingToken); if (isAvailableForTaggning.HasValue) { if (termGroup.IsSystemGroup) { throw new ParseException("The " + TaxmlSpec.IsAvailableForTaggingToken + " attribute is not supported for system term sets", xmlNode); } termSet.IsAvailableForTagging = isAvailableForTaggning.Value; } bool?isOpenForTermCreation = this.GetBooleanAttributeValue(xmlNode, TaxmlSpec.IsOpenForTermCreationToken); if (isOpenForTermCreation.HasValue) { if (termGroup.IsSystemGroup) { throw new ParseException("The " + TaxmlSpec.IsOpenForTermCreationToken + " attribute is not supported for system term sets", xmlNode); } termSet.IsOpenForTermCreation = isOpenForTermCreation.Value; } string owner = this.GetAttributeValue(xmlNode, TaxmlSpec.OwnerToken); if (owner != null) { termSet.Owner = owner; } string contact = this.GetAttributeValue(xmlNode, TaxmlSpec.ContactToken); if (contact != null) { termSet.Contact = contact; } // Add the term set to the group termGroup.AddTermSet(termSet); var inOrderList = new List <Guid>(); foreach (XElement childNode in xmlNode.Elements()) { switch (childNode.Name.LocalName) { case TaxmlSpec.LocalizedNameToken: int lcid = this.GetLcidFromLanguageAttribute(childNode, termSet); termSet.SetName(childNode.Value, lcid); break; case TaxmlSpec.DescriptionToken: // TermSet.Description is not localized termSet.Description = childNode.Value; break; case TaxmlSpec.CustomPropertyToken: this.ProcessCustomProperty(termSet.CustomProperties, childNode); break; case TaxmlSpec.CustomSortOrderToken: this.ProcessCustomSortOrder(termSet.CustomSortOrder, childNode); break; case TaxmlSpec.StakeHolderToken: termSet.AddStakeholder(childNode.Value); break; case TaxmlSpec.TermToken: this.ProcessTerm(childNode, termSet, inOrderList, isTermLink: false); break; case TaxmlSpec.TermLinkToken: this.ProcessTerm(childNode, termSet, inOrderList, isTermLink: true); break; case TaxmlSpec.SyncActionToken: this.ProcessSyncAction(childNode, termSet); break; default: throw new ParseException("Unimplemented XML tag \"" + childNode.Name.LocalName + "\"", childNode); } } this.ProcessInOrderList(termSet, inOrderList, xmlNode); }
public void LoadFromResource(Type typeInAssembly, string expectedNamespace, string resourceName) { TaxmlSpec.ImportResource(typeInAssembly, expectedNamespace, resourceName, delegate(StreamReader reader) { this.LoadFromStream(reader); } ); }