예제 #1
0
        private TermSetItem getTerCollByID(Guid termsetID, string TermstoreName, Guid termgroupId)
        {
            Term retColl = null;

            try
            {
                //TermStore _TermStore = _TaxonomySession.TermStores[TermstoreName];

                Group gp = _TermStore.GetGroup(termgroupId);
                _TermStore.GetTermSets(new[] { "Legislation" });
                foreach (TermSet item in _TermStore.GetTermSets(new[] { "Legislation" })) //gp.TermSets)
                {
                    Term tr = findRecursive(item, termsetID);
                    if (tr != null)
                    {
                        return(tr);
                    }
                    string s = item.Name;
                }
                return(retColl);
            }
            catch (Exception w)
            {
                _isValidState = false;
                log.Error(string.Format("{0}.{1}", MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name), w);
                throw;
            }
        }
예제 #2
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;
            }
        }
예제 #3
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);
        }
예제 #4
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);
        }
        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;
        }
예제 #6
0
        protected void ImportTermSet(IEnumerable <ManagedMetadataEntity> entities, Group termGroup, bool isOpenForTermCreation)
        {
            IEnumerable <ManagedMetadataEntity> termSetEntities = from e in entities
                                                                  where !string.IsNullOrEmpty(e.TermSetName)
                                                                  select e;

            // create term sets
            foreach (ManagedMetadataEntity termSetEntity in termSetEntities)
            {
                if (termSetEntity == null)
                {
                    continue;
                }

                int     lcid    = termSetEntity.LCID.HasValue ? termSetEntity.LCID.Value : 1033;
                TermSet termSet = _termStore.GetTermSets(termSetEntity.TermSetName, lcid).FirstOrDefault();

                if (termSet != null)
                {
                    _termStore.WorkingLanguage = lcid;        //set the working language to the language we want to add
                    termSet.Name = termSetEntity.TermSetName; //Set the language specific name
                }
                else
                {
                    termSet = termGroup.CreateTermSet(termSetEntity.TermSetName, Guid.NewGuid(), lcid);
                }

                termSet.Description           = termSetEntity.TermSetDescription;
                termSet.IsAvailableForTagging = termSetEntity.AvailableForTagging;
                termSet.IsOpenForTermCreation = isOpenForTermCreation;

                var termLevels = new List <IEnumerable <ManagedMetadataEntity> >();

                #region First Level terms Query

                //TODO: add logic to identify parent term set.. and modify spreadsheet appropriately...
                IEnumerable <ManagedMetadataEntity> firstLevelTerms = from e in entities
                                                                      where (!String.IsNullOrEmpty(e.Level1Term) && String.IsNullOrEmpty(e.Level2Term) &&
                                                                             String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) &&
                                                                             String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) &&
                                                                             String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID)
                                                                      select e;

                termLevels.Add(firstLevelTerms);

                #endregion

                //Set custom order to match import
                //termSet.CustomSortOrder = String.Join(":", firstLevelTerms.Select(x => x.Level1Term).ToArray());
                _termStore.CommitAll();

                #region Second Level Terms Query

                var secondLevelTerms = from e in entities
                                       where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) &&
                                              String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) &&
                                              String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) &&
                                              String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID)
                                       select e;

                termLevels.Add(secondLevelTerms);

                #endregion

                #region Third Level Terms Query

                var thirdLevelTerms = from e in entities
                                      where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) &&
                                             !String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) &&
                                             String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) &&
                                             String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID)
                                      select e;

                termLevels.Add(thirdLevelTerms);

                #endregion

                #region Fourth Level Terms Query

                var fourthLevelTerms = from e in entities
                                       where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) &&
                                              !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) &&
                                              String.IsNullOrEmpty(e.Level5Term) && String.IsNullOrEmpty(e.Level6Term) &&
                                              String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID)
                                       select e;

                termLevels.Add(fourthLevelTerms);

                #endregion

                #region Fifth Level Terms Query

                var fifthLevelTerms = from e in entities
                                      where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) &&
                                             !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) &&
                                             !String.IsNullOrEmpty(e.Level5Term) && String.IsNullOrEmpty(e.Level6Term) &&
                                             String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID)
                                      select e;

                termLevels.Add(fifthLevelTerms);

                #endregion

                #region Sixth Level Terms Query

                var sixthLevelTerms = from e in entities
                                      where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) &&
                                             !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) &&
                                             !String.IsNullOrEmpty(e.Level5Term) && !String.IsNullOrEmpty(e.Level6Term) &&
                                             String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID)
                                      select e;

                termLevels.Add(sixthLevelTerms);

                #endregion

                #region Seventh Level Terms Query

                IEnumerable <ManagedMetadataEntity> seventhLevelTerms = from e in entities
                                                                        where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) &&
                                                                               !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) &&
                                                                               !String.IsNullOrEmpty(e.Level5Term) && !String.IsNullOrEmpty(e.Level6Term) &&
                                                                               !String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID)
                                                                        select e;

                termLevels.Add(seventhLevelTerms);

                #endregion

                foreach (ManagedMetadataEntity termEntity in firstLevelTerms)
                {
                    UpdateTerm(termSet, termEntity, termLevels, 1);
                }

                _termStore.CommitAll();
            }
        }
예제 #7
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;
        }