private IEnumerable<Item> GetLookupValues(BaseDataMap map, Item listParent, string importValue, string value)
 {
     if (!lookupValues.Any())
     {
         var listItems = listParent.GetChildren();
         foreach (Item item in listItems)
         {
             var lookupValue = item[MatchOnFieldName].ToLower();
             if (!lookupValues.ContainsKey(lookupValue))
             {
                 lookupValues.Add(lookupValue, new List<Item> {item});
             }
             else
             {
                 var itemList = lookupValues[lookupValue];
                 if (itemList != null)
                 {
                     if (!itemList.Contains(item))
                     {
                         itemList.Add(item);
                     }
                 }
             }
         }
     }
     if (lookupValues.ContainsKey(value))
     {
         return lookupValues[value];
     }
     return new List<Item>();
 }
 public virtual IEnumerable<Item> GetMatchingChildItem(BaseDataMap map, Item listParent, string importValue)
 {
     IEnumerable<Item> t = (from Item c in listParent.GetChildren()
                            where c.DisplayName.ToLower().Equals(StringUtility.GetNewItemName(importValue, 60))
                            select c).ToList();
     return t;
 }
        public static void GetRandomRelativePaths(Item currentItem, ref StringCollection stringCollection)
        {
            if (stringCollection == null)
                stringCollection = new StringCollection();

            if (currentItem != null)
            {
                var children = currentItem.GetChildren(ChildListOptions.None);
                if (children != null)
                {
                    foreach (Item child in children)
                    {
                        if (child.Fields["__Renderings"] != null && !String.IsNullOrEmpty(child.Fields["__Renderings"].ToString()))
                        {
                            string url = Sitecore.Links.LinkManager.GetItemUrl(child);

                            var aspxExtension = ".aspx";
                            if (!url.EndsWith(aspxExtension))
                                url += aspxExtension;

                            stringCollection.Add(url);
                            GetRandomRelativePaths(child, ref stringCollection);
                        }
                    }
                }
            }
        }
 public override IEnumerable<Item> GetMatchingChildItem(BaseDataMap map, Item listParent, string importValue)
 {
     IEnumerable<Item> t = (from Item c in listParent.GetChildren()
                            where c[MatchOnFieldName].ToLower().Equals(importValue.ToLower())
                            select c).ToList();
     return t;
 }
        private void RenderChildren(Item currentItem)
        {
            if (currentItem["show in menu"].Equals("1"))
            {
                ChildList children = currentItem.GetChildren();

                _sb.AppendFormat("<li><a href=\"{0}\">{1}</a></li><ul>", Links.LinkManager.GetItemUrl(currentItem),
                                FieldRenderer.Render(currentItem, "title"));

                foreach (Item child in children)
                {
                    RenderChildren(child);
                }

                _sb.Append("</ul>");
            }
        }
 private void LoadImagePanels(Item panelRoot, string rootUrl)
 {
     if (panelRoot.HasChildren)
     {
         foreach (Item panelParent in panelRoot.GetChildren())
         {
             PageSummaryItem current = new PageSummaryItem(panelParent);
             if (!current.Hidefrommenu.Checked)
             {
                 ImagePanel panel = this.Page.LoadControl("~/layouts/virginactive/navigation/ImagePanel.ascx") as ImagePanel;
                 panel.ContextItem = current;
                 panel.RootUrl = rootUrl; //Set a root URL because we want to generate jump links and section QS value
                 phPanels.Controls.Add(panel);
             }
         }
     }
 }
