Exemplo n.º 1
0
        // Create the TermSetGoal objects in the specified TermStore object.
        static void SyncTermSet(TermStore termStore, TermSetGoal termSetGoal)
        {
            Group group = termStore.Groups.FirstOrDefault(g => g.Name == termSetGoal.GroupName);

            if (group == null)
            {
                Log("* Creating missing group \"" + termSetGoal.GroupName + "\"");
                group = termStore.CreateGroup(termSetGoal.GroupName);
            }

            TermSet termSet = termStore.GetTermSet(termSetGoal.Id);

            if (termSet == null)
            {
                Log("* Creating missing term set \"" + termSetGoal.Name + "\"");
                termSet = group.CreateTermSet(termSetGoal.Name, termSetGoal.Id, lcid);
            }
            else
            {
                if (termSet.Group.Id != group.Id)
                {
                    Log("* Moving term set to group \"" + group.Name + "\"");
                    termSet.Move(group);
                }

                if (termSet.Name != termSetGoal.Name)
                {
                    termSet.Name = termSetGoal.Name;
                }
            }

            termStore.CommitAll();

            // Load the tree of terms as a flat list.
            Dictionary <Guid, Term> termsById = new Dictionary <Guid, Term>();

            foreach (Term term in termSet.GetAllTerms())
            {
                termsById.Add(term.Id, term);
            }

            Log("Step 1: Adds and Moves");
            ProcessAddsAndMoves(termSet, termSetGoal, termsById);

            Log("Step 2: Deletes");
            // Requery the TermSet object to reflect changes to the topology.
            termSet = termStore.GetTermSet(termSetGoal.Id);
            ProcessDeletes(termSet, termSetGoal); // Step 2

            Log("Step 3: Property Updates");
            termSet = termStore.GetTermSet(termSetGoal.Id);
            ProcessPropertyUpdates(termSet, termSetGoal); // Step 3

            termStore.CommitAll();
        }
Exemplo n.º 2
0
 private void SetTaxonomyField(TaxonomySession metadataService, SPListItem item, Guid fieldId, string fieldValue)
 {
     TaxonomyField taxField = item.Fields[fieldId] as TaxonomyField;
     TermStore termStore = metadataService.TermStores[taxField.SspId];
     TermSet termSet = termStore.GetTermSet(taxField.TermSetId);
     SetTaxonomyFieldValue(termSet, taxField, item, fieldValue);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Aplica el Metadato al listItem especificado.
        /// </summary>
        /// <param name="listItem"></param>
        /// <param name="site"></param>
        /// <param name="campo">Field Internal Name</param>
        /// <param name="valor">Term1/Term1Son/Term1GrandSon</param>
        /// <param name="lcid"></param>
        /// <returns></returns>
        public static void SetMetadata(ref SPListItem listItem, SPSite site, string campo, string valor, int lcid, bool multi)
        {
            TaxonomySession session   = new TaxonomySession(site);
            TaxonomyField   tagsField = (TaxonomyField)listItem.Fields.GetField(campo);
            TermStore       termStore = session.TermStores[tagsField.SspId];
            TermSet         termSet   = termStore.GetTermSet(tagsField.TermSetId);
            Term            termResult;

            if (multi)
            {
                ICollection <Term> termCol = new List <Term>();
                foreach (string term in valor.Split(';'))
                {
                    termResult = CrearNuevosTerminos(ref termStore, ref termSet, valor.Split('/'), lcid);
                    termCol.Add(termResult);
                }
                tagsField.SetFieldValue(listItem, termCol);
            }
            else
            {
                termResult = CrearNuevosTerminos(ref termStore, ref termSet, valor.Split('/'), lcid);
                tagsField.SetFieldValue(listItem, termResult);
            }
            listItem.SystemUpdate();
        }
        // Create the goal objects in the specified term store
        static void ImportTermSet(TermStore termStore, TermSetGoal termSetGoal)
        {
            Log("Setting up term set \"" + termSetGoal.Name + "\"");
            Group group = termStore.Groups.FirstOrDefault(g => g.Name == termSetGoal.GroupName);

            if (group == null)
            {
                Log("Creating missing group \"" + termSetGoal.GroupName + "\"");
                group = termStore.CreateGroup(termSetGoal.GroupName);
            }

            TermSet termSet = termStore.GetTermSet(termSetGoal.Id);

            if (termSet != null)
            {
                Log("Deleting existing term set \"" + termSetGoal.Name + "\"");
                termSet.Delete();
                termStore.CommitAll();
            }

            Log("Creating new term set \"" + termSetGoal.Name + "\"");
            termSet = group.CreateTermSet(termSetGoal.Name, termSetGoal.Id);
            termStore.CommitAll();

            ImportTerms(termSet, termSetGoal);

            termStore.CommitAll();
        }
Exemplo n.º 5
0
        internal static List <SelectListItem> getTaxItems(ClientContext ctx)
        {
            List <SelectListItem> items = new List <SelectListItem>();

            TermStore      store = ctx.Site.GetDefaultKeywordsTermStore();
            TermSet        tset  = store.GetTermSet("{3D4C7DE0-3867-44C3-871A-C36DEC4E1970}".ToGuid());
            TermCollection terms = tset.Terms;

            ctx.Load(terms);
            ctx.Load(terms, tms => tms.Include(l => l.Labels));

            ctx.ExecuteQuery();

            foreach (Term t in terms)
            {
                SelectListItem item = new SelectListItem();

                item.Value = t.Id.ToString();
                item.Text  = t.Labels.Where(l => l.Language == 1033).FirstOrDefault().Value;
                items.Add(item);
            }


            return(items);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Tokenizes the taxonomy field.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        protected string TokenizeTaxonomyField(Web web, XElement element)
        {
            // Replace Taxonomy field references to SspId, TermSetId with tokens
            TaxonomySession session = TaxonomySession.GetTaxonomySession(web.Context);
            TermStore       store   = session.GetDefaultSiteCollectionTermStore();

            var sspIdElement = element.XPathSelectElement("./Customization/ArrayOfProperty/Property[Name = 'SspId']/Value");

            if (sspIdElement != null)
            {
                sspIdElement.Value = "{sitecollectiontermstoreid}";
            }
            var termSetIdElement = element.XPathSelectElement("./Customization/ArrayOfProperty/Property[Name = 'TermSetId']/Value");

            if (termSetIdElement != null)
            {
                Guid termSetId = Guid.Parse(termSetIdElement.Value);
                if (termSetId != Guid.Empty)
                {
                    Microsoft.SharePoint.Client.Taxonomy.TermSet termSet = store.GetTermSet(termSetId);
                    store.Context.ExecuteQueryRetry();

                    if (!termSet.ServerObjectIsNull())
                    {
                        termSet.EnsureProperties(ts => ts.Name, ts => ts.Group);

                        termSetIdElement.Value = String.Format("{{termsetid:{0}:{1}}}", termSet.Group.IsSiteCollectionGroup ? "{sitecollectiontermgroupname}" : termSet.Group.Name, termSet.Name);
                    }
                }
            }

            return(element.ToString());
        }
Exemplo n.º 7
0
        public static bool mk_NOR(TermStore termstore, string _group, string _termset, string _nor)
        {
            LogHelper logger = LogHelper.Instance;
            
            bool _result = false;
            try
            {
                TermSet termset = termstore.GetTermSet(GetIdTermSet(termstore, _group, _termset));

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    Term term = termset.CreateTerm(_nor, termstore.DefaultLanguage);
                    termset.TermStore.CommitAll();
                });

                _result = true;
                logger.Log(string.Format("Normativa {0} creata nel Set {1}", _nor, _termset, LogSeverity.Debug));
            }
            catch (Exception ex)
            {
                _result = false;
                logger.Log(ex.Message + " : " + string.Format("Normativa {0} non creata nel Set {1}", _nor, _termset, LogSeverity.Error));
            }
            return _result;
        }
