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


C# DataProvider.CreateItem方法代码示例

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


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

示例1: GetGlassTemplateFolder

        /// <summary>
        /// Creates the item /sitecore/templates/glasstemplates
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private ItemDefinition GetGlassTemplateFolder(DataProvider provider, CallContext context)
        {
            var templateFolder = provider.GetItemDefinition(TemplateFolderId, context);

            var glassFolder = provider.GetItemDefinition(GlassFolderId, context);

            if (glassFolder == ItemDefinition.Empty || glassFolder == null)
            {
                provider.CreateItem(GlassFolderId, "GlassTemplates", FolderTemplateId, templateFolder, context);
                glassFolder = provider.GetItemDefinition(GlassFolderId, context);
            }

            if (glassFolder == null)
            {
                Sitecore.Diagnostics.Log.Error("Failed to find GlassTemplates folder", this);
                throw new RequiredObjectIsNullException("Failed to find GlassTemplates folder");
            }

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

示例2: CreateTemplateItem

        /// <summary>
        /// Creates the template item.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="config">The config.</param>
        /// <param name="type">The type.</param>
        /// <param name="sqlDataProvider">The SQL data provider.</param>
        /// <param name="containingFolder">The containing folder.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        /// <exception cref="Sitecore.Exceptions.RequiredObjectIsNullException">TemplateItem is null for ID {0}.Formatted(templateDefinition.ID)</exception>
        public ItemDefinition CreateTemplateItem(
            Database db,
            SitecoreTypeConfiguration config, 
            Type type, 
            DataProvider sqlDataProvider, 
            ItemDefinition containingFolder,
            CallContext context)
        {
            //create the template in Sitecore
            string templateName = string.IsNullOrEmpty(config.TemplateName) ? type.Name : config.TemplateName;

            sqlDataProvider.CreateItem(config.TemplateId, templateName, TemplateTemplateId, containingFolder,
                                       context);
            var templateDefinition = sqlDataProvider.GetItemDefinition(config.TemplateId, context);
            ClearCaches(db);

            var templateItem = db.GetItem(templateDefinition.ID);

            if (templateItem == null)
                throw new RequiredObjectIsNullException("TemplateItem is null for ID {0}".Formatted(templateDefinition.ID));

            using (new ItemEditing(templateItem, true))
            {
                templateItem["__Base template"] = "{1930BBEB-7805-471A-A3BE-4858AC7CF696}";
            }

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

示例3: GetTemplateFolder

        /// <summary>
        /// Gets the template folder that the class template should be created in using the classes
        /// namespace. 
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="defaultFolder"></param>
        /// <param name="sqlDataProvider"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public ItemDefinition GetTemplateFolder(string nameSpace, ItemDefinition defaultFolder, DataProvider sqlDataProvider, CallContext context)
        {
            //setup folders
            IEnumerable<string> namespaces = nameSpace.Split('.');
            namespaces = namespaces.SkipWhile(x => x != "Templates").Skip(1);

            ItemDefinition containingFolder = defaultFolder;
            foreach (var ns in namespaces)
            {
                var children = sqlDataProvider.GetChildIDs(containingFolder, context);

                ItemDefinition found = null;
                foreach (ID child in children)
                {
                    if (!ID.IsNullOrEmpty(child))
                    {
                        var childDef = sqlDataProvider.GetItemDefinition(child, context);
                        if (childDef.Name == ns)
                            found = childDef;
                    }
                }

                if (found == null)
                {
                    ID newId = ID.NewID;
                    sqlDataProvider.CreateItem(newId, ns, FolderTemplateId, containingFolder, context);
                    found = sqlDataProvider.GetItemDefinition(newId, context);
                }
                containingFolder = found;
            }

            if (containingFolder == null)
            {
                Sitecore.Diagnostics.Log.Error("Failed to load containing folder {0}".Formatted(nameSpace), this);
                throw new RequiredObjectIsNullException("Failed to load containing folder {0}".Formatted(nameSpace));
            }

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

示例4: EnsureSqlVersion

 private bool EnsureSqlVersion(ItemDefinition itemDefinition, DataProvider sqlProvider, CallContext context)
 {
     var sqlVersion = GetSqlVersion(itemDefinition.ID, context, sqlProvider);
     if (sqlVersion != null)
     {
         return true;
     }
     if (itemDefinition.ID == FolderId ||
         ControllerType.GetAllNamespaces().ContainsKey(itemDefinition.ID.ToGuid())
         || ControllerType.GetAllControllers().ContainsKey(itemDefinition.ID.ToGuid())
         || ControllerAction.GetControllerAction(itemDefinition.ID) != null)
     {
         var parentId = GetParentID(itemDefinition, context) ?? sqlProvider.GetParentID(itemDefinition, context);
         var itemdef = GetItemDefinition(parentId, context) ?? sqlProvider.GetItemDefinition(parentId, context);
         if (!sqlProvider.CreateItem(itemDefinition.ID, itemDefinition.Name, itemDefinition.TemplateID, itemdef, context))
         {
             return false;
         }
         
         var item = Database.GetItem(itemDefinition.ID);
         var existingFields = new ItemChanges(item);
         foreach (Field field in item.Fields)
         {
             existingFields.SetFieldValue(field, item[field.ID]);
         }
         sqlProvider.SaveItem(itemDefinition, existingFields, context);
         return true;
     }
     return false;
 }
开发者ID:wavveen,项目名称:BoC.Sitecore.CodefirstRenderings,代码行数:30,代码来源:CodeFirstRenderingsDataProvider.cs


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