Esempio n. 1
0
        private static void RefactorGrupos(SPWeb web, Term term, string guid)
        {
            ResultTable resultTable = RealizarBusqueda(guid);
            int         contador    = 0;
            int         i           = 0;
            List <DocumentoSharePoint> primerOrden = OrdenarResultados(resultTable);

            string[] guidsResoluciones = term.CustomSortOrder.Split(':').Reverse().ToArray();
            Guid     guidResolucion    = new Guid(guidsResoluciones[i]);
            Term     resoulcion        = termSet.GetTerm(guidResolucion);
            int      prefijoGrupo      = 10000;

            foreach (DocumentoSharePoint doc in primerOrden)
            {
                //contador++;
                contador += 100;
                //if (contador % 100 == 0)
                //{
                //prefijoGrupo += 10000;
                //contador = 1;
                i++;
                try
                {
                    guidResolucion = new Guid(guidsResoluciones[i]);
                    resoulcion     = termSet.GetTerm(guidResolucion);
                }
                catch (Exception ex)
                {
                    logProceso.WriteLine("Error obteniendo la nueva resolución: " + ex.Message + "se continuará aplicando en la rama: " + resoulcion.GetPath());
                }
                //}
                Console.WriteLine(doc.Path + " " + contador + "/" + primerOrden.Count);
                SPListItem item = web.GetFile(doc.Path).Item;
                if (item.File.CheckOutType == SPFile.SPCheckOutType.None)
                {
                    TaxonomyField campo = (TaxonomyField)item.Fields.GetField(field);
                    //int orden = prefijoGrupo + contador * 100;
                    //Console.WriteLine(orden);
                    Console.WriteLine(contador);
                    //item[campoOrden] = orden;
                    item[campoOrden] = contador;
                    AplicarTermino(term, resoulcion.GetPath().Split(';').Last(), doc.Path, item, resoulcion, contador);
                }
                else
                {
                    logDesprotegidos.WriteLine("Documento Desprotegido: " + doc.Path);
                }
            }
        }
Esempio n. 2
0
        public TermInstance GetTerm(object termId)
        {
            var guid = GuidInstance.ConvertFromJsObjectToGuid(termId);
            var term = m_termSet.GetTerm(guid);

            return(new TermInstance(Engine.Object.InstancePrototype, term));
        }
Esempio n. 3
0
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            SiteMapNodeCollection siteMapNodes = new SiteMapNodeCollection();
            // cast from .net node to portalnode
            PortalSiteMapNode portalNode = node as PortalSiteMapNode;

            // check it
            if (portalNode == null)
            {
                return(siteMapNodes);
            }
            TaxonomySession taxonomySession = new TaxonomySession(SPContext.Current.Site);
            TermStore       termStore       = taxonomySession.TermStores[0];
            Group           termGroup       = termStore.Groups["BeckyTermGroup"];
            TermSet         termSet         = termGroup.TermSets["BeckyTermSet"];

            // root
            if (node.Key.ToLower() == SPContext.Current.Web.ServerRelativeUrl.ToLower())
            {
                foreach (var term in termSet.Terms)
                {
                    siteMapNodes.Add(SetNavNode(portalNode, term));
                }
            }
            else
            {
                var subTerm = termSet.GetTerm(new Guid(node.Key));
                foreach (var term in subTerm.Terms)
                {
                    siteMapNodes.Add(SetNavNode(portalNode, term));
                }
            }

            return(siteMapNodes);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the term for identifier
        /// </summary>
        /// <param name="site">The Site.</param>
        /// <param name="termStoreGroupName">The Group Name in the term store</param>
        /// <param name="termSetName">The name of the term set containing the term</param>
        /// <param name="id">The GUID of the term to get.</param>
        /// <returns>The term</returns>
        public Term GetTermForIdInTermSet(SPSite site, string termStoreGroupName, string termSetName, Guid id)
        {
            SiteTaxonomyCache taxCache            = this.taxonomyCacheManager.GetSiteTaxonomyCache(site, null, this.taxonomyHelper);
            TermStore         termStore           = this.taxonomyHelper.GetDefaultSiteCollectionTermStore(taxCache.TaxonomySession);
            Group             siteCollectionGroup = GetGroupFromTermStore(termStore, termStoreGroupName);
            TermSet           termSet             = this.GetTermSetFromGroup(termStore, siteCollectionGroup, termSetName);

            return(termSet.GetTerm(id));
        }