Exemplo n.º 8
0
        public static bool sp_NOR(TermStore termstore, string _group, string _termset, string _nor, string _p, string _v)
        {
            LogHelper logger = LogHelper.Instance;
            
            bool _result = false;

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    Guid uidStore = new Guid(idStore);
                    TermSet termset = termstore.GetTermSet(GetIdTermSet(termstore, _group, _termset));
                    Term term = termset.Terms[_nor];
                    term.SetCustomProperty(_p, _v);
                    termset.TermStore.CommitAll();
                });

                _result = true;
                logger.Log(string.Format("Proprietà {0} aggiunta nella Normativa {1} ", _p, _nor, LogSeverity.Debug));
            }
            catch (Exception ex)
            {
                _result = false;
                logger.Log(ex.Message + " : " + string.Format("Proprietà {0} non aggiunta nella Normativa {1} ", _p, _nor, LogSeverity.Error));
            }
            return _result;
        }
Exemplo n.º 9
0
        public static void CreateProductTaxonomy(ClientContext ctx)
        {
            TermStore store = ctx.Site.GetDefaultKeywordsTermStore();
            TermGroup productCategoryGroup = store.GetTermGroupByName("OD2");

            if (productCategoryGroup == null)
            {
                productCategoryGroup = store.CreateTermGroup("OD2", Constants.TAXONOMY_OD2_GROUP_ID.ToGuid(), "Stuff for od2");
            }


            TermSet ts = store.GetTermSet(Constants.TAXONOMY_PRODUCTCAT_TERMSET_ID.ToGuid());

            ctx.Load(ts);
            ctx.ExecuteQuery();
            // if term store does not exist create a new one.
            if (ts.ServerObjectIsNull.Value)
            {
                ts = productCategoryGroup.CreateTermSet("Product Category", Constants.TAXONOMY_PRODUCTCAT_TERMSET_ID.ToGuid(), 1033);
                store.CommitAll();
                ctx.Load(ts);
                ctx.ExecuteQuery();
                ts.CreateTerm("Prod Cat 1", 1033, Guid.NewGuid());
                ts.CreateTerm("Prod Cat 2", 1033, Guid.NewGuid());
                ts.CreateTerm("Prod Cat 3", 1033, Guid.NewGuid());
                ts.CreateTerm("Prod Cat 4", 1033, Guid.NewGuid());

                store.CommitAll();
                ctx.ExecuteQuery();
            }
        }
Exemplo n.º 10
0
        public static bool mk_At(TermStore termstore, string _group, string _termset, string _am, string _pr, string _at)
        {
            LogHelper logger = LogHelper.Instance;
            
            bool _result = false;
            try
            {
                TermSet termset = termstore.GetTermSet(GetIdTermSet(termstore, _group, _termset));
                Term term = termset.Terms[_am].Terms[_pr];

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    term.CreateTerm(_at, termstore.DefaultLanguage);
                    termset.TermStore.CommitAll();
                });

                _result = true;
                logger.Log(string.Format("Attivita {0} creata nel processo {1} dell'ambito {2} nel set {3}", _pr, _am, _termset, LogSeverity.Debug));
            }
            catch (Exception ex)
            {
                _result = false;
                logger.Log(ex.Message + " : " + string.Format("Attivita {0} creata nel processo {1} dell'ambito {2} nel set {3}", _at, _pr, _am, _termset, LogSeverity.Debug));
            }
            return _result;
        }
