/// <summary> /// Gets the item definition for the item with the given ID /// </summary> /// <param name="sItemId">Sitecore Item ID</param> /// <param name="sDatabaseName">Sitecore Database from where the item definition will be pulled out</param> /// <param name="iProviderCount">Sitecore CallContext provider count</param> /// <returns>Item's definition</returns> public ItemDefinitionContract GetItemDefinition(string sItemId, string sDatabaseName) { #region VARIABLES ItemDefinition oItemDefinition; ItemDefinitionContract oItemDefinitionContract; Sitecore.Data.ID oItemId; Sitecore.Data.ID oItemParentId; DataProvider oWebDataProvider; CallContext oWebCallContext; //Add variables here #endregion Sitecore.Diagnostics.Log.Info(string.Format("Start GetItemDefinition {0}", sItemId), this); oItemDefinition = null; oItemDefinitionContract = null; if (!string.IsNullOrEmpty(sItemId)) { oItemId = new Sitecore.Data.ID(sItemId); oWebCallContext = BuildCallContext(sDatabaseName); oWebDataProvider = GetDataProvider(sDatabaseName); if (oWebDataProvider != null) { oItemDefinition = oWebDataProvider.GetItemDefinition(oItemId, oWebCallContext); if (oItemDefinition != null) { oItemDefinitionContract = new ItemDefinitionContract() { Id = oItemDefinition.ID.Guid, Name = oItemDefinition.Name, TemplateId = oItemDefinition.TemplateID.ToString(), BranchId = oItemDefinition.BranchId.ToString() }; oItemParentId = oWebDataProvider.GetParentID(oItemDefinition, oWebCallContext); if (!ID.IsNullOrEmpty(oItemParentId)) { oItemDefinitionContract.ParentId = oItemParentId.ToString(); } } } else { Sitecore.Diagnostics.Log.Error("Unable to find data provide", this); } } Sitecore.Diagnostics.Log.Info(string.Format("End GetItemDefinition: ItemDefinition."), this); return(oItemDefinition == null ? null : oItemDefinitionContract); }
/// <summary> /// Gets the item definitions for the item with the given IDs /// </summary> /// <param name="oItemsIds">Sitecore IDs</param> /// <param name="sDatabaseName">Sitecore Database from where the item definition will be pulled out</param> /// <param name="iProviderCount">Sitecore CallContext provider count</param> /// <returns>A List with the Item definitions. It may return null if no definition is found</returns> public List <ItemDefinitionContract> GetItemDefinitions(List <string> oItemsIds, string sDatabaseName) { #region VARIABLES ItemDefinition oItemDefinition; ItemDefinitionContract oItemDefinitionContract; List <ItemDefinitionContract> oItemDefinitions; Sitecore.Data.ID oItemId; Sitecore.Data.ID oItemParentId; DataProvider oWebDataProvider; CallContext oWebCallContext; //Add variables here #endregion Sitecore.Diagnostics.Log.Info("Start GetItemDefinitions", this); oItemDefinitions = null; oItemDefinition = null; oItemDefinitionContract = null; if (oItemsIds != null && oItemsIds.Count > 0) { oWebCallContext = BuildCallContext(sDatabaseName); oWebDataProvider = GetDataProvider(sDatabaseName); if (oWebDataProvider != null) { oItemDefinitions = new List <ItemDefinitionContract>(); foreach (string sItemId in oItemsIds) { oItemId = new Sitecore.Data.ID(sItemId); oItemDefinition = oWebDataProvider.GetItemDefinition(oItemId, oWebCallContext); if (oItemDefinition != null) { oItemDefinitionContract = new ItemDefinitionContract() { Id = oItemDefinition.ID.Guid, Name = oItemDefinition.Name, TemplateId = oItemDefinition.TemplateID.ToString(), BranchId = oItemDefinition.BranchId.ToString() }; oItemParentId = oWebDataProvider.GetParentID(oItemDefinition, oWebCallContext); if (!ID.IsNullOrEmpty(oItemParentId)) { oItemDefinitionContract.ParentId = oItemParentId.ToString(); } oItemDefinitions.Add(oItemDefinitionContract); Sitecore.Diagnostics.Log.Info(string.Format("ItemDefinition for {0} added", sItemId), this); } } } else { Sitecore.Diagnostics.Log.Error("Unable to find data provide", this); } } Sitecore.Diagnostics.Log.Info("End GetItemDefinitions: ItemDefinition.", this); return(oItemDefinitions); }