Exemplo n.º 1
0
        /// <summary>
        /// Gets the child I ds section.
        /// </summary>
        /// <param name="section">The section.</param>
        /// <param name="context">The context.</param>
        /// <returns>IDList.</returns>
        private IDList GetChildIDsSection(SectionInfo section, CallContext context)
        {
            var cls = _typeConfigurations.First(x => x.Value.TemplateId == section.TemplateId).Value;

            var fields = cls.Properties.OfType<SitecoreFieldConfiguration>();

            IDList fieldIds = new IDList();

            var providers = context.DataManager.Database.GetDataProviders();
            var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider));

            foreach (var field in fields)
            {
                if (field.PropertyInfo.DeclaringType != cls.Type)
                    continue;



                if (field.CodeFirst && field.SectionName == section.Name && !ID.IsNullOrEmpty(field.FieldId))
                {
                    var record = FieldTable.FirstOrDefault(x => x.FieldId == field.FieldId);
                    //test if the fields exists in the database: if so, we're using codefirst now, so remove it.
                    var existing = otherProvider.GetItemDefinition(field.FieldId, context);
                    if (existing != null)
                    {
                        using (new SecurityDisabler())
                            otherProvider.DeleteItem(existing, context);
                    }
                    if (record == null)
                    {
                        string fieldName = field.FieldName.IsNullOrEmpty() ? field.PropertyInfo.Name : field.FieldName;


                        record = new FieldInfo(field.FieldId, section.SectionId, fieldName, field.FieldType,
                                               field.FieldSource, field.FieldTitle, field.IsShared, field.IsUnversioned,
                                               field.FieldSortOrder, field.ValidationRegularExpression,
                                               field.ValidationErrorText, field.IsRequired);

                        if (field.FieldValueConfigs != null && field.FieldValueConfigs.Any())
                        {
                            foreach (var ffv in field.FieldValueConfigs)
                            {
                                record.FieldFieldValues.Add(ffv.FieldId, ffv.FieldValue);
                            }
                        }

                    }

                    fieldIds.Add(record.FieldId);
                    FieldTable.Add(record);


                }
            }

            return fieldIds;
        }
        /// <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>
        /// <returns>IDList.</returns>
        private IDList GetChildIDsTemplate(SitecoreTypeConfiguration template, ItemDefinition itemDefinition, CallContext context)
        {
            IDList fields = new IDList();

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

            var providers     = context.DataManager.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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the child I ds section.
        /// </summary>
        /// <param name="section">The section.</param>
        /// <param name="context">The context.</param>
        /// <param name="sqlProvider">The SQL provider.</param>
        /// <returns>
        /// IDList.
        /// </returns>
        private IDList GetChildIDsSection(SectionInfo section, CallContext context, DataProvider sqlProvider)
        {
            var config = TypeConfigurations.First(x => x.Value.TemplateId == section.TemplateId);
            var cls    = config.Value;

            var fields = cls.Properties.OfType <SitecoreFieldConfiguration>();

            IDList fieldIds = new IDList();

            var interfaces = cls.Type.GetInterfaces();

            foreach (var field in fields)
            {
                //fix: added check on interfaces, if field resides on interface then skip here
                var propertyFromInterface = interfaces.FirstOrDefault(inter => inter.GetProperty(field.PropertyInfo.Name) != null &&
                                                                      inter.GetProperty(field.PropertyInfo.Name).GetCustomAttributes(typeof(SitecoreFieldAttribute), false).Any());
                if (field.PropertyInfo.DeclaringType != cls.Type || propertyFromInterface != null)
                {
                    continue;
                }

                if (field.CodeFirst && field.SectionName == section.Name && !ID.IsNullOrEmpty(field.FieldId))
                {
                    var record = FieldTable.FirstOrDefault(x => x.FieldId == field.FieldId);
                    //test if the fields exists in the database: if so, we're using codefirst now, so remove it.
                    var existing = sqlProvider.GetItemDefinition(field.FieldId, context);
                    if (existing != null)
                    {
                        using (new SecurityDisabler())
                        {
                            if (DisableItemHandlerWhenDeletingFields)
                            {
                                using (new DisableItemHandler())
                                    sqlProvider.DeleteItem(existing, context);
                            }
                            else
                            {
                                sqlProvider.DeleteItem(existing, context);
                            }
                        }
                    }

                    if (record == null)
                    {
                        string fieldName = field.FieldName.IsNullOrEmpty() ? field.PropertyInfo.Name : field.FieldName;

                        record = new FieldInfo(field.FieldId, section.SectionId, fieldName, field.FieldType, field.CustomFieldType,
                                               field.FieldSource, field.FieldTitle, field.IsShared, field.IsUnversioned,
                                               field.FieldSortOrder, field.ValidationRegularExpression,
                                               field.ValidationErrorText, field.IsRequired);

                        if (field.FieldValueConfigs != null && field.FieldValueConfigs.Any())
                        {
                            foreach (var ffv in field.FieldValueConfigs)
                            {
                                record.FieldFieldValues.Add(ffv.FieldId, ffv.FieldValue);
                            }
                        }
                    }

                    fieldIds.Add(record.FieldId);
                    FieldTable.Add(record);
                }
            }

            return(fieldIds);
        }
Exemplo n.º 4
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>
        /// <returns>IDList.</returns>
        private IDList GetChildIDsTemplate(SitecoreTypeConfiguration template, ItemDefinition itemDefinition, CallContext context)
        {
            IDList fields = new IDList();

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

            var providers = context.DataManager.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;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the child I ds section.
        /// </summary>
        /// <param name="section">The section.</param>
        /// <param name="context">The context.</param>
        /// <param name="sqlProvider">The SQL provider.</param>
        /// <returns>
        /// IDList.
        /// </returns>
        private IDList GetChildIDsSection(SectionInfo section, CallContext context, DataProvider sqlProvider)
        {
            var config = TypeConfigurations.First(x => x.Value.TemplateId == section.TemplateId);
            var cls = config.Value;

            var fields = cls.Properties.OfType<SitecoreFieldConfiguration>();

            IDList fieldIds = new IDList();

            var interfaces = cls.Type.GetInterfaces();

            foreach (var field in fields)
            {
                //fix: added check on interfaces, if field resides on interface then skip here
                var propertyFromInterface = interfaces.FirstOrDefault(inter => inter.GetProperty(field.PropertyInfo.Name) != null 
                                                                            && inter.GetProperty(field.PropertyInfo.Name).GetCustomAttributes(typeof(SitecoreFieldAttribute), false).Any());
                if (field.PropertyInfo.DeclaringType != cls.Type || propertyFromInterface != null)
                    continue;

                if (field.CodeFirst && field.SectionName == section.Name && !ID.IsNullOrEmpty(field.FieldId))
                {
                    var record = FieldTable.FirstOrDefault(x => x.FieldId == field.FieldId);
                    //test if the fields exists in the database: if so, we're using codefirst now, so remove it.
                    var existing = sqlProvider.GetItemDefinition(field.FieldId, context);
                    if (existing != null)
                    {
                        using (new SecurityDisabler())
                        {
                            if (DisableItemHandlerWhenDeletingFields)
                            {
                                using (new DisableItemHandler())
                                    sqlProvider.DeleteItem(existing, context);
                            }
                            else
                            {
                                sqlProvider.DeleteItem(existing, context);
                            }
                        }
                    }

                    if (record == null)
                    {
                        string fieldName = field.FieldName.IsNullOrEmpty() ? field.PropertyInfo.Name : field.FieldName;

                        record = new FieldInfo(field.FieldId, section.SectionId, fieldName, field.FieldType, field.CustomFieldType,
                                               field.FieldSource, field.FieldTitle, field.IsShared, field.IsUnversioned,
                                               field.FieldSortOrder, field.ValidationRegularExpression,
                                               field.ValidationErrorText, field.IsRequired);

                        if (field.FieldValueConfigs != null && field.FieldValueConfigs.Any())
                        {
                            foreach (var ffv in field.FieldValueConfigs)
                            {
                                record.FieldFieldValues.Add(ffv.FieldId, ffv.FieldValue);
                            }
                        }
                    }

                    fieldIds.Add(record.FieldId);
                    FieldTable.Add(record);
                }
            }

            return fieldIds;
        }