Exemplo n.º 11
0
        public static string GetTermIdForTerm(string term, Guid termSetId, ClientContext clientContext)
        {
            string termId = string.Empty;

            //Get term set from ID
            TaxonomySession tSession = TaxonomySession.GetTaxonomySession(clientContext);
            TermStore       ts       = tSession.GetDefaultSiteCollectionTermStore();
            TermSet         tset     = ts.GetTermSet(termSetId);

            LabelMatchInformation lmi = new LabelMatchInformation(clientContext);

            lmi.Lcid            = 1033;
            lmi.TrimUnavailable = true;
            lmi.TermLabel       = term;

            //Search for matching terms in the term set based on label
            TermCollection termMatches = tset.GetTerms(lmi);

            clientContext.Load(tSession);
            clientContext.Load(ts);
            clientContext.Load(tset);
            clientContext.Load(termMatches);

            clientContext.ExecuteQuery();

            //Set term ID to first match
            if (termMatches != null && termMatches.Count() > 0)
            {
                termId = termMatches.First().Id.ToString();
            }

            return(termId);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Updates a single-value managed metatada column
        /// </summary>
        /// <param name="taxonomyTerm"></param>
        /// <param name="item"></param>
        /// <param name="fieldToUpdate"></param>
        public static void UpdateMMField(string taxonomyTerm, SPListItem item, string fieldToUpdate)
        {
            //Get the metadata taxonomy field, a taxonomy session, the term store, and a collection of term sets in the store
            TaxonomyField   managedMetadataField = item.ParentList.Fields[fieldToUpdate] as TaxonomyField;
            Guid            tsId        = managedMetadataField.TermSetId;
            Guid            termStoreId = managedMetadataField.SspId;
            TaxonomySession tSession    = new TaxonomySession(item.ParentList.ParentWeb.Site);
            TermStore       tStore      = tSession.TermStores[termStoreId];
            TermSet         tSet        = tStore.GetTermSet(tsId);
            TermCollection  terms       = tSet.GetTerms(taxonomyTerm, false);
            Term            term        = null;

            //If term doesn't exist, create it in the term store
            if (terms.Count == 0)
            {
                Console.WriteLine("Creating term in managed metadata, {0}", taxonomyTerm);
                term = tSet.CreateTerm(taxonomyTerm, tStore.Languages[0]);
                tStore.CommitAll();
            }
            else
            {
                term = terms[0];
            }

            //Set the managed metadata field to the term retrieved from the term store
            managedMetadataField.SetFieldValue(item, term);
            item.Update();
        }
Exemplo n.º 13
0
        protected override void ProcessFieldProperties(SPField field, FieldDefinition fieldModel)
        {
            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            // process taxonomy field specific properties
            var taxField      = field.WithAssertAndCast <TaxonomyField>("field", value => value.RequireNotNull());
            var taxFieldModel = fieldModel.WithAssertAndCast <TaxonomyFieldDefinition>("model", value => value.RequireNotNull());

            var site = GetCurrentSite();

            var       taxSession = new TaxonomySession(site);
            TermStore tesmStore  = null;

            if (taxFieldModel.UseDefaultSiteCollectionTermStore == true)
            {
                tesmStore = taxSession.DefaultSiteCollectionTermStore;
            }
            else if (taxFieldModel.SspId.HasValue)
            {
                tesmStore = taxSession.TermStores[taxFieldModel.SspId.Value];
            }
            else if (!string.IsNullOrEmpty(taxFieldModel.SspName))
            {
                tesmStore = taxSession.TermStores[taxFieldModel.SspName];
            }

            TermSet termSet = null;

            if (taxFieldModel.TermSetId.HasValue)
            {
                termSet = tesmStore.GetTermSet(taxFieldModel.TermSetId.Value);
            }
            else if (!string.IsNullOrEmpty(taxFieldModel.TermSetName))
            {
                termSet = tesmStore.GetTermSets(taxFieldModel.TermSetName, taxFieldModel.TermSetLCID).FirstOrDefault();
            }

            Term term = null;

            if (taxFieldModel.TermId.HasValue)
            {
                term = tesmStore.GetTerm(taxFieldModel.TermId.Value);
            }
            else if (!string.IsNullOrEmpty(taxFieldModel.TermName))
            {
                term = tesmStore.GetTerms(taxFieldModel.TermName, taxFieldModel.TermLCID, false).FirstOrDefault();
            }

            taxField.SspId = tesmStore.Id;

            if (termSet != null)
            {
                taxField.TermSetId = termSet.Id;
            }
            else if (term != null)
            {
                taxField.TermSetId = term.Id;
            }
        }
Exemplo n.º 14
0
        private void MatchTaxonomyField(SPListItem targetSPListItem, SPField targetSPField, string sourceValue)
        {
            // this is a managed metadata field
            TaxonomyField   managedField = targetSPField as TaxonomyField;
            TaxonomySession session      = new TaxonomySession(targetSPListItem.Web.Site);
            TermStore       termStore    = session.TermStores[managedField.SspId];
            TermSet         termSet      = termStore.GetTermSet(managedField.TermSetId);
            int             lcid         = CultureInfo.CurrentCulture.LCID;

            // TODO: this is Classification code; to be replaced with the one below!
            Term myTerm = termSet.GetTerms(this.SubstringBefore(sourceValue, "|"), false).FirstOrDefault();

            if (myTerm != null)
            {
                string termString =
                    string.Concat(myTerm.GetDefaultLabel(lcid), TaxonomyField.TaxonomyGuidLabelDelimiter, myTerm.Id);
                int[] ids =
                    TaxonomyField.GetWssIdsOfTerm(targetSPListItem.Web.Site, termStore.Id, termSet.Id, myTerm.Id, true, 1);

                // set the WssId (TaxonomyHiddenList ID) to -1 so that it is added to the TaxonomyHiddenList
                if (ids.Length == 0)
                {
                    termString = "-1;#" + termString;
                }
                else
                {
                    termString = ids[0] + ";#" + termString;
                }

                targetSPListItem[targetSPField.Id] = termString;
            }
        }
Exemplo n.º 15
0
 private void SetTaxonomyField(TaxonomySession metadataService, SPListItem item, Guid fieldId, List<string> fieldValues)
 {
     TaxonomyField taxField = item.Fields[fieldId] as TaxonomyField;
     TermStore termStore = metadataService.TermStores[taxField.SspId];
     TermSet termSet = termStore.GetTermSet(taxField.TermSetId);
     if (taxField.AllowMultipleValues) SetTaxonomyFieldMultiValue(termSet, taxField, item, fieldValues);
     else SetTaxonomyFieldValue(termSet, taxField, item, fieldValues.First());
 }
Exemplo n.º 16
0
        internal static bool CheckIfTermSetIdIsUnique(TermStore store, Guid id)
        {
            var existingTermSet = store.GetTermSet(id);

            store.Context.Load(existingTermSet);
            store.Context.ExecuteQueryRetry();

            return(existingTermSet.ServerObjectIsNull == true);
        }
Exemplo n.º 17
0
        public static NavigationTermSet CriarItemNaTermStore(string url, string urlweb, Guid NavTermSetId, Guid TaggingTermSetId)
        {
            SPSite site = new SPSite(url);

            SPWeb web = site.AllWebs[urlweb];

            TaxonomySession taxonomySession = new TaxonomySession(site);

            if (taxonomySession.TermStores.Count == 0)
            {
                throw new InvalidOperationException("O Serviço de taxonomia não existe");
            }

            TermStore termStore = taxonomySession.TermStores[0];

            TermSet existingTermSet = termStore.GetTermSet(NavTermSetId);

            if (existingTermSet != null)
            {
                existingTermSet.Delete();
                termStore.CommitAll();
            }


            Group   siteCollectionGroup = termStore.GetSiteCollectionGroup(web.Site);
            TermSet termSet             = siteCollectionGroup.CreateTermSet("Teste01", NavTermSetId);

            termStore.CommitAll();

            NavigationTermSet navTermSet = NavigationTermSet.GetAsResolvedByWeb(termSet, web,
                                                                                StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider);

            termStore.CommitAll();

            navTermSet.IsNavigationTermSet = true;

            navTermSet.TargetUrlForChildTerms.Value = "/en/Pages/default.aspx";

            NavigationTerm term1 = navTermSet.CreateTerm("Term 1", NavigationLinkType.SimpleLink);

            term1.SimpleLinkUrl = "http://h9j/pt/Paginas/default.aspx";
            termStore.CommitAll();

            /*
             * NavigationTerm term2 = navTermSet.CreateTerm("Term 2", NavigationLinkType.FriendlyUrl, Guid.NewGuid());
             *
             * term2.FriendlyUrlSegment.Value = "PAgInicial";
             *
             * term2.TargetUrl.Value = "/en/Pages/default.aspx";
             */


            termStore.CommitAll();

            return(navTermSet);
        }
Exemplo n.º 18
0
        public ActionResult GetFields(string SelectedCT, string SPHostUrl)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            using (var ctx = spContext.CreateUserClientContextForSPHost())
            {
                List        list = ctx.Web.Lists.GetByTitle("karlshamn");
                ContentType contentTypeToEdit = list.ContentTypes.GetById(SelectedCT);
                ctx.Load(list);
                ctx.Load(contentTypeToEdit, include => include.Fields, include => include.Name);
                ctx.ExecuteQuery();

                TermStore store = ctx.Site.GetDefaultSiteCollectionTermStore();
                //TermGroup group = store.GetTermGroupByName("Qian_OfficeAddin");
                TermSet termSet = store.GetTermSet("08b6e1c6-d9ac-4014-bcbf-6e23987fb5c5".ToGuid());


                ctx.Load(store);
                //ctx.Load(group);
                ctx.Load(termSet, include => include.Terms);
                ctx.ExecuteQuery();


                List <string> termList = new List <string>();

                foreach (Term term in termSet.Terms)
                {
                    termList.Add(term.Name);
                }


                ViewBag.Term  = termList;
                ViewBag.Term1 = "Meh";



                List <string> fieldList = new List <string>();
                foreach (Field item in contentTypeToEdit.Fields)
                {
                    if (item.Group == "Karlshamn Fields")
                    {
                        fieldList.Add(item.Title);
                    }
                }

                FieldCollection fields = contentTypeToEdit.Fields;

                ViewBag.Title = contentTypeToEdit.Name;

                ViewBag.SelectedCT = SelectedCT;
                ViewBag.SPHostUrl  = SPHostUrl;

                return(View(fields));
            }
        }
