// GET: Footer public ActionResult Index() { // TODO: should point to the /Home/Resources folder var footerFolder = Sitecore.Context.Database.GetItem("/sitecore/content/Home"); IEnumerable<NavItem> GetNavItems(Item navRoot) { var items = new List<Item> { navRoot }; ID contentItemId = new Sitecore.Data.ID("{77E1B420-FABC-4CA7-BEBF-B0BEA60BB92E}"); items.AddRange(navRoot.Children.Where( item => item.DescendsFrom(contentItemId))); var navItems = items.Skip(1).Select( item => new NavItem { Item = item, Url = LinkManager.GetItemUrl(item), }); return navItems; } var footerLinks = new NavGroup { RootItem = footerFolder, RootUrl = LinkManager.GetItemUrl(footerFolder), NavItems = GetNavItems(footerFolder) }; return View(footerLinks); }
private bool InheritsFromTemplate(TemplateItem templateItem, Sitecore.Data.ID templateId) { return(templateItem.ID == templateId || (templateItem.BaseTemplates != null && templateItem.BaseTemplates .Where(baseTempl => InheritsFromTemplate(baseTempl, templateId)).Count() > 0)); }
private Item GetThisItemFromRight(Sitecore.Data.ID theItemID) { Item itm = null; Item retVal = null; try { Database RightDB = Sitecore.Configuration.Factory.GetDatabase(strRightDB); if (RightDB != null) { itm = RightDB.GetItem(theItemID); } if (itm != null) { Sitecore.Data.Fields.TextField tf = null; if (itm.TemplateName.ToString().ToLower() == "product") { tf = itm.Fields["_NDC"]; } else if (itm.TemplateName.ToString().ToLower() == "productgroup") { tf = itm.Fields["Product Group Name"]; } if ((tf != null) && (!String.IsNullOrWhiteSpace(tf.Value))) { retVal = itm; } } } catch (Exception ex) { } return(retVal); }
public static void ClearSitecoreCacheofItem(string database, Sitecore.Data.ID itemID) { try { Database db = GetDatabase(database); //clear data cache db.Caches.DataCache.RemoveItemInformation(itemID); //clear item cache db.Caches.ItemCache.RemoveItem(itemID); //clear standard values cache db.Caches.StandardValuesCache.RemoveKeysContaining(itemID.ToString()); //remove path cache db.Caches.PathCache.RemoveKeysContaining(itemID.ToString()); Sitecore.Caching.Cache prefetchCache = GetPrefetchCache(db); if (prefetchCache != null) { prefetchCache.RemoveKeysContaining(itemID.ToString()); } } catch { } }
// GET: Navigation public ActionResult Index() { Item homeItem = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath); IEnumerable <NavItem> GetNavItems(Item navRoot) { var items = new List <Item> { navRoot }; ID contentItemId = new Sitecore.Data.ID("{77E1B420-FABC-4CA7-BEBF-B0BEA60BB92E}"); items.AddRange(navRoot.Children.Where(item => item.DescendsFrom(contentItemId))); var navItems = items.Select(item => new NavItem { Item = item, Url = LinkManager.GetItemUrl(item), }); return(navItems); } var navLinks = new NavGroup { RootItem = homeItem, RootUrl = LinkManager.GetItemUrl(homeItem), NavItems = GetNavItems(homeItem) }; return(View(navLinks)); }
/// <summary> /// Sets the properties. /// /// </summary> private void SetProperties() { var @string = StringUtil.GetString(new string[1] { Source }); if (ScID.IsID(@string)) { DataSource = Source; } else if (Source != null && [email protected]().StartsWith("/", StringComparison.OrdinalIgnoreCase)) { ExcludeTemplatesForSelection = StringUtil.ExtractParameter("ExcludeTemplatesForSelection", Source).Trim(); IncludeTemplatesForSelection = StringUtil.ExtractParameter("IncludeTemplatesForSelection", Source).Trim(); IncludeTemplatesForDisplay = StringUtil.ExtractParameter("IncludeTemplatesForDisplay", Source).Trim(); ExcludeTemplatesForDisplay = StringUtil.ExtractParameter("ExcludeTemplatesForDisplay", Source).Trim(); ExcludeItemsForDisplay = StringUtil.ExtractParameter("ExcludeItemsForDisplay", Source).Trim(); IncludeItemsForDisplay = StringUtil.ExtractParameter("IncludeItemsForDisplay", Source).Trim(); AllowMultipleSelection = string.Compare(StringUtil.ExtractParameter("AllowMultipleSelection", Source).Trim().ToLowerInvariant(), "yes", StringComparison.InvariantCultureIgnoreCase) == 0; DataSource = StringUtil.ExtractParameter("DataSource", Source).Trim().ToLowerInvariant(); DatabaseName = StringUtil.ExtractParameter("databasename", Source).Trim().ToLowerInvariant(); } else { DataSource = Source; } }
protected void rptDailyDetails_ItemDataBound(object sender, RepeaterItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { DataRowView dr = (DataRowView)e.Item.DataItem; Sitecore.Data.ID itmID = (Sitecore.Data.ID.Parse(dr[1].ToString())); if (itmID != Sitecore.Data.ID.Null) { Sitecore.Data.Items.Item itm = webDB.GetItem(itmID); if (itm != null) { Label lblName = (Label)e.Item.FindControl("lblProductName"); if (lblName != null) { Item product = GetProductGroup(itm); if (product == null) { product = GetProductCategory(itm); } if (product != null) { lblName.Text = product.Fields["Product Group Name"].Value.ToString(); } } HtmlInputCheckBox cbItm = (HtmlInputCheckBox)e.Item.FindControl("cbItmID"); if (cbItm != null) { cbItm.Attributes.Add("onclick", String.Format("trackItemsToApprove('{0}', this);", itm.ID.ToString())); } } } } }
/// <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); }
public MultiSiteContext(Guid id) { var db = Sitecore.Context.Database ?? Sitecore.Data.Database.GetDatabase("master"); var dataId = new Sitecore.Data.ID(id); var item = db.GetItem(dataId); ProccessItem(item); }
protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { DataRowView dr = (DataRowView)e.Item.DataItem; Sitecore.Data.ID itmID = (Sitecore.Data.ID.Parse(dr["ProductCategoryItemID"].ToString())); if (itmID != Sitecore.Data.ID.Null) { Sitecore.Data.Items.Item itm = webDB.GetItem(itmID); if (itm != null) { Sitecore.Data.Fields.TextField catField = itm.Fields["Category"]; if ((catField != null) && (!String.IsNullOrWhiteSpace(catField.Value.ToString()))) { String category = catField.Value.ToString(); HtmlGenericControl lblName = (HtmlGenericControl)e.Item.FindControl("lblCategory"); if (lblName != null) { lblName.InnerHtml = itm.Fields["Category"].Value.ToString(); } HtmlAnchor anchr = (HtmlAnchor)e.Item.FindControl("CatAnch"); if (anchr != null) { anchr.Attributes.Add("href", String.Format("#{0}", category.ToLower().Replace(" ", ""))); } } } } DataView dv = dt.DefaultView; dv.RowFilter = String.Format("ProductCategoryItemID = '{0}'", itmID.ToString()); String[] ColumnsToFilter = { "ProductCategoryItemID", "ProductGroupItemID", "ItemID" }; DataTable distinctGroups = dv.ToTable(true, ColumnsToFilter); Repeater Groups = (Repeater)e.Item.FindControl("rptGroups"); if (Groups != null) { DataTable dtNew = distinctGroups; distinctGroups.Columns.Add("AttrWarnings"); foreach (DataRow drNew in dtNew.Rows) { ID ndcItemID = Sitecore.Data.ID.Parse(drNew["ItemID"]); if (ndcItemID != Sitecore.Data.ID.Null) { Item NDC = webDB.GetItem(ndcItemID); if (NDC != null) { drNew["AttrWarnings"] += NDC.Fields["_xAttrWarnings"].Value.ToString(); } } } Groups.DataSource = dtNew; Groups.DataBind(); } } }
/// <summary> /// Determines whether the specified item has a valid layout. This separates a viewable content item from, /// say, a folder /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool HasLayout(Sitecore.Data.Items.Item item) { if (null != item && null != item.Visualization) { Sitecore.Data.ID layoutId = item.Visualization.GetLayoutID(Sitecore.Context.Device); return(Guid.Empty != layoutId.Guid); } return(false); }
/// <summary> ///Use this method when getting the item for a specific GUID. Will use the current context database (web). /// </summary> /// <param name="id">string</param> /// <returns>Item</returns> public static Item GetItemFromGUID(string guid) { Item item = null; if (!string.IsNullOrEmpty(guid)) { Sitecore.Data.ID ItemID = ID.Parse(guid); item = Sitecore.Context.Database.GetItem(ItemID); } return(item); }
private void ParseXmlConfiguration(XmlDocument fallbackXml, Dictionary <ID, Setting> settings) { // complex structure... // TODO: Create a nice Sitecore field editing interface for this /// <fallback> /// <setting target="{id}" source="{id}|{id}|{id}..." enableEllipsis="true|false" clipAt="{number chars}" /> /// <setting target="{id}" source="{id}|{id}|{id}..." enableEllipsis="true|false" clipAt="{number chars}" /> /// ... /// </fallback> foreach (XmlNode child in fallbackXml.FirstChild.ChildNodes) { XmlAttribute target = child.Attributes["target"]; XmlAttribute source = child.Attributes["source"]; XmlAttribute enableEllipsis = child.Attributes["enableEllipsis"]; XmlAttribute clipAt = child.Attributes["clipAt"]; /// TODO: Guard against improper input.. move to factory Setting setting = new Setting(); if (enableEllipsis != null) { setting.UseEllipsis = bool.Parse(enableEllipsis.Value); } if (clipAt != null) { int i; if (int.TryParse(clipAt.Value, out i) && i > 0) { setting.ClipAt = i; } } List <Field> fallbackFields = new List <Field>(); List <string> fallbackFieldNames = source.Value.Split(new char[] { '|', ',', ';' }, System.StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (string fallbackFieldName in fallbackFieldNames) { Field f = InnerItem.Fields[fallbackFieldName]; if (f != null) { fallbackFields.Add(f); } } setting.SourceFields = fallbackFields; ID targetID = new Sitecore.Data.ID(target.Value); settings.Add(targetID, setting); } }
public DictionarySiteSettings(Guid id) { Sitecore.Diagnostics.Log.Info("DictionarySiteSettings: Guid:" + id, this); var db = Sitecore.Context.Database ?? Sitecore.Data.Database.GetDatabase("master"); Sitecore.Diagnostics.Log.Info("Current DB Context:" + db.Name, this); var dataId = new Sitecore.Data.ID(id); var item = db.GetItem(dataId); Load(item); }
public void Process(WorkflowPipelineArgs args) { CreateFromMasterActionItem action = args.ProcessorItem.InnerItem; if (action.TargetMaster != string.Empty && action.TargetName != string.Empty) { Item parent = null; if (action.TargetParent != string.Empty) { parent = Sitecore.Context.ContentDatabase.Items[action.TargetParent]; } if (parent == null) { parent = args.DataItem; } Sitecore.Data.ID id = Sitecore.Data.ID.Parse(action.TargetMaster); BranchItem branch = args.DataItem.Database.GetItem(id); Item target = parent.Add(this.GetTargetName(action.TargetName, parent), branch); if (target != null) { if (action.TargetWorkflow != string.Empty) { using (new SecurityDisabler()) { using (new EditContext(target)) { target[FieldIDs.Workflow] = action.TargetWorkflow; } } } if (action.TargetState != string.Empty) { using (new SecurityDisabler()) { using (new EditContext(target)) { target[FieldIDs.State] = action.TargetState; } } } } } }
/// <summary> /// This method used to resolve the item in sitecore using index based on the item name /// </summary> /// <param name="args"></param> public override void Process(HttpRequestArgs args) { if (Context.Item != null || Context.Database == null || args.Url.ItemPath.Length == 0) { return; } //http://domainname/en/chicken/ var requestUrl = args.Url.ItemPath.TrimEnd('/'); //http://domainname/en/chicken var index = requestUrl.LastIndexOf('/'); //Gets the item name "chicken" var itemName = requestUrl.Substring(index + 1); using (var searchContext = ContentSearchManager.GetIndex("sitecore_web_index").CreateSearchContext()) { //Find the item from the index using name and template id ID itemTemplateID = new Sitecore.Data.ID(new Guid("{AAECA0F0-87E7-42F1-9278-24C2C9250A06}")); var result = searchContext.GetQueryable <SearchResultItem>(). Where( x => x.TemplateId == itemTemplateID && x.Name == itemName ).FirstOrDefault(); if (result != null) { var item = result.GetItem(); if (item.Language == Context.Language) { Context.Item = result.GetItem(); } } else { var langItem = Sitecore.Context.Database.GetItem(result.ItemId, Context.Language); if (langItem != null) { Context.Item = langItem; } } } }
/// <summary> /// Executes the specified formid. /// </summary> /// <param name="formid">The formid.</param> /// <param name="fields">The fields.</param> /// <param name="data">The data.</param> public void Execute(Sitecore.Data.ID formid, Sitecore.Form.Core.Client.Data.Submit.AdaptedResultList fields, params object[] data) { var master = Sitecore.Configuration.Factory.GetDatabase("master"); var producttwo = master.GetItem(new ID("{2D9304C0-9CA7-484A-BD45-4AB664AFAFE3}")); using (new SecurityDisabler()) { producttwo.Editing.BeginEdit(); producttwo.Fields["Price"].Value = "$20.00"; producttwo.Editing.EndEdit(); } var web = new[] { Sitecore.Configuration.Factory.GetDatabase("web") }; var english = new[] { Language.Current }; PublishManager.PublishItem(producttwo, web, english, false, false); }
public static NimbleSearch.Foundation.Api.Models.API.SearchResult Map(ISearchResults searchResult, SearchParameters parameters, SearchConfigurations configurations, Guid selectedTabId, int currentPage, bool isAutoComplete) { NimbleSearch.Foundation.Api.Models.API.SearchResult apiSearchResult = new Models.API.SearchResult(); Sitecore.Data.ID tabId = ID.Parse(selectedTabId); var defaultTab = configurations.Tabs.Where(i => i.TabID == tabId).FirstOrDefault(); if (defaultTab == null) { return(apiSearchResult); } apiSearchResult.TotalNumberOfResults = searchResult.TotalNumberOfResults; if (parameters.PageSize == 0) { parameters.PageSize = defaultTab.PageSize; } apiSearchResult.TotalPages = (int)Math.Ceiling((double)searchResult.TotalNumberOfResults / parameters.PageSize); apiSearchResult.CurrentPageIndex = currentPage; apiSearchResult.PageSize = parameters.PageSize; apiSearchResult.DocumentStartIndex = (apiSearchResult.PageSize * (apiSearchResult.CurrentPageIndex + 1)) - apiSearchResult.PageSize + 1; apiSearchResult.DocumentEndIndex = (apiSearchResult.PageSize * (apiSearchResult.CurrentPageIndex + 1)); if (apiSearchResult.DocumentEndIndex > apiSearchResult.TotalNumberOfResults) { apiSearchResult.DocumentEndIndex = apiSearchResult.TotalNumberOfResults; } apiSearchResult.SortOptions = !isAutoComplete?BuildSortOptions(defaultTab) : new List <Models.API.SortOption>(); apiSearchResult.Facets = !isAutoComplete?BuildFacets(searchResult, defaultTab) : new List <FacetResult>(); apiSearchResult.Tabs = BuildTabs(configurations, searchResult, tabId); apiSearchResult.NoResultsMessage = defaultTab.NoResultsMessage; apiSearchResult.MoveToNextTabWhenNoResults = defaultTab.MoveToNextTabWhenEmpty; apiSearchResult.NextTab = defaultTab.NextTab; apiSearchResult.Items = BuildItemResult(searchResult, defaultTab); apiSearchResult.DefaultSortOption = !isAutoComplete && defaultTab.DefaultSortOption != null ? (apiSearchResult.SortOptions.Where(x => x.Value == defaultTab.DefaultSortOption.FieldName).FirstOrDefault()) : null; apiSearchResult.Duration = searchResult.Duration; return(apiSearchResult); }
public IHttpActionResult SaveItem(SavedDocumentSaveRequest request) { Sitecore.Data.ID itemID = ID.Null; if (!Sitecore.Data.ID.TryParse(request.DocumentID, out itemID)) { return(Ok(new { success = false, message = BadIDKey })); } var page = SitecoreContext.GetItem <I___BasePage>(itemID.Guid); var article = SitecoreContext.GetItem <IArticle>(itemID.Guid); var publicationName = ArticleService.GetArticlePublicationName(article); var result = SaveDocumentContext.Save(page.Title, publicationName, request.DocumentID); return(Ok(new { success = result.Success, message = result.Message })); }
public ActionResult Index(sc80basicsitecoremvc.Models.CommentForm commentsForm) { using (new SecurityDisabler()) { Database master = Sitecore.Configuration.Factory.GetDatabase("master"); master.GetItem("/sitecore/content/home"); Item item = Sitecore.Context.Database.GetItem(new ID("{C9E3730D-E1C6-466F-9524-DA44861A45CB}")); ID sitecoreID = new Sitecore.Data.ID(item.ID.ToString()); TemplateID templateID = new TemplateID(sitecoreID); string name = ItemUtil.ProposeValidItemName(Sitecore.DateUtil.IsoNow); Item newComment = Sitecore.Context.Item.Add(name, templateID); newComment.Editing.BeginEdit(); newComment.Fields["Comment Author"].Value = commentsForm.CommentsAuthor.ToString(); newComment.Fields["Comment Text"].Value = commentsForm.CommentsText.ToString(); LinkField website = newComment.Fields["Comment Author Website"]; website.Url = commentsForm.CommentsAuthorWebsite.ToString(); website.Text = commentsForm.CommentsAuthorWebsite.ToString(); website.Target = "_blank"; website.LinkType = "external"; newComment.Editing.EndEdit(); } return(View()); }
public ActionResult Index(sc80basicsitecoremvc.Models.CommentForm commentsForm) { using (new SecurityDisabler()) { Database master = Sitecore.Configuration.Factory.GetDatabase("master"); master.GetItem("/sitecore/content/home"); Item item = Sitecore.Context.Database.GetItem(new ID("{C9E3730D-E1C6-466F-9524-DA44861A45CB}")); ID sitecoreID = new Sitecore.Data.ID(item.ID.ToString()); TemplateID templateID = new TemplateID(sitecoreID); string name = ItemUtil.ProposeValidItemName(Sitecore.DateUtil.IsoNow); Item newComment = Sitecore.Context.Item.Add(name, templateID); newComment.Editing.BeginEdit(); newComment.Fields["Comment Author"].Value = commentsForm.CommentsAuthor.ToString(); newComment.Fields["Comment Text"].Value = commentsForm.CommentsText.ToString(); LinkField website = newComment.Fields["Comment Author Website"]; website.Url = commentsForm.CommentsAuthorWebsite.ToString(); website.Text = commentsForm.CommentsAuthorWebsite.ToString(); website.Target = "_blank"; website.LinkType = "external"; newComment.Editing.EndEdit(); } return View(); }
/// <summary> /// Replacing (.ashx) extension for media library items inside RTE with the original extensions /// </summary> public void ChangeMediaExtenstions() { // Get the master database Database master = Sitecore.Data.Database.GetDatabase("master"); //Get Media Library item by ID Item mediaLibraryItem = master.GetItem("{9E857E70-2F5D-4B68-A60C-C03135ACE0AC}"); //Get the root item Item rootItem = master.GetItem(Sitecore.ItemIDs.ContentRoot); //List of all media IDs inside RTE List <string> lstMediaIDs; Sitecore.Data.ID sitecoreMediaID; Guid guidID; Item mediaItem; //Field Name for Media library items string strExtFieldName = "Extension"; //Temp variable for storing the item Name/ID with it's original value string strNewValue = string.Empty; //Loop on all items under the root item foreach (Item item in rootItem.Axes.GetDescendants()) { //Loop on all fields for each item foreach (Sitecore.Data.Fields.Field field in item.Fields) { //Check if this field is RTE (rich text editor) if (FieldTypeManager.GetField(field) is HtmlField && !field.Name.StartsWith("__")) { //check if the RTE contains andy media library item with '.ashx' extension if (field.Value.ToLower().Contains(".ashx")) { //Get all IDs for all media items with '.ashx' extension lstMediaIDs = GetAllMediaIDs(field.Value); //Change the extension for every media item foreach (string mediaName in lstMediaIDs) { //Check if Media item is referenced by Sitecore ID (Guid) if (Guid.TryParse(mediaName, out guidID)) { sitecoreMediaID = new Sitecore.Data.ID(guidID); //Get the original item of this item from Media Libarary by 'ID' mediaItem = mediaLibraryItem.Axes.GetDescendants().Where(x => x.ID == sitecoreMediaID).FirstOrDefault(); } //If the Media item is referenced by Name else { //Get the original item of this item from Media Libarary by 'Name' mediaItem = mediaLibraryItem.Axes.GetDescendants().Where(x => x.Name == mediaName).FirstOrDefault(); } if (mediaItem != null && mediaItem.Fields[strExtFieldName] != null && !string.IsNullOrEmpty(mediaItem.Fields[strExtFieldName].Value)) { //Get the original extension for the media item strNewValue = mediaName + "." + mediaItem.Fields[strExtFieldName].Value; using (new Sitecore.SecurityModel.SecurityDisabler()) { item.Editing.BeginEdit(); try { /* * Replacing the old value of media library item with a new value with the original extension * For example: * Old value :/9E857E70-2F5D-4B68-A60C-C03135ACE0AC.ashx * New value :/9E857E70-2F5D-4B68-A60C-C03135ACE0AC.jpg */ field.Value = field.Value.Replace(mediaName + ".ashx", strNewValue); item.Editing.EndEdit(); } catch (System.Exception ex) { Sitecore.Diagnostics.Log.Error("Could not update item " + item.Paths.FullPath + ": " + ex.Message, this); item.Editing.CancelEdit(); } } } } } } } //Publishing item to 'web' database PublishItem(item); } }
/// <summary> /// Retireves the information for all the versions of the given item /// </summary> /// <param name="sItemId">Sitecore Item ID</param> /// <param name="sDatabaseName">Sitecore Database To Use</param> /// <param name="iProviderCount">Sitecore CallContext ProviderCount</param> /// <returns>List of Versions</returns> public List <VersionUriContract> GetItemVersions(string sItemId, string sDatabaseName) { #region VARIABLES ItemDefinition oItemDefinition; List <VersionUriContract> oListOfItemVersionsToReturn; Sitecore.Data.ID oItemId; DataProvider oWebDataProvider; CallContext oWebCallContext; VersionUriList oVersions; VersionUriContract oVersionUriContract; VersionContract oVersionContract; LanguageContract oLanguageContract; //Add variables here #endregion Sitecore.Diagnostics.Log.Info(string.Format("GetItemVersions Begin {0}", sItemId), this); oListOfItemVersionsToReturn = new List <VersionUriContract>(); if (!string.IsNullOrEmpty(sItemId)) { oItemId = new Sitecore.Data.ID(sItemId); oWebCallContext = BuildCallContext(sDatabaseName); oWebDataProvider = GetDataProvider(sDatabaseName); if (oWebDataProvider != null && oWebCallContext != null) { oItemDefinition = oWebDataProvider.GetItemDefinition(oItemId, oWebCallContext); if (oItemDefinition != null) { oVersions = oWebDataProvider.GetItemVersions(oItemDefinition, oWebCallContext); if (oVersions != null) { int numberOfVersions = oVersions.Count; for (int versionIndex = 0; versionIndex < numberOfVersions; versionIndex++) { if (oVersions[versionIndex] != null && oVersions[versionIndex].Language != null && oVersions[versionIndex].Version != null) { oLanguageContract = new LanguageContract() { Name = oVersions[versionIndex].Language.Name }; oVersionContract = new VersionContract() { Number = oVersions[versionIndex].Version.Number }; oVersionUriContract = new VersionUriContract() { Version = oVersionContract, Language = oLanguageContract }; oListOfItemVersionsToReturn.Add(oVersionUriContract); } } } } else { Sitecore.Diagnostics.Log.Error(string.Format("Unable to get ItemDefinition for item:{0}", sItemId), this); } } else { if (oWebDataProvider == null) { Sitecore.Diagnostics.Log.Error("Unable to find data provide", this); } if (oWebCallContext == null) { Sitecore.Diagnostics.Log.Error(string.Format("Unable to get CallContext using database:{0} ", sDatabaseName), this); } } } Sitecore.Diagnostics.Log.Info(string.Format("GetItemVersions End, Versions:{0}", oListOfItemVersionsToReturn), this); return(oListOfItemVersionsToReturn); }
public static void ShowItemBrowser(string header, string text, string icon, string button, Sitecore.Data.ID root, Sitecore.Data.ID selected) { ShowItemBrowser( header, text, icon, button, root, selected, Sitecore.Context.ContentDatabase.Name); }
public static void ShowItemBrowser(string header, string text, string icon, string button, Sitecore.Data.ID root, Sitecore.Data.ID selected, string database) { ShowItemBrowser( header, text, icon, button, root.ToString(), selected.ToString(), database); }
protected SCItems.Item GetItem(SCData.ID itemId) { return(this._database.GetItem(itemId)); }
public GlassItemDefinition(Sitecore.Data.ID itemId, string itemName, Sitecore.Data.ID templateId, Sitecore.Data.ID branchId) : base(itemId, itemName, templateId, branchId) { }
/// <summary> /// Gets the IDs for the children of the given item /// </summary> /// <param name="sItemId">Sitecore Item ID</param> /// <param name="sDatabaseName">Sitecore Database to be used by the data provider</param> /// <param name="iProviderCount">Sitecore provider count for the call context</param> /// <returns>List of IDs serialized</returns> public List <Guid> GetChildIDs(string sItemId, string sDatabaseName) { #region VARIABLES ItemDefinition oItemDefinition; List <Guid> oChildIdsList; Sitecore.Data.ID oItemId; DataProvider oWebDataProvider; CallContext oWebCallContext; IDList oChildList; //Add variables here... #endregion Sitecore.Diagnostics.Log.Info(string.Format("GetChildIDs Start {0}", sItemId), this); oChildIdsList = new List <Guid>(); if (!string.IsNullOrEmpty(sItemId)) { oItemId = new Sitecore.Data.ID(sItemId); oWebCallContext = BuildCallContext(sDatabaseName); oWebDataProvider = GetDataProvider(sDatabaseName); if (oWebDataProvider != null && oWebCallContext != null) { oItemDefinition = oWebDataProvider.GetItemDefinition(oItemId, oWebCallContext); if (oItemDefinition != null) { oChildList = oWebDataProvider.GetChildIDs(oItemDefinition, oWebCallContext); if (oChildList != null) { foreach (var child in oChildList) { oChildIdsList.Add(((ID)child).Guid); } } } else { Sitecore.Diagnostics.Log.Error(string.Format("Unable to get ItemDefinition for item:{0}", sItemId), this); } } else { if (oWebDataProvider == null) { Sitecore.Diagnostics.Log.Error("Unable to find data provider", this); } if (oWebCallContext == null) { Sitecore.Diagnostics.Log.Error(string.Format("Unable to get CallContext using database:{0}", sDatabaseName), this); } } } Sitecore.Diagnostics.Log.Info(string.Format("GetChildIDs End, ChildCount:{0}", oChildIdsList.Count), this); return(oChildIdsList); }
public FieldAttribute(Sitecore.Data.ID id) : base(id) { }
/// <summary> /// Gets the IDs for the children of the given item /// </summary> /// <param name="sItemId">Sitecore Item ID</param> /// <param name="sDatabaseName">Sitecore Database to be used by the data provider</param> /// <param name="iProviderCount">Sitecore provider count for the call context</param> /// <returns>List of IDs serialized</returns> public Dictionary <Guid, List <Guid> > GetItemsChildIDs(List <string> oItemIds, string sDatabaseName) { #region VARIABLES ItemDefinition oItemDefinition; List <Guid> oChildIdsList; Sitecore.Data.ID oItemId; DataProvider oWebDataProvider; CallContext oWebCallContext; IDList oChildList; Dictionary <Guid, List <Guid> > oItemsWithChilds; //Add variables here... #endregion oItemsWithChilds = new Dictionary <Guid, List <Guid> >(); if (oItemIds != null) { Sitecore.Diagnostics.Log.Info(string.Format("GetChildIDs Start For {0} item(s)", oItemIds.Count), this); oWebCallContext = BuildCallContext(sDatabaseName); oWebDataProvider = GetDataProvider(sDatabaseName); if (oWebDataProvider != null && oWebCallContext != null) { foreach (string sItemId in oItemIds) { oItemId = new Sitecore.Data.ID(sItemId); if (oItemsWithChilds.ContainsKey(oItemId.Guid)) { continue; } oItemDefinition = oWebDataProvider.GetItemDefinition(oItemId, oWebCallContext); if (oItemDefinition != null) { oChildList = oWebDataProvider.GetChildIDs(oItemDefinition, oWebCallContext); if (oChildList != null) { oChildIdsList = new List <Guid>(); foreach (var child in oChildList) { oChildIdsList.Add(((ID)child).Guid); } oItemsWithChilds.Add(oItemDefinition.ID.Guid, oChildIdsList); } } else { Sitecore.Diagnostics.Log.Error(string.Format("Unable to get ItemDefinition for item:{0}", sItemId), this); } } } else { if (oWebDataProvider == null) { Sitecore.Diagnostics.Log.Error("Unable to find data provider", this); } if (oWebCallContext == null) { Sitecore.Diagnostics.Log.Error(string.Format("Unable to get CallContext using database:{0}", sDatabaseName), this); } } } Sitecore.Diagnostics.Log.Info(string.Format("GetChildIDs End, ChildCount:{0}", oItemsWithChilds.Count), this); return(oItemsWithChilds); }
private void ParseXmlConfiguration(XmlDocument fallbackXml, Dictionary<ID, Setting> settings) { // complex structure... // TODO: Create a nice Sitecore field editing interface for this /// <fallback> /// <setting target="{id}" source="{id}|{id}|{id}..." enableEllipsis="true|false" clipAt="{number chars}" /> /// <setting target="{id}" source="{id}|{id}|{id}..." enableEllipsis="true|false" clipAt="{number chars}" /> /// ... /// </fallback> foreach (XmlNode child in fallbackXml.FirstChild.ChildNodes) { XmlAttribute target = child.Attributes["target"]; XmlAttribute source = child.Attributes["source"]; XmlAttribute enableEllipsis = child.Attributes["enableEllipsis"]; XmlAttribute clipAt = child.Attributes["clipAt"]; /// TODO: Guard against improper input.. move to factory Setting setting = new Setting(); if (enableEllipsis != null) { setting.UseEllipsis = bool.Parse(enableEllipsis.Value); } if (clipAt != null) { int i; if (int.TryParse(clipAt.Value, out i) && i > 0) { setting.ClipAt = i; } } List<Field> fallbackFields = new List<Field>(); List<string> fallbackFieldNames = source.Value.Split(new char[] { '|', ',', ';' }, System.StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (string fallbackFieldName in fallbackFieldNames) { Field f = InnerItem.Fields[fallbackFieldName]; if (f != null) { fallbackFields.Add(f); } } setting.SourceFields = fallbackFields; ID targetID = new Sitecore.Data.ID(target.Value); settings.Add(targetID, setting); } }
/// <summary> /// Gets the Sitecore ID associated to the parent of the given item /// </summary> /// <param name="sItemId">Sitecore Item ID</param> /// <param name="sDatabaseName">Sitecore Database to be used by the data provider</param> /// <param name="iProviderCount">Sitecore provider count for the call context</param> /// <returns>Sitecore ID serialized</returns> public Guid GetParentID(string sItemId, string sDatabaseName) { #region VARIABLES ItemDefinition oItemDefinition; Sitecore.Data.ID oItemId; DataProvider oWebDataProvider; CallContext oWebCallContext; Sitecore.Data.ID oParentID; Guid oParentGuid; //Add variables here... #endregion Sitecore.Diagnostics.Log.Info(string.Format("GetParentID Start {0}", sItemId), this); oParentID = ID.Null; oParentGuid = Guid.Empty; if (!string.IsNullOrEmpty(sItemId)) { oItemId = new Sitecore.Data.ID(sItemId); oWebCallContext = BuildCallContext(sDatabaseName); oWebDataProvider = GetDataProvider(sDatabaseName); if (oWebDataProvider != null && oWebCallContext != null) { oItemDefinition = oWebDataProvider.GetItemDefinition(oItemId, oWebCallContext); if (oItemDefinition != null) { oParentID = oWebDataProvider.GetParentID(oItemDefinition, oWebCallContext); if (!ID.IsNullOrEmpty(oParentID)) { oParentGuid = oParentID.Guid; } } else { Sitecore.Diagnostics.Log.Error(string.Format("Unable to get ItemDefinition for item:{0}", sItemId), this); } } else { if (oWebDataProvider == null) { Sitecore.Diagnostics.Log.Error("Unable to find data provide", this); } if (oWebCallContext == null) { Sitecore.Diagnostics.Log.Error(string.Format("Unable to get CallContext using database:{0}", sDatabaseName), this); } } } Sitecore.Diagnostics.Log.Info(string.Format("GetParentID End, Parentt ID:{0}", oParentGuid), this); return(oParentGuid); }