本文整理汇总了C#中DataProvider.GetItemDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# DataProvider.GetItemDefinition方法的具体用法?C# DataProvider.GetItemDefinition怎么用?C# DataProvider.GetItemDefinition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataProvider
的用法示例。
在下文中一共展示了DataProvider.GetItemDefinition方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: 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;
}
}
示例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: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: GetChildIDsTemplate
/// <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;
}
示例8: 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;
}
示例9: GetChildIDsTemplate
/// <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)).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));
record = exists != null ?
new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder) { Existing = true } :
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;
}
示例10: GetSqlVersion
private ItemDefinition GetSqlVersion(ID itemId, CallContext context, DataProvider sqlProvider)
{
if (sqlProvider == null)
return null;
var sqlVersion = sqlProvider.GetItemDefinition(itemId, context);
return sqlVersion;
}
示例11: 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;
}