Exemplo n.º 19
0
        private string GetTermIdForTaxonomyField(TaxonomyField field, string term, ListItem pendingItem, Microsoft.SharePoint.Client.File pendingFile)
        {
            if (_terms == null)
            {
                _terms = new Dictionary <string, IDictionary <string, string> >();
            }

            if (!_terms.Keys.Contains(field.Title))
            {
                _terms[field.Title] = new Dictionary <string, string>();
            }

            if (_terms[field.Title].Keys.Contains(term))
            {
                return(_terms[field.Title][term].ToString());
            }

            var termId = string.Empty;

            //before we go forward,save pending item
            pendingItem.Update();
            ctx.Load(pendingFile);
            ctx.ExecuteQuery();

            TaxonomySession tSession = TaxonomySession.GetTaxonomySession(ctx);

            ctx.Load(tSession.TermStores);
            ctx.ExecuteQuery();
            TermStore ts   = tSession.TermStores.First();
            TermSet   tset = ts.GetTermSet(field.TermSetId);

            LabelMatchInformation lmi = new LabelMatchInformation(ctx);

            lmi.Lcid            = 1033;
            lmi.TrimUnavailable = true;
            lmi.TermLabel       = term;

            TermCollection termMatches = tset.GetTerms(lmi);

            ctx.Load(tSession);
            ctx.Load(ts);
            ctx.Load(tset);
            ctx.Load(termMatches);

            ctx.ExecuteQuery();

            if (termMatches != null && termMatches.Count() > 0)
            {
                termId = termMatches.First().Id.ToString();
            }

            _terms[field.Title][term] = termId;

            return(termId);
        }
Exemplo n.º 20
0
        private IEnumerable <NavigationNode> FilterNavigationNodesToRestrictedTermSet(SPWeb web, NavigationQueryParameters queryParameters, IEnumerable <NavigationNode> nodes, Term[] restrictedTerms = null)
        {
            // If first pass, initialize the restricted nodes with first level terms
            if (restrictedTerms == null)
            {
                // Get restricted term set
                var       session   = new TaxonomySession(web.Site);
                TermStore termStore = null;

                if (queryParameters.TermStoreId == Guid.Empty)
                {
                    termStore = this.taxonomyHelper.GetDefaultSiteCollectionTermStore(session);
                }
                else
                {
                    termStore = session.TermStores[queryParameters.TermStoreId];
                }

                var termSet = termStore.GetTermSet(queryParameters.RestrictedTermSetId);

                var nodeMatchingSettings = queryParameters.NodeMatchingSettings;
                if ((nodeMatchingSettings != null) && nodeMatchingSettings.RestrictToCurrentNavigationLevel)
                {
                    var currentTermId = TaxonomyNavigationContext.Current.NavigationTerm.Id;
                    restrictedTerms = termSet.GetTerm(currentTermId).Parent.Terms.ToArray();
                }
                else
                {
                    restrictedTerms = termSet.Terms.ToArray();
                }
            }

            // Flattened navigation nodes for easier search
            var flattenedNodes  = nodes.Flatten(node => node.ChildNodes);
            var restrictedNodes = restrictedTerms.Select(term => flattenedNodes.SingleOrDefault(node => node.Id.Equals(term.Id))).ToArray();

            for (var i = 0; i < restrictedTerms.Length; i++)
            {
                var restrictedTerm = restrictedTerms[i];
                var restrictedNode = restrictedNodes[i];

                // If term contains children, recurvise call
                if (restrictedTerm.Terms.Count > 0)
                {
                    restrictedNode.ChildNodes = this.FilterNavigationNodesToRestrictedTermSet(web, queryParameters, nodes, restrictedTerm.Terms.ToArray());
                }
                else
                {
                    restrictedNode.ChildNodes = new List <NavigationNode>();
                }
            }

            return(restrictedNodes);
        }
