本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}