Exemple #1
0
        /// <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;
        }
Exemple #2
0
        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();
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        /// <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;
            }
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        public LocalTermStore(Guid id, string serviceName, int defaultLanguageLcid = LocalTermStore.EnglishLanguageLcid)
            : base(id, defaultLanguageLcid)
        {
            ToolkitUtilities.ConfirmNotNull(serviceName, "serviceName");

            this.serviceName = serviceName;
            this.SetAvailableLanguageLcids(new[] { defaultLanguageLcid });
        }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
 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;
 }
Exemple #10
0
 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;
        }
Exemple #12
0
 /// <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);
     }
 }
Exemple #13
0
        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);
        }
Exemple #14
0
        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;
        }
Exemple #16
0
        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;
        }
Exemple #17
0
        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);
                    }
                }
            }
        }
Exemple #18
0
 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());
 }
Exemple #20
0
 public void AddStakeholder(string stakeholder)
 {
     ToolkitUtilities.ConfirmNotNull(stakeholder, "stakeholder");
     this.stakeholders.Add(stakeholder);
 }
Exemple #21
0
 public override int GetHashCode()
 {
     return(ToolkitUtilities.CombineHashCodes(this.isDefault.GetHashCode(), base.GetHashCode()));
 }
Exemple #22
0
 public override int GetHashCode()
 {
     return(ToolkitUtilities.CombineHashCodes(this.lcid.GetHashCode(), this.value.GetHashCode()));
 }
Exemple #23
0
        /// <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;
        }
Exemple #24
0
 public override int GetHashCode()
 {
     return(ToolkitUtilities.CombineHashCodes(this.Started.GetHashCode(), this.Sequence.GetHashCode()));
 }