Exemplo n.º 21
0
        public static string SetReference(ClientContext ctx, TaxonomyFieldValueCollection tax, TaxonomyFieldValue typeDoc, int Id)
        {
            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(ctx);

            taxonomySession.UpdateCache();
            TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();

            ctx.Load(termStore,
                     termStoreArg => termStoreArg.WorkingLanguage,
                     termStoreArg => termStoreArg.Id,
                     termStoreArg => termStoreArg.Groups.Include(
                         groupArg => groupArg.Id,
                         groupArg => groupArg.Name
                         )
                     );
            Guid    catTermId  = new Guid(tax.ElementAt(0).TermGuid);
            TermSet catTermSet = termStore.GetTermSet(new Guid("6792f6c1-20ec-4e10-a1e8-a2c04f2906ec"));
            Term    catTerm    = catTermSet.GetTerm(catTermId);

            ctx.Load(catTermSet);
            ctx.Load(catTerm);
            ctx.Load(catTerm.Labels);
            // ctx.Load(catTerm.Parent.Labels);
            Guid    docTermId  = new Guid(typeDoc.TermGuid);
            TermSet docTermSet = termStore.GetTermSet(new Guid("40ae95fa-353f-4154-a574-65f7297286ca"));
            Term    docTerm    = docTermSet.GetTerm(docTermId);

            ctx.Load(docTermSet);
            ctx.Load(docTerm);
            ctx.Load(docTerm.Labels);
            ctx.ExecuteQuery();
            string reference = catTerm.Labels[1].Value + "/" + docTerm.Labels[1].Value + "/" + Id;

            //if(catTerm.Parent.Labels.Count > 1)
            //{
            //   reference = catTerm.Parent.Labels[1].Value + "/" + catTerm.Labels[1].Value + "/" + docTerm.Labels[1].Value + "/" + Id;
            //}
            return(reference);
        }
Exemplo n.º 22
0
        /// <summary>Fixes the SP field taxonomy.</summary>
        /// <param name="contextSpSite">The context sp site.</param>
        /// <param name="fileSPListItem">The file sp list item.</param>
        /// <param name="sourceValue">The source value.</param>
        /// <returns>The fix sp field taxonomy.</returns>
        private string FixSPFieldTaxonomy(SPSite contextSpSite, SPListItem fileSPListItem, string sourceValue)
        {
            string s    = "\t\tTaxonomy\n\t\t-" + contextSpSite.Url + ",\n\t\t-" + sourceValue + "\n";
            int    lcid = CultureInfo.CurrentCulture.LCID;

            // this is a managed metadata field
            TaxonomyField   taxonomyField   = this.ContextSPField as TaxonomyField;
            TaxonomySession taxonomySession = new TaxonomySession(contextSpSite);
            TermStore       termStore       = taxonomySession.TermStores[taxonomyField.SspId];
            TermSet         termSet         = termStore.GetTermSet(taxonomyField.TermSetId);

            s += "\t\tlcid:\t\t" + lcid + "\n\t\ttaxField:\t" + taxonomyField.Title + "\n";
            s += "\t\ttermstores:\t" + taxonomySession.TermStores.Count + "\n";
            s += "\t\ttermstore:\t" + termStore.Name + "\n\t\ttermset:\t" + termSet.Name + "\n";

            // this is Classification code; to be replaced with the one below!
            Term myTerm = termSet.GetTerms(this.SubStringBefore(sourceValue, "|"), false).FirstOrDefault();

            if (myTerm != null)
            {
                s += "\t\tmyTerm:\t\t" + myTerm.Name + "\n";
                s += "\t\twas:" + fileSPListItem[this.ContextSPField.Id] + "\n";
                string termString = String.Concat(myTerm.GetDefaultLabel(lcid),
                                                  TaxonomyField.TaxonomyGuidLabelDelimiter,
                                                  myTerm.Id);
                int[] ids = TaxonomyField.GetWssIdsOfTerm(
                    contextSpSite,
                    termStore.Id,
                    termSet.Id,
                    myTerm.Id,
                    true,
                    1);
                s += "\t\ttermString:\t" + termString + "\n\t\tids:\t\t" + ids.Length + "\n";

                // set the WssId (TaxonomyHiddenList ID) to -1 so that it is added to the TaxonomyHiddenList
                // fileSPListItem[this.ContextSPField.Id] = (ids.Length == 0) ? "-1;#" + termString : ids[0] + ";#" + termString;
                if (ids.Length == 0)
                {
                    termString = "-1;#" + termString;
                }
                else
                {
                    termString = ids[0] + ";#" + termString;
                }

                fileSPListItem[this.ContextSPField.Id] = termString;
            }

            s += "\t\tis_:" + fileSPListItem[this.ContextSPField.Id] + "\n";
            return(s);
        }
