protected override void ProcessChildren(Author entity, SortedChildren children) { foreach (var book in children.Added) { book.Monitored = _monitorNewBookService.ShouldMonitorNewBook(book, children.UpToDate, entity.MonitorNewItems); } }
private void MonitorSingleEdition(SortedChildren children) { children.Old.ForEach(x => x.Monitored = false); var monitored = children.Future.Where(x => x.Monitored).ToList(); if (monitored.Count == 1) { return; } if (monitored.Count == 0) { monitored = children.Future; } if (monitored.Count == 0) { // there are no future children so nothing to do return; } var toMonitor = monitored.OrderByDescending(x => x.Id > 0 ? _mediaFileService.GetFilesByEdition(x.Id).Count : 0) .ThenByDescending(x => x.Ratings.Popularity).First(); monitored.ForEach(x => x.Monitored = false); toMonitor.Monitored = true; // force update of anything we've messed with var extraToUpdate = children.UpToDate.Where(x => monitored.Contains(x)); children.UpToDate = children.UpToDate.Except(extraToUpdate).ToList(); children.Updated.AddRange(extraToUpdate); Debug.Assert(!children.Future.Any() || children.Future.Count(x => x.Monitored) == 1, "one edition monitored"); }
protected override bool RefreshChildren(SortedChildren localChildren, List <Edition> remoteChildren, Author remoteData, bool forceChildRefresh, bool forceUpdateFileTags, DateTime?lastUpdate) { // make sure only one of the releases ends up monitored MonitorSingleEdition(localChildren); localChildren.All.ForEach(x => _logger.Trace($"release: {x} monitored: {x.Monitored}")); _editionService.InsertMany(localChildren.Added); return(_refreshEditionService.RefreshEditionInfo(localChildren.Added, localChildren.Updated, localChildren.Merged, localChildren.Deleted, localChildren.UpToDate, remoteChildren, forceUpdateFileTags)); }
protected override bool RefreshChildren(SortedChildren localChildren, List <AlbumRelease> remoteChildren, bool forceChildRefresh, bool forceUpdateFileTags) { var refreshList = localChildren.All; // make sure only one of the releases ends up monitored localChildren.Old.ForEach(x => x.Monitored = false); MonitorSingleRelease(localChildren.Future); refreshList.ForEach(x => _logger.Trace($"release: {x} monitored: {x.Monitored}")); return(_refreshAlbumReleaseService.RefreshEntityInfo(refreshList, remoteChildren, forceChildRefresh, forceUpdateFileTags)); }
protected override bool RefreshChildren(SortedChildren localChildren, List <Book> remoteChildren, Author remoteData, bool forceChildRefresh, bool forceUpdateFileTags, DateTime?lastUpdate) { return(_refreshBookService.RefreshBookInfo(localChildren.All, remoteChildren, remoteData, forceChildRefresh, forceUpdateFileTags, lastUpdate)); }
protected override bool RefreshChildren(SortedChildren localChildren, List <Track> remoteChildren, bool forceChildRefresh, bool forceUpdateFileTags) { return(_refreshTrackService.RefreshTrackInfo(localChildren.Added, localChildren.Updated, localChildren.Merged, localChildren.Deleted, localChildren.UpToDate, remoteChildren, forceUpdateFileTags)); }
protected bool SortChildren(Entity entity, List <Child> remoteChildren, bool forceChildRefresh, bool forceUpdateFileTags) { // Get existing children (and children to be) from the database var localChildren = GetLocalChildren(entity, remoteChildren); var sortedChildren = new SortedChildren(); sortedChildren.Deleted.AddRange(localChildren); // Cycle through children foreach (var remoteChild in remoteChildren) { // Check for child in existing children, if not set properties and add to new list var tuple = GetMatchingExistingChildren(localChildren, remoteChild); var existingChild = tuple.Item1; var mergedChildren = tuple.Item2; if (existingChild != null) { sortedChildren.Deleted.Remove(existingChild); PrepareExistingChild(existingChild, remoteChild, entity); if (existingChild.Equals(remoteChild)) { sortedChildren.UpToDate.Add(existingChild); } else { sortedChildren.Updated.Add(existingChild); } // note the children that are going to be merged into existingChild foreach (var child in mergedChildren) { sortedChildren.Merged.Add(Tuple.Create(child, existingChild)); sortedChildren.Deleted.Remove(child); } } else { PrepareNewChild(remoteChild, entity); sortedChildren.Added.Add(remoteChild); // note the children that will be merged into remoteChild (once added) foreach (var child in mergedChildren) { sortedChildren.Merged.Add(Tuple.Create(child, remoteChild)); sortedChildren.Deleted.Remove(child); } } } _logger.Debug("{0} {1} {2}s up to date. Adding {3}, Updating {4}, Merging {5}, Deleting {6}.", entity, sortedChildren.UpToDate.Count, typeof(Child).Name.ToLower(), sortedChildren.Added.Count, sortedChildren.Updated.Count, sortedChildren.Merged.Count, sortedChildren.Deleted.Count); // Add in the new children (we have checked that foreign IDs don't clash) AddChildren(sortedChildren.Added); // now trigger updates var updated = RefreshChildren(sortedChildren, remoteChildren, forceChildRefresh, forceUpdateFileTags); PublishChildrenUpdatedEvent(entity, sortedChildren.Added, sortedChildren.Updated); return(updated); }
protected abstract bool RefreshChildren(SortedChildren localChildren, List <Child> remoteChildren, bool forceChildRefresh, bool forceUpdateFileTags);
protected abstract bool RefreshChildren(SortedChildren localChildren, List <TChild> remoteChildren, Author remoteData, bool forceChildRefresh, bool forceUpdateFileTags, DateTime?lastUpdate);
protected override bool RefreshChildren(SortedChildren localChildren, List <SeriesBookLink> remoteChildren, Author remoteData, bool forceChildRefresh, bool forceUpdateFileTags, DateTime?lastUpdate) { return(_refreshLinkService.RefreshSeriesBookLinkInfo(localChildren.Added, localChildren.Updated, localChildren.Merged, localChildren.Deleted, localChildren.UpToDate, remoteChildren, forceUpdateFileTags)); }
protected virtual void ProcessChildren(TEntity entity, SortedChildren children) { }
protected override bool RefreshChildren(SortedChildren localChildren, List <Album> remoteChildren, bool forceChildRefresh, bool forceUpdateFileTags) { // we always want to end up refreshing the albums since we don't get have proper data Ensure.That(localChildren.UpToDate.Count, () => localChildren.UpToDate.Count).IsLessThanOrEqualTo(0); return(_refreshAlbumService.RefreshAlbumInfo(localChildren.All, remoteChildren, forceChildRefresh, forceUpdateFileTags)); }