示例#1
0
        public bool DownloadBook(CatalogBookItemModel catalogBookItemModel, int catalogId, bool fullBook = true)
        {
            var link = fullBook
                           ? GetDownloadLink(catalogBookItemModel.Links.ToArray())
                           : GetDownloadLink(catalogBookItemModel.TrialLink);

            if (link == null)
            {
                return(false);
            }

            if (!_bookDownloader.IsStarted)
            {
                _bookDownloader.Start();
            }

            var downloadModel = new BookDownloadModel
            {
                Path = link.Url,
                Type = GetBookType(link.Type),

                IsZip             = CheckIsZip(link.Type),
                Name              = catalogBookItemModel.Title,
                Author            = catalogBookItemModel.Author,
                Description       = catalogBookItemModel.Description,
                AcquisitionUrl    = catalogBookItemModel.AcquisitionLink != null ? catalogBookItemModel.AcquisitionLink.Url : null,
                AcquisitionType   = catalogBookItemModel.AcquisitionLink != null ? catalogBookItemModel.AcquisitionLink.Type : null,
                AcquisitionPrices = catalogBookItemModel.AcquisitionLink != null?catalogBookItemModel.AcquisitionLink.ToString() : null,
                                        DataSourceID  = catalogId,
                                        IsTrial       = !fullBook,
                                        CatalogItemId = catalogBookItemModel.Id
            };

            int oldQueueCount = _container.Count;

            _bookDownloadsRepository.Add(downloadModel);

            var downloadViewModel = new DownloadItemDataModel(downloadModel);

            _container.Enqueue(downloadViewModel);

            if (_container.Count == oldQueueCount)
            {
                int index = _container.GetDataModelIndex(downloadViewModel);
                if (index > -1)
                {
                    var viewModel = _container.Items[index];
                    if (viewModel.Status == DownloadStatus.Error)
                    {
                        viewModel.Status = DownloadStatus.Pending;
                        _bookDownloadsRepository.Remove(downloadModel.DownloadID);
                    }
                }
            }
            return(true);
        }
示例#2
0
        private void HandleBookDownloading(DownloadItemDataModel downloadItemDataModel, IDownloadsContainer instance)
        {
            if (ProcessBook(downloadItemDataModel))
            {
                RemoveItem(downloadItemDataModel, instance);
                _bookDownloadsRepository.Remove(downloadItemDataModel.DownloadID);

                OnDownloadCompleted(downloadItemDataModel);
            }
            else if (downloadItemDataModel.Status == DownloadStatus.Error)
            {
                OnDownloadError(downloadItemDataModel);
            }
        }
示例#3
0
 public void Remove(DownloadItemDataModel item)
 {
     _bookDownloadsRepository.Remove(item.DownloadID);
 }