Exemplo n.º 23
0
        public static NavigationTermSet RecreateSampleNavTermSet(TestContext testContext,
                                                                 TaxonomySession taxonomySession, SPWeb web)
        {
            Console.WriteLine(testContext, "RecreateSampleNavTermSet(): START");

            // Use the first TermStore object in the list.
            if (taxonomySession.TermStores.Count == 0)
            {
                throw new InvalidOperationException("The Taxonomy Service is offline or missing.");
            }

            TermStore termStore = taxonomySession.TermStores[0];

            // Does the TermSet object already exist?
            TermSet existingTermSet = termStore.GetTermSet(TestConfig.NavTermSetId);

            if (existingTermSet != null)
            {
                Console.WriteLine(testContext, "RecreateSampleNavTermSet(): Deleting old TermSet");
                existingTermSet.Delete();
                termStore.CommitAll();
            }

            Console.WriteLine(testContext, "RecreateSampleNavTermSet(): Creating new TermSet");

            // Create a new TermSet object.
            Group   siteCollectionGroup = termStore.GetSiteCollectionGroup(web.Site);
            TermSet termSet             = siteCollectionGroup.CreateTermSet("Navigation Demo", TestConfig.NavTermSetId);

            NavigationTermSet navTermSet = NavigationTermSet.GetAsResolvedByWeb(termSet, web,
                                                                                StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider);

            navTermSet.IsNavigationTermSet          = true;
            navTermSet.TargetUrlForChildTerms.Value = "~site/Pages/Topics/Topic.aspx";

            NavigationTerm term1 = navTermSet.CreateTerm("Term 1", NavigationLinkType.SimpleLink);

            term1.SimpleLinkUrl = "http://www.bing.com/";

            NavigationTerm term2  = navTermSet.CreateTerm("Term 2", NavigationLinkType.FriendlyUrl);
            NavigationTerm term2a = term2.CreateTerm("Term 2 A", NavigationLinkType.FriendlyUrl);
            NavigationTerm term2b = term2.CreateTerm("Term 2 B", NavigationLinkType.FriendlyUrl);

            NavigationTerm term3 = navTermSet.CreateTerm("Term 3", NavigationLinkType.FriendlyUrl);

            termStore.CommitAll();

            Console.WriteLine(testContext, "RecreateSampleNavTermSet(): FINISH");

            return(navTermSet);
        }
Exemplo n.º 24
0
        private static Term GetTermByName(ClientContext ctx, string issueCategory)
        {
            TermStore store   = ctx.Site.GetDefaultSiteCollectionTermStore();
            TermSet   termSet = store.GetTermSet("{3D4C7DE0-3867-44C3-871A-C36DEC4E1970}".ToGuid());

            TermCollection terms = termSet.Terms;

            ctx.Load(terms);
            ctx.ExecuteQuery();

            Term term = terms.Where(t => t.Name == issueCategory).FirstOrDefault();

            return(term);
        }
