Example #1
0
        public void DownloadAllPodcasts()
        {
            Logger.Debug(() => $"DownloadViewModel:DownloadAllPodcasts");

            if (AllSyncItems.Count < 1)
            {
                Observables.DisplayMessage?.Invoke(this, "Nothing to download");
                return;
            }

            Observables.StartDownloading?.Invoke(this, null);

            int numberOfConnections = ControlFile.GetMaximumNumberOfConcurrentDownloads();

            System.Net.ServicePointManager.DefaultConnectionLimit = numberOfConnections;

            List <ISyncItem> AllEpisodesToDownload = new List <ISyncItem>(AllSyncItems.Count);

            AllSyncItems.Where(recyclerItem => recyclerItem.Selected).ToList().ForEach(item => AllEpisodesToDownload.Add(item.SyncItem));

            IEpisodeDownloader[] downloadTasks = Converter.ConvertItemsToTasks(AllEpisodesToDownload, DownloadStatusUpdate, DownloadProgressUpdate);
            foreach (var task in downloadTasks)
            {
                Logger.Debug(() => $"DownloadViewModel:Download to: {task.SyncItem.DestinationPath}");
            }

            // run them in a task pool
            TaskPool.RunAllTasks(numberOfConnections, downloadTasks);
        }
Example #2
0
        private void DownloadFile1()
        {
            ReadOnlyControlFile controlFile = new ReadOnlyControlFile(_inputfilename);
            IPodcastInfo        info        = GetPodcastInfo(controlFile, 0);

            DisplayMessage(string.Format("Reading a feed: {0}", info.Feed.Address));
            IList <ISyncItem> allEpisodes = GetAllEpisodesInFeed(controlFile, info);

            if (allEpisodes.Count < 1)
            {
                DisplayMessage("No episodes in the feed - dont forget the state.xml file is being used", DisplayLevel.Warning);
                return;
            }
            IList <ISyncItem> firstEpisode = new List <ISyncItem>(1);

            firstEpisode.Add(allEpisodes.First());

            DisplayMessage(string.Format("Downloading Eposode: {0}", firstEpisode.First().EpisodeTitle));
            ISyncItemToEpisodeDownloaderTaskConverter converter = _iocContainer.Resolve <ISyncItemToEpisodeDownloaderTaskConverter>();

            IEpisodeDownloader[] downloadTasks = converter.ConvertItemsToTasks(firstEpisode, StatusUpdate, ProgressUpdate);

            // run them in a task pool
            ITaskPool taskPool = _iocContainer.Resolve <ITaskPool>();

            taskPool.RunAllTasks(1, downloadTasks);

            DisplayMessage(string.Format("Download Complete", allEpisodes.Count));
        }
        // dont run this on the UI thread
        private void DownloadAllPodcasts()
        {
            Logger.Debug(() => $"DownloadViewModel:DownloadAllPodcasts");

            if (AllItems.Count < 1)
            {
                Observables.DisplayMessage?.Invoke(this, ResourceProvider.GetString(Resource.String.no_downloads_text));
                return;
            }

            lock (SyncLock)
            {
                if (DownloadingInProgress)
                {
                    Logger.Warning(() => $"DownloadViewModel:DownloadAllPodcasts - already in progress - ignored");
                    return;
                }
                DownloadingInProgress = true;
            }

            try
            {
                Observables.StartDownloading?.Invoke(this, null);

                var controlFile         = ApplicationControlFileProvider.GetApplicationConfiguration();
                int numberOfConnections = controlFile.GetMaximumNumberOfConcurrentDownloads();
                NetworkHelper.SetNetworkConnectionLimit(numberOfConnections);

                List <ISyncItem> AllEpisodesToDownload = new List <ISyncItem>(AllItems.Count);
                AllItems.Where(recyclerItem => recyclerItem.Selected).ToList().ForEach(item => AllEpisodesToDownload.Add(item.SyncItem));

                IEpisodeDownloader[] downloadTasks = Converter.ConvertItemsToTasks(AllEpisodesToDownload, DownloadStatusUpdate, DownloadProgressUpdate);
                foreach (var task in downloadTasks)
                {
                    Logger.Debug(() => $"DownloadViewModel:Download to: {task.SyncItem.DestinationPath}");
                }

                // run them in a task pool
                TaskPool.RunAllTasks(numberOfConnections, downloadTasks);
                Logger.Debug(() => $"DownloadViewModel:Download tasks complete");
            }
            catch (Exception ex)
            {
                Logger.LogException(() => $"DownloadViewModel:DownloadAllPodcasts", ex);
                CrashReporter.LogNonFatalException(ex);
                Observables.DisplayMessage?.Invoke(this, ex.Message);
            }
            finally
            {
                Observables.EndDownloading?.Invoke(this, ResourceProvider.GetString(Resource.String.download_activity_complete));
                if (ExitRequested)
                {
                    Observables.Exit?.Invoke(this, null);
                }
                DownloadingInProgress = false;
            }
        }