当前位置: 首页>>代码示例>>C#>>正文


C# DataProvider.DeleteItem方法代码示例

本文整理汇总了C#中DataProvider.DeleteItem方法的典型用法代码示例。如果您正苦于以下问题:C# DataProvider.DeleteItem方法的具体用法?C# DataProvider.DeleteItem怎么用?C# DataProvider.DeleteItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataProvider的用法示例。


在下文中一共展示了DataProvider.DeleteItem方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveDeletedClasses

        /// <summary>
        /// Check a folder and all sub folders in Sitecore for templates
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="provider"></param>
        /// <param name="context"></param>
        /// <returns>True of the folder is deleted itself.</returns>
         private bool RemoveDeletedClasses(ItemDefinition folder, DataProvider provider, CallContext context)
         {
             var childIds = provider.GetChildIDs(folder, context);
             
             //check child items
             foreach (ID childId in childIds.ToArray())
             {
                 var childDefinition = provider.GetItemDefinition(childId, context);

                 //if child is template check the template still exists in the code base
                 if (childDefinition.TemplateID == TemplateTemplateId)
                 {
                     if (Classes.Any(x => x.Value.TemplateId == childDefinition.ID.Guid && x.Value.ClassAttribute.CodeFirst))
                         continue;

                     provider.DeleteItem(childDefinition, context);
                     childIds.Remove(childDefinition.ID);
                 }
                 // if the child is a folder check the children of the folder
                 else if (childDefinition.TemplateID == FolderTemplateId)
                 {
                     //if the folder itself is deleted then remove from the parent
                     if (RemoveDeletedClasses(childDefinition, provider, context))
                     {
                         childIds.Remove(childDefinition.ID);
                     }
                 }
             }

             //if there are no children left delete the folder 
             if (childIds.Count == 0)
             {
                 provider.DeleteItem(folder, context);
                 return true;
             }
             else
             {
                 return false;
             }

             

         }
开发者ID:csteeg,项目名称:Glass.Sitecore.Mapper,代码行数:50,代码来源:GlassDataProvider.cs

示例2: GetChildIDsSection

        /// <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;
        }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:74,代码来源:GlassDataProvider.cs

示例3: RemoveDeletedClasses

        /// <summary>
        /// Check a folder and all sub folders in Sitecore for templates
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="context">The context.</param>
        /// <returns>True of the folder is deleted itself.</returns>
        private bool RemoveDeletedClasses(ItemDefinition folder, DataProvider provider, CallContext context)
        {
            if (folder == null) throw new ArgumentNullException("folder");
            if (provider == null) throw new ArgumentNullException("provider");
            if (context == null) throw new ArgumentNullException("context");

            var childIds = provider.GetChildIDs(folder, context);

            //check child items
            foreach (ID childId in childIds.ToArray())
            {
                var childDefinition = provider.GetItemDefinition(childId, context);

                //if child is template check the template still exists in the code base
                if (childDefinition.TemplateID == TemplateTemplateId)
                {
                    if (_typeConfigurations.Any(x => x.Value.TemplateId == childDefinition.ID && x.Value.CodeFirst))
                        continue;

                    provider.DeleteItem(childDefinition, context);
                    childIds.Remove(childDefinition.ID);
                }
                // if the child is a folder check the children of the folder
                else if (childDefinition.TemplateID == FolderTemplateId)
                {
                    //if the folder itself is deleted then remove from the parent
                    if (RemoveDeletedClasses(childDefinition, provider, context))
                    {
                        childIds.Remove(childDefinition.ID);
                    }
                }
            }

            //if there are no children left delete the folder 
            if (childIds.Count == 0 && folder.ID != GlassFolderId)
            {
                provider.DeleteItem(folder, context);
                return true;
            }
            else
            {
                return false;
            }



        }
开发者ID:bplasmeijer,项目名称:Glass.Mapper,代码行数:54,代码来源:GlassDataProvider.cs

示例4: GetChildIDsSection

        /// <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 cls = TypeConfigurations.First(x => x.Value.TemplateId == section.TemplateId).Value;
            var fields = cls.Properties.OfType<SitecoreFieldConfiguration>();
            var fieldIds = new IDList();

            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 = sqlProvider.GetItemDefinition(field.FieldId, context);
                    if (existing != null)
                    {
                        using (new SecurityDisabler())
                            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;
        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:56,代码来源:GlassDataProvider.cs


注:本文中的DataProvider.DeleteItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。