Exemplo n.º 25
0
        public static TaxonomyFieldValue GetTaxonomyFieldValue(SPSite site, TaxonomyField field, string value, out List <int> wssIds)
        {
            TaxonomySession taxonomySession = new TaxonomySession(site);
            TermStore       termStore       = taxonomySession.TermStores[field.SspId];
            TermSet         termSet         = termStore.GetTermSet(field.TermSetId);

            wssIds = new List <int>();
            TaxonomyFieldValue taxonomyFieldValue = TaxonomyFieldControl.GetTaxonomyValue(value);

            wssIds.AddRange(TaxonomyField.GetWssIdsOfTerm(site, termStore.Id, termSet.Id,
                                                          new Guid(taxonomyFieldValue.TermGuid), true, 100));

            return(taxonomyFieldValue);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Extract all the terms from a termset for caching and quicker processing
        /// </summary>
        /// <param name="termSetId"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static Dictionary <Guid, TermData> GetAllTermsFromTermSet(Guid termSetId, ClientContext context)
        {
            //Use a source and target Dictionary<guid,string>
            //Key = Id, Value = Path(e.g.termgroup | termset | term)
            var termsCache = new Dictionary <Guid, TermData>();

            try
            {
                using (var clonedContext = context.Clone(context.Web.GetUrl()))
                {
                    TaxonomySession session   = TaxonomySession.GetTaxonomySession(clonedContext);
                    TermStore       termStore = session.GetDefaultSiteCollectionTermStore();
                    var             termSet   = termStore.GetTermSet(termSetId);
                    var             termGroup = termSet.Group;
                    clonedContext.Load(termSet, t => t.Terms, t => t.Name);
                    clonedContext.Load(termGroup, g => g.Name);
                    clonedContext.ExecuteQueryRetry();

                    var termGroupName = termGroup.Name;
                    var setName       = termSet.Name;
                    var termSetPath   = $"{termGroupName}{TermTransformator.TermNodeDelimiter}{setName}";
                    foreach (var term in termSet.Terms)
                    {
                        var termName = term.Name;
                        var termPath = $"{termSetPath}{TermNodeDelimiter}{termName}";
                        termsCache.Add(term.Id,
                                       new TermData()
                        {
                            TermGuid = term.Id, TermLabel = termName, TermPath = termPath, TermSetId = termSetId
                        });

                        if (term.TermsCount > 0)
                        {
                            var subTerms = ParseSubTerms(termPath, term, termSetId, clonedContext);
                            //termsCache
                            foreach (var foundTerm in subTerms)
                            {
                                termsCache.Add(foundTerm.Key, foundTerm.Value);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //TODO: Record any failure
            }

            return(termsCache);
        }
Exemplo n.º 27
0
        public static TermSet LookupTermSet(TermStore tesmStore, string termSetName, Guid?termSetId, int termSetLCID)
        {
            if (termSetId.HasGuidValue())
            {
                return(tesmStore.GetTermSet(termSetId.Value));
            }

            if (!string.IsNullOrEmpty(termSetName))
            {
                return(tesmStore.GetTermSets(termSetName, termSetLCID).FirstOrDefault());
            }

            return(null);
        }
Exemplo n.º 28
0
        public static NavigationTermSet CriarItemNaTermStore(string url, string urlweb, Guid NavTermSetId, Guid TaggingTermSetId)
        {
            SPSite site = new SPSite(url);

            SPWeb web = site.AllWebs[url];

            TaxonomySession taxonomySession = new TaxonomySession(site);

            if (taxonomySession.TermStores.Count == 0)
            {
                throw new InvalidOperationException("O Serviço de taxonomia não existe");
            }

            TermStore termStore = taxonomySession.TermStores[0];

            TermSet existingTermSet = termStore.GetTermSet(NavTermSetId);

            if (existingTermSet != null)
            {
                existingTermSet.Delete();
                termStore.CommitAll();
            }


            Group             siteCollectionGroup = termStore.GetSiteCollectionGroup(web.Site);
            TermSet           termSet             = siteCollectionGroup.CreateTermSet("Teste01", NavTermSetId);
            NavigationTermSet navTermSet          = NavigationTermSet.GetAsResolvedByWeb(termSet, web,
                                                                                         StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider);

            navTermSet.IsNavigationTermSet = true;

            navTermSet.TargetUrlForChildTerms.Value = "~site/Pages/Topics/Topic.aspx";

            NavigationTerm term1 = navTermSet.CreateTerm("Term 1", NavigationLinkType.SimpleLink);

            term1.SimpleLinkUrl = "https://ekisiot.sharepoint.com/";

            NavigationTerm term2 = navTermSet.CreateTerm("Term 2", NavigationLinkType.FriendlyUrl);

            NavigationTerm term2a = term2.CreateTerm("Term 2 A", NavigationLinkType.FriendlyUrl);

            NavigationTerm term2b = term2.CreateTerm("Term 2 B", NavigationLinkType.FriendlyUrl);

            NavigationTerm term3 = navTermSet.CreateTerm("Term 3", NavigationLinkType.FriendlyUrl);

            termStore.CommitAll();

            return(navTermSet);
        }
Exemplo n.º 29
0
        public static TaxonomyFieldValueCollection GetTaxonomyFieldValues(SPSite site, Guid sspId, Guid termSetId, IEnumerable <string> values, bool addIfDoesNotExist /*, out bool newTermsAdded*/)
        {
            bool            newTermsAdded;
            TaxonomySession taxonomySession = new TaxonomySession(site);
            TermStore       termStore       = taxonomySession.TermStores[sspId];
            TermSet         termSet         = termStore.GetTermSet(termSetId);

            TaxonomyFieldValueCollection val = GetTaxonomyFieldValues(termSet, values, addIfDoesNotExist, out newTermsAdded);

            if (newTermsAdded)
            {
                termStore.CommitAll();
            }

            return(val);
        }
Exemplo n.º 30
0
        private static TermSet AddTermSet(ClientContext clientContext, TermStore termStore, TermGroup termGroup)
        {
            var termSetId = new Guid("56ca0eea-635e-4cc1-ac35-fc2040f4cfe5");
            var termSet = termStore.GetTermSet(termSetId);
            clientContext.Load(termSet, ts => ts.Terms);
            clientContext.ExecuteQuery();

            if (termSet.ServerObjectIsNull.Value)
            {
                termSet = termGroup.CreateTermSet("Taxonomy Navigation", termSetId, 1033);
                termSet.SetCustomProperty("_Sys_Nav_IsNavigationTermSet", "True");
                clientContext.Load(termSet, ts => ts.Terms);
                clientContext.ExecuteQuery();
            }

            return termSet;
        }
Exemplo n.º 31
0
        public static TermSet LookupTermSet(ClientRuntimeContext context, TermStore termStore,
                                            string termSetName, Guid?termSetId, int termSetLCID)
        {
            var storeContext = context;

            if (!string.IsNullOrEmpty(termSetName))
            {
                var termSets = termStore.GetTermSetsByName(termSetName, termSetLCID);

                storeContext.Load(termSets);
                storeContext.ExecuteQueryWithTrace();

                return(termSets.FirstOrDefault());
            }

            if (termSetId.HasGuidValue())
            {
                TermSet termSet = null;

                var scope = new ExceptionHandlingScope(storeContext);
                using (scope.StartScope())
                {
                    using (scope.StartTry())
                    {
                        termSet = termStore.GetTermSet(termSetId.Value);
                        storeContext.Load(termSet);
                    }

                    using (scope.StartCatch())
                    {
                    }
                }

                storeContext.ExecuteQueryWithTrace();

                if (termSet != null && termSet.ServerObjectIsNull == false)
                {
                    storeContext.Load(termSet, g => g.Id);
                    storeContext.ExecuteQueryWithTrace();

                    return(termSet);
                }
            }

            return(null);
        }
Exemplo n.º 32
0
        public static TermSet LookupTermSet(ClientRuntimeContext context, TermStore termStore,
            Site site,
            string termGroupName, Guid? termGroupId, bool? isSiteCollectionGroup,
            string termSetName, Guid? termSetId, int termSetLCID)
        {
            var storeContext = context;

            TermGroup currenGroup = null;

            if (!string.IsNullOrEmpty(termGroupName))
            {
                currenGroup = termStore.Groups.GetByName(termGroupName);

                storeContext.Load(currenGroup);
                storeContext.ExecuteQueryWithTrace();
            }
            else if (termGroupId != null && termGroupId.HasGuidValue())
            {
                currenGroup = termStore.Groups.GetById(termGroupId.Value);

                storeContext.Load(currenGroup);
                storeContext.ExecuteQueryWithTrace();
            }
            else if (isSiteCollectionGroup == true)
            {
                currenGroup = termStore.GetSiteCollectionGroup(site, false);

                storeContext.Load(currenGroup);
                storeContext.ExecuteQueryWithTrace();
            }

            if (!string.IsNullOrEmpty(termSetName))
            {
                if (currenGroup != null && (currenGroup.ServerObjectIsNull == false))
                {
                    TermSet termSet = null;

                    var scope = new ExceptionHandlingScope(storeContext);
                    using (scope.StartScope())
                    {
                        using (scope.StartTry())
                        {
                            termSet = currenGroup.TermSets.GetByName(termSetName);
                            storeContext.Load(termSet);
                        }

                        using (scope.StartCatch())
                        {

                        }
                    }

                    storeContext.ExecuteQueryWithTrace();

                    if (termSet != null && termSet.ServerObjectIsNull == false)
                    {
                        storeContext.Load(termSet, g => g.Id);
                        storeContext.ExecuteQueryWithTrace();

                        return termSet;
                    }
                }
                else
                {
                    var termSets = termStore.GetTermSetsByName(termSetName, termSetLCID);

                    storeContext.Load(termSets);
                    storeContext.ExecuteQueryWithTrace();

                    return termSets.FirstOrDefault();
                }
            }

            if (termSetId.HasGuidValue())
            {
                if (currenGroup != null && (currenGroup.ServerObjectIsNull == false))
                {
                    TermSet termSet = null;

                    var scope = new ExceptionHandlingScope(storeContext);
                    using (scope.StartScope())
                    {
                        using (scope.StartTry())
                        {
                            termSet = currenGroup.TermSets.GetById(termSetId.Value);
                            storeContext.Load(termSet);
                        }

                        using (scope.StartCatch())
                        {

                        }
                    }

                    storeContext.ExecuteQueryWithTrace();

                    if (termSet != null && termSet.ServerObjectIsNull == false)
                    {
                        storeContext.Load(termSet, g => g.Id);
                        storeContext.ExecuteQueryWithTrace();

                        return termSet;
                    }
                }
                else
                {
                    TermSet termSet = null;

                    var scope = new ExceptionHandlingScope(storeContext);
                    using (scope.StartScope())
                    {
                        using (scope.StartTry())
                        {
                            termSet = termStore.GetTermSet(termSetId.Value);
                            storeContext.Load(termSet);
                        }

                        using (scope.StartCatch())
                        {

                        }
                    }

                    storeContext.ExecuteQueryWithTrace();

                    if (termSet != null && termSet.ServerObjectIsNull == false)
                    {
                        storeContext.Load(termSet, g => g.Id);
                        storeContext.ExecuteQueryWithTrace();

                        return termSet;
                    }
                }
            }

            return null;
        }
Exemplo n.º 33
0
        public static TermSet LookupTermSet(
            TermStore tesmStore,
            string termGroupName, Guid? groupId, bool? isSiteCollectionGroup, SPSite site,
            string termSetName, Guid? termSetId, int termSetLCID)
        {
            Group currentGroup = null;

            if (!string.IsNullOrEmpty(termGroupName))
            {
                currentGroup = tesmStore.Groups.FirstOrDefault(g => g.Name.ToUpper() == termGroupName.ToUpper());
            }
            else if (groupId != null && groupId.HasGuidValue())
            {
                currentGroup = tesmStore.GetGroup(groupId.Value);
            }
            else if (isSiteCollectionGroup.HasValue && isSiteCollectionGroup.Value)
            {
                currentGroup = tesmStore.GetSiteCollectionGroup(site);
            }

            if (termSetId.HasGuidValue())
            {
                if (currentGroup != null)
                    return currentGroup.TermSets.FirstOrDefault(t => t.Id == termSetId.Value);

                return tesmStore.GetTermSet(termSetId.Value);
            }

            if (!string.IsNullOrEmpty(termSetName))
            {
                if (currentGroup != null)
                    return currentGroup.TermSets.FirstOrDefault(t => t.Name.ToUpper() == termSetName.ToUpper());

                return tesmStore.GetTermSets(termSetName, termSetLCID).FirstOrDefault();
            }

            return null;
        }
Exemplo n.º 34
0
        public static TermSet LookupTermSet(TermStore tesmStore, string termSetName, Guid? termSetId, int termSetLCID)
        {
            if (termSetId.HasGuidValue())
                return tesmStore.GetTermSet(termSetId.Value);

            if (!string.IsNullOrEmpty(termSetName))
                return tesmStore.GetTermSets(termSetName, termSetLCID).FirstOrDefault();

            return null;
        }
Exemplo n.º 35
0
        public static TermSet LookupTermSet(ClientRuntimeContext context, TermStore termStore,
            string termSetName, Guid? termSetId, int termSetLCID)
        {
            var storeContext = context;

            if (!string.IsNullOrEmpty(termSetName))
            {
                var termSets = termStore.GetTermSetsByName(termSetName, termSetLCID);

                storeContext.Load(termSets);
                storeContext.ExecuteQueryWithTrace();

                return termSets.FirstOrDefault();
            }

            if (termSetId.HasGuidValue())
            {
                TermSet termSet = null;

                var scope = new ExceptionHandlingScope(storeContext);
                using (scope.StartScope())
                {
                    using (scope.StartTry())
                    {
                        termSet = termStore.GetTermSet(termSetId.Value);
                        storeContext.Load(termSet);
                    }

                    using (scope.StartCatch())
                    {

                    }
                }

                storeContext.ExecuteQueryWithTrace();

                if (termSet != null && termSet.ServerObjectIsNull == false)
                {
                    storeContext.Load(termSet, g => g.Id);
                    storeContext.ExecuteQueryWithTrace();

                    return termSet;
                }
            }

            return null;
        }
Exemplo n.º 36
0
        /// <summary>
        /// Exports the full list of terms from all termsets in all termstores.
        /// </summary>
        /// <param name="site">The site to export the termsets from</param>
        /// <param name="termSetId">The ID of the termset to export</param>
        /// <param name="includeId">if true, Ids of the the taxonomy items will be included</param>
        /// <param name="termStore">The term store to export the termset from</param>
        /// <param name="delimiter">if specified, this delimiter will be used. Notice that IDs will be delimited with ;# from the label</param>
        /// <returns></returns>
        public static List<string> ExportTermSet(this Site site, Guid termSetId, bool includeId, TermStore termStore, string delimiter = "|")
        {
            var clientContext = site.Context;
            var termsString = new List<string>();
            TermCollection terms = null;

            if (termSetId != Guid.Empty)
            {
                var termSet = termStore.GetTermSet(termSetId);
                terms = termSet.Terms;
                clientContext.Load(terms, t => t.IncludeWithDefaultProperties(s => s.TermSet), t => t.IncludeWithDefaultProperties(s => s.TermSet.Group));
            }

            clientContext.ExecuteQueryRetry();

            if (terms.Any())
            {
                foreach (var term in terms)
                {
                    var groupName = DenormalizeName(term.TermSet.Group.Name);
                    var termsetName = DenormalizeName(term.TermSet.Name);
                    var termName = DenormalizeName(term.Name);
                    clientContext.ExecuteQueryRetry();
                    var groupPath = string.Format("{0}{1}", groupName, (includeId) ? string.Format(";#{0}", term.TermSet.Group.Id.ToString()) : "");
                    var termsetPath = string.Format("{0}{1}", termsetName, (includeId) ? string.Format(";#{0}", term.TermSet.Id.ToString()) : "");
                    var termPath = string.Format("{0}{1}", termName, (includeId) ? string.Format(";#{0}", term.Id.ToString()) : "");
                    termsString.Add(string.Format("{0}{3}{1}{3}{2}", groupPath, termsetPath, termPath, delimiter));

                    if (term.TermsCount > 0)
                    {
                        var subTermPath = string.Format("{0}{3}{1}{3}{2}", groupPath, termsetPath, termPath, delimiter);

                        termsString.AddRange(ParseSubTerms(subTermPath, term, includeId, delimiter, clientContext));
                    }

                    termsString.Add(string.Format("{0}{3}{1}{3}{2}", groupPath, termsetPath, termPath, delimiter));
                }
            }

            return termsString.Distinct().ToList<string>();
        }