示例#1
0
        public void Handle(TrackImportedEvent message)
        {
            if (!message.NewDownload)
            {
                return;
            }

            var downloadId = message.DownloadId;

            if (downloadId.IsNullOrWhiteSpace())
            {
                downloadId = FindDownloadId(message);
            }

            var history = new History
            {
                EventType   = HistoryEventType.BookFileImported,
                Date        = DateTime.UtcNow,
                Quality     = message.BookInfo.Quality,
                SourceTitle = message.ImportedBook.SceneName ?? Path.GetFileNameWithoutExtension(message.BookInfo.Path),
                AuthorId    = message.BookInfo.Author.Id,
                BookId      = message.BookInfo.Book.Id,
                DownloadId  = downloadId
            };

            //Won't have a value since we publish this event before saving to DB.
            //history.Data.Add("FileId", message.ImportedEpisode.Id.ToString());
            history.Data.Add("DroppedPath", message.BookInfo.Path);
            history.Data.Add("ImportedPath", message.ImportedBook.Path);
            history.Data.Add("DownloadClient", message.DownloadClient);

            _historyRepository.Insert(history);
        }
示例#2
0
        public void should_return_ok_on_track_imported_event()
        {
            GivenFolderExists(downloadRootPath);
            var importEvent = new TrackImportedEvent(new LocalTrack(), new TrackFile(), new List <TrackFile>(), true, new DownloadClientItem());

            Subject.Check(importEvent).ShouldBeOk();
        }
        public void should_return_ok_on_book_imported_event()
        {
            GivenFolderExists(_downloadRootPath);
            var importEvent = new TrackImportedEvent(new LocalBook(), new BookFile(), new List <BookFile>(), true, _downloadItem);

            Subject.Check(importEvent).ShouldBeOk();
        }
示例#4
0
 public void Handle(TrackImportedEvent message)
 {
     foreach (var track in message.TrackInfo.Tracks)
     {
         track.TrackFile = message.ImportedTrack;
         BroadcastResourceChange(ModelAction.Updated, MapToResource(track, true, true));
     }
 }
示例#5
0
        private string FindDownloadId(TrackImportedEvent trackedDownload)
        {
            _logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedBook.Path);

            var bookIds = new List <int> {
                trackedDownload.BookInfo.Book.Id
            };

            var allHistory = _historyRepository.FindDownloadHistory(trackedDownload.BookInfo.Author.Id, trackedDownload.ImportedBook.Quality);

            //Find download related items for these episdoes
            var albumsHistory = allHistory.Where(h => bookIds.Contains(h.BookId)).ToList();

            var processedDownloadId = albumsHistory
                                      .Where(c => c.EventType != HistoryEventType.Grabbed && c.DownloadId != null)
                                      .Select(c => c.DownloadId);

            var stillDownloading = albumsHistory.Where(c => c.EventType == HistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList();

            string downloadId = null;

            if (stillDownloading.Any())
            {
                var matchingHistory = stillDownloading.Where(c => c.BookId == trackedDownload.BookInfo.Book.Id).ToList();

                if (matchingHistory.Count != 1)
                {
                    return(null);
                }

                var newDownloadId = matchingHistory.Single().DownloadId;

                if (downloadId == null || downloadId == newDownloadId)
                {
                    downloadId = newDownloadId;
                }
                else
                {
                    return(null);
                }
            }

            return(downloadId);
        }
示例#6
0
        public void Handle(TrackImportedEvent message)
        {
            if (!message.NewDownload)
            {
                return;
            }

            var downloadId = message.DownloadId;

            // Try to find the downloadId if the user used manual import (from wanted: missing) or the
            // API to import and downloadId wasn't provided.
            if (downloadId.IsNullOrWhiteSpace())
            {
                downloadId = _historyService.FindDownloadId(message);
            }

            if (downloadId.IsNullOrWhiteSpace())
            {
                return;
            }

            var history = new DownloadHistory
            {
                EventType = DownloadHistoryEventType.FileImported,

                AuthorId         = message.ImportedBook.Author.Value.Id,
                DownloadId       = downloadId,
                SourceTitle      = message.BookInfo.Path,
                Date             = DateTime.UtcNow,
                Protocol         = message.DownloadClientInfo.Protocol,
                DownloadClientId = message.DownloadClientInfo.Id
            };

            history.Data.Add("DownloadClient", message.DownloadClientInfo.Type);
            history.Data.Add("DownloadClientName", message.DownloadClientInfo.Name);
            history.Data.Add("SourcePath", message.BookInfo.Path);
            history.Data.Add("DestinationPath", message.ImportedBook.Path);

            _repository.Insert(history);
        }
示例#7
0
 public void Handle(TrackImportedEvent message)
 {
     _refreshDebounce.Execute();
 }
示例#8
0
 public void Handle(TrackImportedEvent message)
 {
     BroadcastResourceChange(ModelAction.Updated, message.BookInfo.Book.ToResource());
 }