Esempio n. 5
0
        public WBRecordsType GetRecordsType(Guid id)
        {
            Term term = TermSet.GetTerm(id);

            if (term == null)
            {
                return(null);
            }
            return(new WBRecordsType(this, term));
        }
Esempio n. 6
0
        public WBTeam GetTeam(Guid id)
        {
            Term term = TermSet.GetTerm(id);

            if (term == null)
            {
                return(null);
            }
            return(new WBTeam(this, term));
        }
Esempio n. 7
0
        protected Term FindTermInTermSet(TermSet termSet, TaxonomyTermDefinition termModel)
        {
            Term result = null;

            if (termModel.Id.HasValue)
            {
                result = termSet.GetTerm(termModel.Id.Value);
            }
            else if (!string.IsNullOrEmpty(termModel.Name))
            {
                result = termSet.GetTerms(termModel.Name, termModel.LCID, false).FirstOrDefault();
            }

            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Gets a collection of <see cref="Term"/> objects referenced by the multiple taxonomy field.
        /// </summary>
        /// <param name="fieldName">Field name.</param>
        /// <param name="termStore">Term store object.</param>
        /// <returns>A collection of terms.</returns>
        protected override IList <Term> GetTaxonomyMultiInternal(string fieldName, TermStore termStore)
        {
            if (this.ListItemAdapater != null)
            {
                return(this.ListItemAdapater.GetTaxonomyMulti(fieldName, termStore));
            }

            string      value = (string)this[fieldName];
            List <Term> terms = new List <Term>();

            if (value != null)
            {
                TermSet     termSet      = null;
                List <Guid> parsedValues = new List <Guid>();
                foreach (string s in value.Split(';'))
                {
                    if (s.StartsWith("GP0|#"))
                    {
                        Guid termId = new Guid(s.Substring(5));
                        parsedValues.Add(termId);
                    }
                    else if (s.StartsWith("GTSet|#"))
                    {
                        if (termSet == null)
                        {
                            Guid termSetId = new Guid(s.Substring(7));
                            termSet = termStore.GetTermSet(termSetId);
                        }
                    }
                }
                if (termSet != null)
                {
                    foreach (Guid termId in parsedValues)
                    {
                        Term term = termSet.GetTerm(termId);
                        if (term != null)
                        {
                            terms.Add(term);
                        }
                    }
                }
            }
            return(terms);
        }
Esempio n. 9
0
        public static bool UpdateTaxonomyFieldValue(SPSite targetSite, TermSet termSet, TaxonomyFieldValue fieldValue, Dictionary <Guid, TaxonomyFieldValue> mappedValues)
        {
            CommonHelper.ConfirmNotNull(targetSite, "targetSite");
            CommonHelper.ConfirmNotNull(termSet, "termSet");
            CommonHelper.ConfirmNotNull(fieldValue, "fieldValue");
            CommonHelper.ConfirmNotNull(mappedValues, "mappedValues");

            Guid originalGuid = new Guid(fieldValue.TermGuid);
            TaxonomyFieldValue newValue;

            if (mappedValues.TryGetValue(originalGuid, out newValue))
            {
                if (newValue != null && newValue.TermGuid != originalGuid.ToString())
                {
                    fieldValue.TermGuid = newValue.TermGuid;
                    fieldValue.WssId    = newValue.WssId;
                    return(true);
                }
                return(false);
            }
            Term originalTerm = termSet.GetTerm(originalGuid);

            if (originalTerm != null)
            {
                mappedValues.Add(originalGuid, null);
                return(false);
            }
            TermCollection matchedTerms = termSet.GetTerms(fieldValue.Label, false);

            if (matchedTerms.Count > 0)
            {
                mappedValues.Add(originalGuid, fieldValue);
                fieldValue.TermGuid = matchedTerms[0].Id.ToString();
                fieldValue.WssId    = matchedTerms[0].EnsureWssId(targetSite, false);
                return(true);
            }
            mappedValues.Add(originalGuid, null);
            return(false);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        private static bool taxFieldChanged(
            Dictionary <string, Guid> indexedTaxonomy,
            TermSet termSet,
            SPListItem item,
            ADuser aduser,
            ref List <Term> terms,
            ref TaxonomyField managedField)
        {
            managedField = item.Fields.GetFieldByInternalName("TaxChalmersDepartment") as TaxonomyField;
            if (aduser.AllUnits != null && aduser.AllUnits.Count > 0)
            {
                terms = aduser.AllUnits.Where(indexedTaxonomy.ContainsKey).Select(s => termSet.GetTerm(indexedTaxonomy[s])).ToList();
                if (terms.Count > 0)
                {
                    LoggingService.WriteTrace(EventSeverity.Information, string.Format("Found {0} matching terms", terms.Count), LogCategory.ChalmersPublicWeb);

                    if (managedField != null)
                    {
                        string fieldTaxItems = item["TaxChalmersDepartment"].ToString();

                        for (int i = 0; i < terms.Count(); i++)
                        {
                            if (fieldTaxItems.Count(f => f == '|') != terms.Count() ||
                                !fieldTaxItems.Contains(terms[i].Name))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            else
            {
                string fieldTaxItems = item["TaxChalmersDepartment"].ToString();
                if (fieldTaxItems.Count(f => f == '|') > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        protected Term FindTermInTermSet(TermSet termSet, TaxonomyTermDefinition termModel)
        {
            Term result = null;

            if (termModel.Id.HasValue)
                result = termSet.GetTerm(termModel.Id.Value);
            else if (!string.IsNullOrEmpty(termModel.Name))
            {
                var termName = NormalizeTermName(termModel.Name);
                result = termSet.GetTerms(termName, termModel.LCID, false).FirstOrDefault();
            }

            return result;
        }
        static DefaultFields UpdateSite(ClientContext ctx, Web web, FieldCollection fields, DefaultFields defaultFields, bool newLibrary)
        {
            // If newLibrary just get default values from web and fill the DefaultFields
            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(ctx);
            TermStore       termStore       = taxonomySession.GetDefaultSiteCollectionTermStore();

            foreach (var df in defaultFields)
            {
                try
                {
                    Field field = fields.GetFieldByInternalName(df.InternalName);
                    if (field != null)
                    {
                        if (!String.IsNullOrEmpty(field.DefaultValue))
                        {
                            string[] guid = field.DefaultValue.Split('|');
                            if (guid.Length > 0)
                            {
                                df.OriginGuid = guid[1];
                                if (newLibrary)
                                {
                                    df.Guid = guid[1];
                                }
                            }
                        }
                        string  termSetGuid = TermSetName.GetTermSetGuidByInternalName(df.InternalName);
                        TermSet termSet     = termStore.GetTermSet(new Guid(termSetGuid));
                        Term    term        = termSet.GetTerm(new Guid(df.Guid));
                        ctx.Load(term);

                        if (newLibrary)
                        {
                            ctx.ExecuteQuery();
                            df.TermItem = term;
                            Log.Info(web.Url, "", df.InternalName, df.Guid);
                        }
                        else
                        {
                            bool          multiValue;
                            TaxonomyField taxField = ctx.CastTo <TaxonomyField>(field);
                            try
                            {
                                multiValue = taxField.AllowMultipleValues;
                            }
                            catch
                            {
                                multiValue = false;
                            }
                            if (multiValue)
                            {
                                string defaultValue = "-1;#" + df.TermLabel + "|" + df.Guid;
                                //TaxonomyFieldValueCollection defaultValue = new TaxonomyFieldValueCollection()
                                //defaultValue.WssId = -1;
                                //defaultValue.Label = df.TermLabel;
                                //defaultValue.TermGuid = df.Guid;

                                //var validatedValue = taxField.GetValidatedString(defaultValue);
                                //ctx.ExecuteQuery();
                                taxField.DefaultValue = defaultValue;

                                taxField.Update();
                                ctx.ExecuteQuery();
                                df.TermItem = term;
                                Log.Info(web.Url, "", df.InternalName, defaultValue);
                            }
                            else
                            {
                                TaxonomyFieldValue defaultValue = new TaxonomyFieldValue();
                                defaultValue.WssId    = -1;
                                defaultValue.Label    = df.TermLabel;
                                defaultValue.TermGuid = df.Guid;

                                var validatedValue = taxField.GetValidatedString(defaultValue);
                                ctx.ExecuteQuery();
                                taxField.DefaultValue = validatedValue.Value;

                                taxField.Update();
                                ctx.ExecuteQuery();
                                df.TermItem = term;
                                Log.Info(web.Url, "", df.InternalName, validatedValue.Value);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(web.Url, "", df.InternalName, ex.Message);
                }
            }

            return(defaultFields);
        }
 public Term FindTerm(TermSet termSet, Guid termGuid)
 {
     termSet.RequireNotNull("termSet");
     return termSet.GetTerm(termGuid);
 }