Example #7
0
 private ServerResponseModel CreateResponseModelForItem(Item item, string device,
                                                        string[] itemFields,
                                                        string[] childFields,
                                                        string mediaBaseUrl)
 {
     return new ServerResponseModel
     {
         Items = new[]
         {
             new ItemModel
             {
                 Properties = MapItem(item),
                 Fields = MapFields(item, itemFields, mediaBaseUrl),
                 Presentation = MapPresentation(item, device),
                 Children = item.GetChildren().Select(child => new ItemModel
                 {
                     Properties = MapItem(child),
                     Fields = MapFields(child, childFields, mediaBaseUrl)
                 })
             }
         }
     };
 }
        public void ProcessMediaItems(Item rootMediaItem, bool recursive)
        {
            if (rootMediaItem.TemplateID != TemplateIDs.MediaFolder
                && rootMediaItem.TemplateID != TemplateIDs.MainSection)
            {
                string statusMessage = "Processed " + Context.Job.Status.Processed + " items";
                Log.Info(statusMessage, this);

                // Update the job status
                Context.Job.Status.Processed++;
                Context.Job.Status.Messages.Add(statusMessage);

                var mediaItem = new MediaItem(rootMediaItem);
                AddMediaItemToZip(mediaItem);
            }
            else if (recursive)
            {
                foreach (Item item in rootMediaItem.GetChildren())
                {
                    ProcessMediaItems(item, true);
                }
            }
        }
        /// <summary>
        /// This function is responsible for pulling the actual Rendering for current device that's loaded and
        /// essentially 
        /// </summary>
        /// <param name="rootItem">The root item in which we need to get the child items to render.</param>
        /// <param name="placeholder">The place holder in which we want to place the child items into.</param>
        private void RenderChildItems(Item rootItem, PlaceHolder placeholder)
        {
            rootItem.GetChildren()
                .ToList()
                .ForEach(item =>
                {
                    // We need to get the path of the actual Sublayout's path
                    // First we need to get the device's rendering for this child item (assume the first returned rendering)
                    RenderingReference renderingReference = item
                        .Visualization
                        .GetRenderings(Sitecore.Context.Device, false)
                        .First();

                    // Now, get the actual sublayout item itself
                    Item sublayoutItem = Sitecore.Context.Database
                        .GetItem(renderingReference.RenderingID);

                    // Create a new sublayout with the sublayout's path and data item path.
                    Sublayout sublayout = new Sublayout
                    {
                        Path = sublayoutItem["Path"],
                        DataSource = item.Paths.Path
                    };

                    // now place this sublayout on the grid.
                    placeholder.Controls.Add(sublayout);
                });
        }
Example #10
0
        protected void GetChildItemsHelper(Item item, bool recurse, WildcardPattern wildcard, string language,
            int version)
        {
            var children = item.GetChildren();
            foreach (Item childItem in children)
            {
                var child = childItem;
                if (wildcard.IsMatch(child.Name))
                {
                    WriteMatchingItem(language, version, child);
                }

                if (recurse)
                {
                    GetChildItemsHelper(child, true, wildcard, language, version);
                }
            }
        }
Example #11
0
        private void SerializeToTargetLanguage(Item item, string target, Language language, bool recursive)
        {
            WriteVerbose(String.Format("Serializing item '{0}' to target '{1}'", item.Name, target));
            WriteDebug(String.Format("[Debug]: Serializing item '{0}' to target '{1}'", item.Name, target));

            if (string.IsNullOrEmpty(target))
            {
                Manager.DumpItem(item);
            }
            else
            {
                target = target.EndsWith("\\") ? target + item.Name : target + "\\" + item.Name;
                Manager.DumpItem(target + ".item", item);
            }
            if (recursive)
            {
                foreach (Item child in item.GetChildren(ChildListOptions.IgnoreSecurity))
                {
                    SerializeToTargetLanguage(child, target, language, true);
                }
            }
        }
Example #12
0
 private object GetPromotionEventDataSource(Item listParentItem)
 {
     Debug.ArgumentNotNull(listParentItem, "listparentitem");
     return listParentItem.GetChildren();
 }
Example #13
0
 private object GetClassSectionsDataSource(Item currentItem)
 {
     Debug.ArgumentNotNull(currentItem, "currentitem");
     return currentItem.GetChildren();
 }
