Exemplo n.º 1
0
        private void DownloadBook()
        {
            try
            {
                foreach (var model in _bookDownloadsRepository.GetItems())
                {
                    _container.Enqueue(new DownloadItemDataModel(model));
                }

                for (;;)
                {
                    var timeOut = 100;
                    if (_container.Count > 0)
                    {
                        var item = _container.Peek();
                        if (item != null)
                        {
                            timeOut = 1;
                            HandleBookDownloading(item, _container);
                        }
                    }

                    Thread.Sleep(timeOut);

                    if (_shouldStop)
                    {
                        break;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 2
0
        public void StartDownload()
        {
            if (!_bookDownloadsRepository.GetItems().Any())
            {
                return;
            }

            _bookDownloader.Start();
        }
        private bool CheckIsDownloading()
        {
            if (CatalogBookItemModel == null)
            {
                return(false);
            }

            var bookDownloadModel = _bookDownloadsRepository.GetItems().FirstOrDefault(i => i.CatalogItemId == CatalogBookItemModel.Id);

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

            int index = _container.GetDataModelIndex(new DownloadItemDataModel(bookDownloadModel));

            if (index > -1)
            {
                var bookDownloadViewModel = _container.Items[index];
                return(bookDownloadViewModel.Status != DownloadStatus.Error);
            }
            return(false);
        }