private bool RemoveRedundantFavorites(List <IFavorite> current, List <IFavorite> newFavorites) { var favoritesToRemove = ListsHelper.GetMissingSourcesInTarget(current, newFavorites); RemoveFavoritesFromCache(favoritesToRemove); return(favoritesToRemove.Count > 0); }
private bool AddMissingFavorites(List <IFavorite> current, List <IFavorite> newFavorites) { var favoritesToAdd = ListsHelper.GetMissingSourcesInTarget(newFavorites, current); AddFavoritesToCache(favoritesToAdd); return(favoritesToAdd.Count > 0); }
private List <IGroup> AddIntoMissingGroups(IFavorite favorite, List <IGroup> newGroups, List <IGroup> oldGroups) { // First create new groups, which aren't in persistence yet var addedGroups = this.groups.AddAllToCache(newGroups); List <IGroup> missingGroups = ListsHelper.GetMissingSourcesInTarget(newGroups, oldGroups); AddIntoMissingGroups(favorite, missingGroups); return(addedGroups); }
private void UpdateFavoriteInGroups(IFavorite favorite, List <IGroup> newGroups) { var oldGroups = this.groups.GetGroupsContainingFavorite(favorite.Id); List <IGroup> addedGroups = this.AddIntoMissingGroups(favorite, newGroups, oldGroups); List <IGroup> redundantGroups = ListsHelper.GetMissingSourcesInTarget(oldGroups, newGroups); Groups.RemoveFavoritesFromGroups(new List <IFavorite> { favorite }, redundantGroups); this.dispatcher.ReportGroupsAdded(addedGroups); }
internal void AddFrom(FavoritesChangedEventArgs source) { var toAdd = ListsHelper.GetMissingSourcesInTarget(source.Added, this.Added); this.Added.AddRange(toAdd); var toUpdate = ListsHelper.GetMissingSourcesInTarget(source.Updated, this.Updated); this.Updated.AddRange(toUpdate); var toRemove = ListsHelper.GetMissingSourcesInTarget(source.Removed, this.Removed); this.Removed.AddRange(toRemove); }
internal List <IGroup> Merge(List <IGroup> newGroups) { List <IGroup> oldGroups = this.ToList(); List <IGroup> addedGroups = ListsHelper.GetMissingSourcesInTarget(newGroups, oldGroups); List <IGroup> deletedGroups = ListsHelper.GetMissingSourcesInTarget(oldGroups, newGroups); addedGroups = this.AddAllToCache(addedGroups); this.dispatcher.ReportGroupsAdded(addedGroups); deletedGroups = this.DeleteFromCache(deletedGroups); this.dispatcher.ReportGroupsDeleted(deletedGroups); return(addedGroups); }
internal void Merge(List <IFavorite> newFavorites) { var oldFavorites = new List <IFavorite>(this); List <IFavorite> missingFavorites = ListsHelper.GetMissingSourcesInTarget(newFavorites, oldFavorites); List <IFavorite> redundantFavorites = ListsHelper.GetMissingSourcesInTarget(oldFavorites, newFavorites); this.AddToCacheAndReport(missingFavorites); List <IFavorite> deleted = this.DeleteAllFavoritesFromCache(redundantFavorites); // dont remove favorites from groups, because we are expecting, that the loaded file already contains correct membership this.dispatcher.ReportFavoritesDeleted(deleted); // Simple update without ensuring, if the favorite was changes or not - possible performance issue); List <IFavorite> notReported = ListsHelper.GetMissingSourcesInTarget(this.ToList(), missingFavorites); this.dispatcher.ReportFavoritesUpdated(notReported); }
private void FavoritesFileChanged(object sender, EventArgs e) { FavoritesFile file = this.LoadFile(); // dont report changes immediately, we have to wait till memberships are refreshed properly this.Dispatcher.StartDelayedUpdate(); List <IGroup> addedGroups = this.groups.Merge(file.Groups.Cast <IGroup>().ToList()); this.favorites.Merge(file.Favorites.Cast <IFavorite>().ToList()); // first update also present groups assignment, // than send the favorite update also for present favorites List <IGroup> updated = this.UpdateFavoritesInGroups(file.FavoritesInGroups); updated = ListsHelper.GetMissingSourcesInTarget(updated, addedGroups); this.Dispatcher.ReportGroupsUpdated(updated); this.Dispatcher.EndDelayedUpdate(); }