Example #14
0
 private object GetChildrenDataSource(Item listParentItem)
 {
     Debug.ArgumentNotNull(listParentItem, "currentitem");
     return listParentItem.GetChildren();
 }
        /// <summary>
        /// Given a destination Item, this will create the structures on this item to host unstructured data
        /// </summary>
        /// <returns>This will return the destination parent Item that hosts the new Item</returns>
        /// <param name="topParent">Gets the root of where this item will be created</param>
        /// <param name="childItemCreationDateTime">Determins the folder that the item will be created within</param>
        internal static Item CreateAndReturnDateFolderDestination(Item topParent, DateTime childItemCreationDateTime)
        {
            Contract.Requires(topParent.IsNotNull());
            Contract.Requires(childItemCreationDateTime.IsNotNull());

            var database = topParent.Database;
            var dateFolder = childItemCreationDateTime.ToString(Config.BucketFolderPath);
            DateTimeFormatInfo dateTimeInfo = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;

            if (dateTimeInfo.DateSeparator != Constants.ContentPathSeperator)
            {
                Log.Info("ItemBuckets. DateTimeFormat inconsistency. Current date separator is " + dateTimeInfo.DateSeparator + " and time separator is " + dateTimeInfo.TimeSeparator + ". Relative path to folder is " + dateFolder, new object());
                dateFolder = dateFolder.Replace(dateTimeInfo.DateSeparator, Constants.ContentPathSeperator).Replace(dateTimeInfo.TimeSeparator,Constants.ContentPathSeperator);
            }

            var destinationFolderPath = topParent.Paths.FullPath + Constants.ContentPathSeperator + dateFolder;
            Item destinationFolderItem;

            // TODO: Use the Path Cache to determine if the path exists instead of looking it up on the item everytime I create an item (will be noticed if programmatically adding items)
            if ((destinationFolderItem = database.GetItem(destinationFolderPath)).IsNull())
            {
                var containerTemplate = database.Templates[new TemplateID(Config.ContainerTemplateId)];
                destinationFolderItem = database.CreateItemPath(destinationFolderPath, containerTemplate, containerTemplate);
            }

            using (new SecurityDisabler())
            {
                topParent.GetChildren().ToList().ForEach(HideItem);
            }

            Contract.Ensures(destinationFolderItem.IsNotNull());

            return destinationFolderItem;
        }
        /// <summary>
        /// The item that is passed to this method will now be made into a Bucket and all items under it will be automatically organised and hidden.
        /// </summary>
        /// <param name="item">The item that is being turned into a Bucket</param>
        /// <param name="callBack">Callback function that gets run once the Bucket Process has finised</param>
        public static void CreateBucket(Item item, Action<Item> callBack)
        {
            #if NET40
            Contract.Requires(item.IsNotNull());
            #else
            Assert.ArgumentNotNull(item, "item");
            #endif
            var bucketableItems = item.Children.ToList().Where(child => child.Template.IsBucketTemplateCheck());

            using(new EditContext(item, SecurityCheck.Disable))
            {
                item.IsBucketItemCheckBox().Checked = true;
            }
            long count = 0;

            foreach (var child in bucketableItems)
            {
                if (Context.Job.IsNotNull())
                {
                    Context.Job.Status.Processed = count;
                }
                if (ShouldDeleteInCreationOfBucket(child))
                {
                    child.Children.ToList().ForEach(MakeIntoBucket);
                    if (Context.Job.IsNotNull())
                    {
                        Context.Job.Status.Messages.Add("Deleting item " + child.Paths.FullPath);
                    }
                }
                else
                {
                    MoveItemToDateFolder(item, child);
                    if (Context.Job.IsNotNull())
                    {
                        Context.Job.Status.Messages.Add("Moving item " + child.Paths.FullPath);
                    }
                }

                count++;
            }

            using (new SecurityDisabler())
            {
                item.GetChildren().ToList().ForEach(HideItem);

            }

            callBack(item);
        }
        private bool RunCompare(SimpleTreeNode parentnode, Item item, Database compareDB, CompareStatus missingDirection)
        {
            var dirty = false;

            try
            {
                var info = new ItemComparisonInfo(item);
                if (_differences.ContainsKey(info.ItemKey))
                    info = _differences[info.ItemKey];

                CompareEngine.RunCompare(compareDB, item, info, missingDirection, _ignoreMissingVersions, _ignoreMissingLanguages);

                // Create the tree node
                var nodeIsNew = false;
                //var node = parentnode.ChildNodes.Cast<TreeNode>().SingleOrDefault(x => x.Value == item.Paths.Path);
                var node = parentnode.Nodes.SingleOrDefault(x => x.Value == info.ItemKey);
                if (node == null)
                {
                    node = CreateNode(info);
                    nodeIsNew = true;
                }

                if (info.Status != CompareStatus.Matched)
                {
                    dirty = true;
                    if (!_differences.ContainsKey(info.ItemKey))
                        _differences.Add(info.ItemKey, info);
                }

                if (Sitecore.Data.Managers.TemplateManager.IsTemplate(item))
                {
                    var t = (TemplateItem)item;
                    if (t.StandardValues != null)
                        dirty = RunCompare(node, t.StandardValues, compareDB, missingDirection) | dirty;
                }
                else
                {
                    foreach (var child in item.GetChildren().InnerChildren)
                    {
                        dirty = RunCompare(node, child, compareDB, missingDirection) | dirty;
                    }
                }

                if (dirty && nodeIsNew)
                    parentnode.AddNode(node);

            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("RunCompare failed. [parentnode:{0}][item:{1}][compareDB:{2}]", new object[]{
                    parentnode == null? "NULL!" : parentnode.Value,
                    item == null ? "NULL!" : item.Paths.Path,
                    compareDB == null ? "NULL!" : compareDB.Name
                }), ex);
            }

            return dirty;
        }
        /// <summary>
        /// Given a destination Item, this will create the structures on this item to host unstructured data
        /// </summary>
        /// <returns>This will return the destination parent Item that hosts the new Item</returns>
        /// <param name="topParent">Gets the root of where this item will be created</param>
        /// <param name="childItemCreationDateTime">Determins the folder that the item will be created within</param>
        internal static Item CreateAndReturnDateFolderDestination(Item topParent, DateTime childItemCreationDateTime)
        {
            var database = topParent.Database;
            var dateFolder = childItemCreationDateTime.ToString(Config.BucketFolderPath);
            var destinationFolderPath = topParent.Paths.FullPath + Constants.ContentPathSeperator + dateFolder;
            Item destinationFolderItem;

            // TODO: Use the Path Cache to determine if the path exists instead of looking it up on the item everytime I create an item (will be noticed if programmatically adding items)
            if ((destinationFolderItem = database.GetItem(destinationFolderPath)).IsNull())
            {
                var containerTemplate = database.Templates[new TemplateID(Config.ContainerTemplateId)];
                destinationFolderItem = database.CreateItemPath(destinationFolderPath, containerTemplate, containerTemplate);
            }

            using (new SecurityDisabler())
            {
                topParent.GetChildren().ToList().ForEach(HideItem);
            }

            return destinationFolderItem;
        }
 private void AddChildren(Item parent, List<Item> items)
 {
     items.Add(parent);
     if (parent.HasChildren)
     {
         foreach (Item child in parent.GetChildren())
         {
             AddChildren(child, items);
         }
     }
 }
 public override IEnumerable<Item> GetMatchingChildItem(BaseDataMap map, Item listParent, string importValue)
 {
     var values = ParseImportValues(importValue);
     var result = new List<Item>();
     foreach (var value in values)
     {
         if (!string.IsNullOrEmpty(value))
         {
             var list =  (IEnumerable<Item>)Enumerable.ToList<Item>(Enumerable.Where<Item>(Enumerable.Cast<Item>((IEnumerable)listParent.GetChildren()), (Func<Item, bool>)(c => c[this.MatchOnFieldName].ToLower().Equals(value.ToLower()))));
             result.AddRange(list);
         }
     }
     return result;
 }
 /// <summary>
 ///     Helper method that logs the Sitecore tree structure starting from the item that is passed.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="level">Level; for indentation</param>
 public static void LogTreeStructure(Item item, int level = 0)
 {
     Console.WriteLine("{0}>{1}", new string(' ', level*2), item.Name);
     // LogItemFields(item, level);
     foreach (Item child in item.GetChildren())
     {
         LogTreeStructure(child, level + 1);
     }
 }
 /// <summary>
 /// searches under the parent for an item whose template matches the id provided
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="TemplateID"></param>
 /// <returns></returns>
 protected Item GetItemByTemplate(Item parent, string TemplateID)
 {
     IEnumerable<Item> x = from Item i in parent.GetChildren()
                           where i.Template.IsID(TemplateID)
                           select i;
     return (x.Any()) ? x.First() : null;
 }
 private void AddItemIDs(Item item, Hashtable itemIDs)
 {
     itemIDs[item.ID] = string.Empty;
     foreach (Item item2 in item.GetChildren(ChildListOptions.None))
     {
         this.AddItemIDs(item2, itemIDs);
     }
 }
        private void PopulateSections(Item homeItem)
        {
            using (new SecurityDisabler())
            {

                var sections = homeItem.GetChildren().ToArray();

                if (sections.Length == 0)
                {
                    sections =
                        Enumerable.Range(1, NumberOfSections).Select(
                            i => homeItem.Add("Section" + i, this.folderItemTemplateId)).ToArray();
                }

                foreach (var section in sections)
                {
                    Enumerable.Range(0, ItemsPerSectionPerRun).Select(
                        i =>
                            {
                                var now = DateTime.Now;
                                var hour = now.ToString("HH");
                                var minute = now.ToString("mm");
                                var second = now.ToString("ss");

                                var hourFolder = section.GetChildren().FirstOrDefault(item => item.Name == hour)
                                                 ?? section.Add(hour, this.folderItemTemplateId);

                                var minuteFolder = hourFolder.GetChildren().FirstOrDefault(item => item.Name == minute)
                                                   ?? hourFolder.Add(minute, this.folderItemTemplateId);

                                var secondFolder = minuteFolder.GetChildren().FirstOrDefault(
                                    item => item.Name == second) ?? minuteFolder.Add(second, this.folderItemTemplateId);

                                return secondFolder.Add(
                                    i.ToString(CultureInfo.InvariantCulture), this.sampleItemTemplateId);
                            }).ToArray();
                }
            }
        }
        /// <summary>
        /// Given a destination Item, this will create the structures on this item to host unstructured data
        /// </summary>
        /// <returns>This will return the destination parent Item that hosts the new Item</returns>
        /// <param name="topParent">Gets the root of where this item will be created</param>
        /// <param name="childItemCreationDateTime">Determins the folder that the item will be created within</param>
        internal static Item CreateAndReturnDateFolderDestination(Item topParent, DateTime childItemCreationDateTime)
        {
            #if NET40
            Contract.Requires(topParent.IsNotNull());
            Contract.Requires(childItemCreationDateTime.IsNotNull());
            #else
            Assert.ArgumentNotNull(topParent, "topParent");
            Assert.ArgumentNotNull(childItemCreationDateTime, "childItemCreationDateTime");
            #endif

            var database = topParent.Database;
            var dateFolder = childItemCreationDateTime.ToString(Config.BucketFolderPath);
            var destinationFolderPath = topParent.Paths.FullPath + Constants.ContentPathSeperator + dateFolder;
            Item destinationFolderItem;

            // TODO: Use the Path Cache to determine if the path exists instead of looking it up on the item everytime I create an item (will be noticed if programmatically adding items)
            if ((destinationFolderItem = database.GetItem(destinationFolderPath)).IsNull())
            {
                var containerTemplate = database.Templates[new TemplateID(Config.ContainerTemplateId)];
                destinationFolderItem = database.CreateItemPath(destinationFolderPath, containerTemplate, containerTemplate);
            }

            using (new SecurityDisabler())
            {
                topParent.GetChildren().ToList().ForEach(HideItem);
            }

            #if NET40
            Contract.Ensures(destinationFolderItem.IsNotNull());
            #else
            Assert.IsTrue(destinationFolderItem.IsNotNull(), "destinationFolderItem cannot be null");
            #endif
            return destinationFolderItem;
        }
 private void RebuildItem(Item item)
 {
     this.UpdateReferences(item);
     foreach (Item item2 in item.GetChildren(ChildListOptions.None))
     {
         this.RebuildItem(item2);
     }
 }