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); }
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); }