/// <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; }
private void QueueUploaders() { int sequence = 1; foreach (var item in ToolkitUtilities.GetPreorder <LocalTaxonomyItem>(this.localTermStore, x => x.ChildItems) ) { this.CheckForUnimplementedSyncActions(item); TaxonomyItemUploader uploader = this.CreateUploader(item); if (uploader == null) { continue; } uploader.ControllerKey.Started = false; #if false // FOR DEBUGGING, BLOCK AS MUCH AS POSSIBLE uploader.ControllerKey.Sequence = -sequence; #else uploader.ControllerKey.Sequence = sequence; #endif ++sequence; } foreach (var uploader in this.queuedUploaders.EnumerateUnordered()) { uploader.Initialize(); } }
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> /// Assigns the description for the specified language. /// </summary> public void SetDescription(string description, int lcid) { // Validate the LCID CultureInfo.GetCultureInfo(lcid); ToolkitUtilities.ConfirmNotNull(description, "description"); if (description.Contains('\t')) { throw new ArgumentException("The description cannot contain tab characters", "description"); } if (description.Length > 0x3e8) { throw new ArgumentException("The description exceeds the maximum allowable length"); } SharedData sharedData = this.GetSharedDataFromSourceTerm(exceptionIfMissing: true); if (description.Length == 0) { sharedData.DescriptionByLcid.Remove(lcid); } else { sharedData.DescriptionByLcid[lcid] = description; } }
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); }
public LocalTermStore(Guid id, string serviceName, int defaultLanguageLcid = LocalTermStore.EnglishLanguageLcid) : base(id, defaultLanguageLcid) { ToolkitUtilities.ConfirmNotNull(serviceName, "serviceName"); this.serviceName = serviceName; this.SetAvailableLanguageLcids(new[] { defaultLanguageLcid }); }
/// <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 LocalTerm(int defaultLanguageLcid, string termLinkSourcePath, bool isPinnedRoot) : base(Guid.Empty, defaultLanguageLcid) { ToolkitUtilities.ConfirmNotNull(termLinkSourcePath, "termLinkSourcePath"); this.sharedDataIfSourceTerm = null; this.termLinkData = new TermLinkData(); this.termLinkData.TermLinkSourcePathParts = LocalTerm.ParseTermLinkSourcePath(termLinkSourcePath); Debug.Assert(this.TermKind == LocalTermKind.TermLinkUsingPath); }
protected void RemoveChildItem <T>(T child) where T : LocalTaxonomyItem { ToolkitUtilities.ConfirmNotNull(child, "child"); if (child.ParentItem != this) { throw new InvalidOperationException("The " + child.Kind + " cannot be removed because it does not belong this container."); } child.ParentItem = null; }
protected T AddChildItem <T>(T child) where T : LocalTaxonomyItem { ToolkitUtilities.ConfirmNotNull(child, "child"); if (child.ParentItem != null) { throw new InvalidOperationException("The " + child.Kind + " cannot be added because it already belongs to another container."); } child.ParentItem = this; return(child); }
public Client15Connector(ClientContext clientContext) { ToolkitUtilities.ConfirmNotNull(clientContext, "clientContext"); this.clientContext = clientContext; this.GetNewGuid = () => { return(Guid.NewGuid()); }; if (this.clientContext.Tag != null) { throw new ArgumentException("The ClientContext is already tagged by another object"); } this.clientContext.Tag = this; }
/// <summary> /// Enumerates every term that belongs to this term set. /// </summary> public IEnumerable <LocalTerm> GetAllTerms() { foreach ( LocalTaxonomyItem item in ToolkitUtilities.GetPreorder((LocalTaxonomyItem)this, item => item.ChildItems)) { if (item == this) { continue; } yield return((LocalTerm)item); } }
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); }
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 TaxonomyItemDownloader(TaxonomyItemDownloaderContext downloaderContext, TClient clientObject, int treeDepth) { ToolkitUtilities.ConfirmNotNull(downloaderContext, "downloaderContext"); ToolkitUtilities.ConfirmNotNull(clientObject, "clientObject"); if (clientObject.Context != downloaderContext.ClientConnector.ClientContext) { throw new ArgumentException("The specified clientObject is not associated with a Client15Connector", "clientObject"); } this.downloaderContext = downloaderContext; this.clientObject = clientObject; this.treeDepth = treeDepth; }
private LocalTerm(Guid id, int defaultLanguageLcid, string nameHint, bool isPinnedRoot) : base(id, defaultLanguageLcid) { ToolkitUtilities.ConfirmNotNull(nameHint, "nameHint"); if (id == Guid.Empty) { throw new ArgumentException("The term link requires a non-empty Guid for the Id", "id"); } this.sharedDataIfSourceTerm = null; this.termLinkData = new TermLinkData(); Debug.Assert(this.TermKind == LocalTermKind.TermLinkUsingId); this.TermLinkNameHint = nameHint; this.IsPinnedRoot = isPinnedRoot; }
private void AddSubtreeToTable(LocalTaxonomyItem rootItem) { foreach (LocalTaxonomyItem localItem in ToolkitUtilities.GetPreorder(rootItem, (LocalTaxonomyItem x) => x.ChildItems)) { LocalTerm localTerm = localItem as LocalTerm; if (localTerm != null && localItem.Id != Guid.Empty) { // Add localTerm to the table List <LocalTerm> termList = null; if (!this.termsByGuid.TryGetValue(localTerm.Id, out termList)) { // Create the missing list termList = new List <LocalTerm>(); this.termsByGuid.Add(localTerm.Id, termList); } // Add the localTerm to the list if (localTerm.IsSourceTerm) { for (int i = 0; i < termList.Count; ++i) { if (termList[i].IsSourceTerm) { throw new InvalidOperationException(string.Format( "The term \"{0}\" cannot be the source term in two different term sets (TermId={1})", localTerm.Name, localTerm.Id)); } } // Source term is first in the list termList.Insert(0, localTerm); } else { termList.Add(localTerm); } } } }
internal LocalizedString(int lcid, string value) { ToolkitUtilities.ConfirmNotNull(value, "value"); this.lcid = lcid; this.value = value; }
private static string GetNormalized(string keyOrValue) { ToolkitUtilities.ConfirmNotNull(keyOrValue, "keyOrValue"); return(keyOrValue.Trim()); }
public void AddStakeholder(string stakeholder) { ToolkitUtilities.ConfirmNotNull(stakeholder, "stakeholder"); this.stakeholders.Add(stakeholder); }
public override int GetHashCode() { return(ToolkitUtilities.CombineHashCodes(this.isDefault.GetHashCode(), base.GetHashCode())); }
public override int GetHashCode() { return(ToolkitUtilities.CombineHashCodes(this.lcid.GetHashCode(), this.value.GetHashCode())); }
/// <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; }
public override int GetHashCode() { return(ToolkitUtilities.CombineHashCodes(this.Started.GetHashCode(), this.Sequence.GetHashCode())); }