Exemple #1
0
        /// <summary>
        /// Get updated Items only from History Table based on from Date to Now Date
        /// </summary>
        /// <param name="dbname">string, Sitecore Database name, example master</param>
        /// <param name="from">DateTime, in UTC format to retrive the items since</param>
        /// <param name="language">string, retrieve specific language item only</param>
        /// <param name="version">int, Item Version Number, Passed item version will only be effective if exact match of path given with history entry found otherwise latest version will be asked for all other items</param>
        /// <param name="path">string, retrive those items only which are under certain location</param>
        /// <returns>Item array</returns>
        public static Item[] getUpdatedHistoryItems(string dbname, DateTime from, string language = "en", string path = "")
        {
            List <Item> li  = new List <Item>();
            var         now = DateTime.UtcNow;

            Sitecore.Collections.HistoryEntryCollection entries = HistoryManager.GetHistory(GetDatabase(dbname), from, now);
            entries = getUniqueLatestVersionFromHistoryCollection(entries);
            if (entries != null && entries.Count > 0)
            {
                foreach (var item in entries)
                {
                    if (item.Category == Sitecore.Data.Engines.HistoryCategory.Item)
                    {
                        if (item.Action == Sitecore.Data.Engines.HistoryAction.AddedVersion || item.Action == Sitecore.Data.Engines.HistoryAction.AddedVersion || item.Action == Sitecore.Data.Engines.HistoryAction.Saved)
                        {
                            Item itm = getHistoryItem(item, dbname, item.ItemVersion.Number, language, path);
                            if (itm != null)
                            {
                                li.Add(itm);
                            }
                        }
                    }
                }
            }
            if (li != null && li.Count > 0)
            {
                li = li.DistinctBy(x => x.ID).ToList <Item>();
            }
            return(li.ToArray <Item>());
        }
Exemple #2
0
 public static Sitecore.Collections.HistoryEntryCollection getUniqueLatestVersionFromHistoryCollection(Sitecore.Collections.HistoryEntryCollection data)
 {
     Sitecore.Collections.HistoryEntryCollection hec = null;
     if (data != null && data.Count > 0)
     {
         hec = new Sitecore.Collections.HistoryEntryCollection();
         //This will find out unique items in history collection
         var unique = data.DistinctBy(x => x.ItemId);
         foreach (var item in unique)
         {
             //This will found those items with same ID in the original data collection
             List <Sitecore.Data.Engines.HistoryEntry> sameItems = (from he in data
                                                                    where he.ItemId == item.ItemId
                                                                    select he).ToList <Sitecore.Data.Engines.HistoryEntry>();
             //This will find out the latest version possible in the sameItems collection
             Sitecore.Data.Engines.HistoryEntry historyEntry = sameItems.Aggregate((i1, i2) => i1.ItemVersion.Number > i2.ItemVersion.Number ? i1 : i2);
             //Finally add the value to real history collection
             if (historyEntry != null)
             {
                 hec.Add(historyEntry);
             }
         }
     }
     return(hec);
 }
Exemple #3
0
        public static Sitecore.Collections.HistoryEntryCollection getAllHistoryItems(string dbname, DateTime from, DateTime to, Sitecore.Data.Engines.HistoryAction ha)
        {
            Sitecore.Collections.HistoryEntryCollection hec = new Sitecore.Collections.HistoryEntryCollection();
            var entries = HistoryManager.GetHistory(GetDatabase(dbname), from, to);

            foreach (var item in entries)
            {
                if (item.Category == Sitecore.Data.Engines.HistoryCategory.Item && ha == item.Action)
                {
                    hec.Add(item);
                }
            }
            return(hec);
        }
Exemple #4
0
        public static Item[] getHistoryAtPoint(string dbname, DateTime atPoint, Sitecore.Data.Engines.HistoryAction ha, string language = "en", string path = "")
        {
            DateTime    from = DateTime.MinValue;
            List <Item> li   = new List <Item>();

            Sitecore.Collections.HistoryEntryCollection hec = getAllHistoryItems(dbname, from, atPoint, ha);
            hec = getUniqueLatestVersionFromHistoryCollection(hec);
            if (hec != null && hec.Count > 0)
            {
                foreach (var item in hec)
                {
                    Item itm = getHistoryItem(item, dbname, item.ItemVersion.Number, language, path);
                    if (itm != null)
                    {
                        li.Add(itm);
                    }
                }
            }
            return(li.ToArray <Item>());
        }