public void DeleteLabel(string label, int lcid) { string normalizedName = ToolkitUtilities.GetNormalizedTaxonomyName(label, "label"); SharedData sharedData = this.GetSharedDataFromSourceTerm(exceptionIfMissing: true); List <string> labelList = null; if (!sharedData.LabelsByLcid.TryGetValue(lcid, out labelList)) { return; } int index = labelList.IndexOf(normalizedName); if (index < 0) { throw new InvalidOperationException("The specified label does not exist"); } if (lcid == this.DefaultLanguageLcid && labelList.Count == 1) { throw new InvalidOperationException( "The label cannot be deleted because it is the default language label"); } labelList.RemoveAt(index); }
/// <summary> /// Deletes all names and assigns a new name for the default language. /// </summary> public void ClearNames(string defaultName) { string normalizedName = ToolkitUtilities.GetNormalizedTaxonomyName(defaultName, "defaultName"); this.nameByLcid.Clear(); this.nameByLcid[this.DefaultLanguageLcid] = normalizedName; }
public void AddLabel(string newLabel, int lcid, bool setAsDefaultLabel) { // Validate the LCID CultureInfo.GetCultureInfo(lcid); string normalizedName = ToolkitUtilities.GetNormalizedTaxonomyName(newLabel, "newLabel"); SharedData sharedData = this.GetSharedDataFromSourceTerm(exceptionIfMissing: true); List <string> labelList = null; if (!sharedData.LabelsByLcid.TryGetValue(lcid, out labelList)) { labelList = new List <string>(); sharedData.LabelsByLcid.Add(lcid, labelList); } int existingIndex = labelList.IndexOf(normalizedName); if (existingIndex >= 0) { labelList.RemoveAt(existingIndex); } if (setAsDefaultLabel) { // Check for sibling terms that are already using this name // (This constraint only applies to the default label.) if (this.TermKind == LocalTermKind.NormalTerm && this.parentItem != null) { var proposedNewLabel = new LocalTermLabel(lcid, newLabel, setAsDefaultLabel); foreach (LocalTerm siblingTerm in this.parentItem.Terms) { if (siblingTerm == this) { continue; } if (siblingTerm.TermKind == LocalTermKind.NormalTerm) { string objection = siblingTerm.ExplainHasLabelConflictWith(this, proposedNewLabel); if (objection != null) { throw new InvalidOperationException(objection); } } } } labelList.Insert(0, normalizedName); } else { labelList.Add(normalizedName); } // Alphabetize the remaining labels labelList.Sort(1, labelList.Count - 1, StringComparer.Ordinal); }
/// <summary> /// Deletes all labels and assigns a new default label. /// </summary> public void ClearLabels(string defaultLabel) { string normalizedName = ToolkitUtilities.GetNormalizedTaxonomyName(defaultLabel, "defaultLabel"); SharedData sharedData = this.GetSharedDataFromSourceTerm(exceptionIfMissing: true); sharedData.LabelsByLcid.Clear(); this.SetName(defaultLabel, this.DefaultLanguageLcid); }
private static List <string> ParseTermLinkSourcePath(string value) { List <string> parts = new List <string>(); var splitParts = value.Split(';'); if (splitParts.Length < 3) { throw new ArgumentException( "The TermLinkSourcePath must contain at least three semicolon-delimited names (group, term set, term)."); } foreach (string splitPart in splitParts) { parts.Add(ToolkitUtilities.GetNormalizedTaxonomyName(splitPart, "part")); } return(parts); }
public bool TryGetByName(string name, out T item) { string normalizedName = ToolkitUtilities.GetNormalizedTaxonomyName(name, "name"); // TODO: This is inefficient; ideally we should maintain a dictionary foreach (T currentItem in this.Items) { if (currentItem.Name.Equals(normalizedName, StringComparison.OrdinalIgnoreCase)) { item = currentItem; return(true); } } item = null; return(false); }
/// <summary> /// Assigns the TermSet name for the specified language. /// </summary> public override void SetName(string value, int lcid) { string normalizedName = ToolkitUtilities.GetNormalizedTaxonomyName(value, "value"); this.nameByLcid[lcid] = normalizedName; }