コード例 #1
0
        private IDList GetChildIDsTemplate(SitecoreClassConfig template, ItemDefinition itemDefinition)
        {
            IDList fields = new IDList();

            List <string> processed = new List <string>();
            var           sections  = template.Properties
                                      .Where(x => x.Property.DeclaringType == template.Type)
                                      .Select(x => x.Attribute).OfType <SitecoreFieldAttribute>()
                                      .Select(x => x.SectionName);

            foreach (var section in sections)
            {
                if (processed.Contains(section) || section.IsNullOrEmpty())
                {
                    continue;
                }

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section);

                if (record == null)
                {
                    record = new SectionInfo(section, new ID(Guid.NewGuid()), itemDefinition.ID);
                    SectionTable.Add(record);
                }
                processed.Add(section);
                fields.Add(record.SectionId);
            }
            return(fields);
        }
コード例 #2
0
        /// <summary>
        /// Gets the child I ds template.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="itemDefinition">The item definition.</param>
        /// <param name="context">The context.</param>
        /// <param name="sqlProvider">The SQL provider.</param>
        /// <returns>
        /// IDList.
        /// </returns>
        private IDList GetChildIDsTemplate(SitecoreTypeConfiguration template, ItemDefinition itemDefinition, CallContext context, DataProvider sqlProvider)
        {
            var fields    = new IDList();
            var processed = new List <string>();
            var sections  = template.Properties
                            .Where(x => x.PropertyInfo.DeclaringType == template.Type)
                            .OfType <SitecoreFieldConfiguration>()
                            .Select(x => new { x.SectionName, x.SectionSortOrder });

            //If sitecore contains a section with the same name in the database, use that one instead of creating a new one
            var existing = sqlProvider.GetChildIDs(itemDefinition, context).OfType <ID>().Select(id => sqlProvider.GetItemDefinition(id, context))
                           .Where(item => item.TemplateID == SectionTemplateId).ToList();

            foreach (var section in sections)
            {
                if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty())
                {
                    continue;
                }

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName);

                if (record == null)
                {
                    var       exists       = existing.FirstOrDefault(def => def.Name.Equals(section.SectionName, StringComparison.InvariantCultureIgnoreCase));
                    var       newId        = GetUniqueGuid(itemDefinition.ID + section.SectionName);
                    const int newSortOrder = 100;

                    record = exists != null ?
                             new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder)
                    {
                        Existing = true
                    } :
                    new SectionInfo(section.SectionName, new ID(newId), itemDefinition.ID, newSortOrder);

                    SectionTable.Add(record);
                }

                processed.Add(section.SectionName);

                if (!record.Existing)
                {
                    fields.Add(record.SectionId);
                }
            }

            //we need to add sections already in the db, 'cause we have to
            foreach (var sqlOne in existing.Where(ex => SectionTable.All(s => s.SectionId != ex.ID)))
            {
                SectionTable.Add(new SectionInfo(sqlOne.Name, sqlOne.ID, itemDefinition.ID, 0)
                {
                    Existing = true
                });
            }

            return(fields);
        }
コード例 #3
0
        private IDList GetChildIDsTemplate(SitecoreClassConfig template, ItemDefinition itemDefinition, CallContext context)
        {
            IDList fields = new IDList();

            List <string> processed = new List <string>();
            var           sections  = template.Properties
                                      .Where(x => x.Property.DeclaringType == template.Type)
                                      .Select(x => x.Attribute).OfType <SitecoreFieldAttribute>()
                                      .Select(x => new { x.SectionName, x.SectionSortOrder });

            var providers     = Database.GetDataProviders();
            var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider));
            //If sitecore contains a section with the same name in the database, use that one instead of creating a new one
            var existing = otherProvider.GetChildIDs(itemDefinition, context).OfType <ID>().Select(id => otherProvider.GetItemDefinition(id, context)).ToList();

            foreach (var section in sections)
            {
                if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty())
                {
                    continue;
                }

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName);

                if (record == null)
                {
                    var exists = existing.FirstOrDefault(def => def.Name.Equals(section));
                    if (exists != null)
                    {
                        record = new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder)
                        {
                            Existing = true
                        };
                    }
                    else
                    {
                        record = new SectionInfo(section.SectionName, new ID(Guid.NewGuid()), itemDefinition.ID, section.SectionSortOrder);
                    }
                    SectionTable.Add(record);
                }
                processed.Add(section.SectionName);
                if (!record.Existing)
                {
                    fields.Add(record.SectionId);
                }
            }
            return(fields);
        }