コード例 #1
0
        protected void SetupMockControlFileFor2Podcasts(DiagnosticOutputLevel level = DiagnosticOutputLevel.None)
        {
            podcast1Mocker = new PodcastInfoMocker()
                             .ApplyFolder(PODCAST_FOLDER_1);
            podcast2Mocker = new PodcastInfoMocker()
                             .ApplyFolder(PODCAST_FOLDER_2);

            var podcasts = new List <IPodcastInfo>(2)
            {
                podcast1Mocker.GetMockedPodcastInfo(),
                podcast2Mocker.GetMockedPodcastInfo()
            };

            MockControlFile = new ControlFileMocker()
                              .ApplySourceRoot(SOURCE_ROOT)
                              .ApplyRetryWaitInSeconds(RETRY_TIME)
                              .ApplyDiagnosticRetainTemporaryFiles(DIAGS)
                              .ApplyMaximumNumberOfConcurrentDownloads(MAX_DOWNLOADS)
                              .ApplyFreeSpaceToLeaveOnDownload(FREE_DISK_SPACE_MB - 1)
                              .ApplyDiagnosticOutput(level)
                              .ApplyPodcasts(podcasts)
                              .GetMockedControlFile();

            A.CallTo(() => MockApplicationControlFileProvider.GetApplicationConfiguration()).Returns(MockControlFile);
        }
コード例 #2
0
        protected void SetupMockControlFileFor1Podcast()
        {
            var podcastMocker = new PodcastInfoMocker()
                                .ApplyFolder("folder1");

            MockControlFile = new ControlFileMocker()
                              .ApplySourceRoot("/sdcard/sourceroot")
                              .ApplyPlaylistFormat(PlaylistFormat.M3U)
                              .ApplyPodcasts(podcastMocker.GetMockedPodcastInfoAsList())
                              .GetMockedControlFile();

            A.CallTo(() => MockApplicationControlFileProvider.GetApplicationConfiguration()).Returns(MockControlFile);
        }
コード例 #3
0
        private void RefreshFeedList()
        {
            AllFeedItems.Clear();
            var cacheRoot   = "";
            var controlFile = ApplicationControlFileProvider.GetApplicationConfiguration();

            if (controlFile != null)
            {
                cacheRoot = controlFile.GetSourceRoot();
                foreach (var podcastInfo in controlFile.GetPodcasts())
                {
                    Logger.Debug(() => $"MainViewModel:RefreshFeedList {podcastInfo.Folder}");
                    var item = new PodcastFeedRecyclerItem()
                    {
                        PodcastFeed = podcastInfo
                    };
                    AllFeedItems.Add(item);
                }
            }
            var heading = ResourceProvider.GetQuantityString(Resource.Plurals.feed_list_heading, AllFeedItems.Count);

            Observables.SetCacheRoot?.Invoke(this, cacheRoot);
            Observables.SetFeedItems?.Invoke(this, Tuple.Create(heading, AllFeedItems));
        }
コード例 #4
0
        protected void SetupMockControlFileFor2Podcasts(DiagnosticOutputLevel level = DiagnosticOutputLevel.None)
        {
            podcast1Mocker = new PodcastInfoMocker()
                             .ApplyFolder(PODCAST_FOLDER_1);
            podcast2Mocker = new PodcastInfoMocker()
                             .ApplyFolder(PODCAST_FOLDER_2);

            var podcasts = new List <IPodcastInfo>(2)
            {
                podcast1Mocker.GetMockedPodcastInfo(),
                podcast2Mocker.GetMockedPodcastInfo()
            };

            MockControlFile = new ControlFileMocker()
                              .ApplySourceRoot(SOURCE_ROOT)
                              .ApplyPodcasts(podcasts)
                              .GetMockedControlFile();

            A.CallTo(() => MockApplicationControlFileProvider.GetApplicationConfiguration()).Returns(MockControlFile);
        }
コード例 #5
0
        public void FindEpisodesToDownload()
        {
            var controlFile = ApplicationControlFileProvider.GetApplicationConfiguration();

            Logger.Debug(() => $"DownloadViewModel:FindEpisodesToDownload");
            if (controlFile == null)
            {
                Logger.Warning(() => $"DownloadViewModel:FindEpisodesToDownload - no control file");
                return;
            }

            var noItemsText          = ResourceProvider.GetString(Resource.String.no_downloads_text);
            var activeConnectionType = NetworkHelper.ActiveNetworkType;

            Logger.Debug(() => $"DownloadViewModel:FindEpisodesToDownload Active = {activeConnectionType}");
            if (activeConnectionType == INetworkHelper.NetworkType.None)
            {
                noItemsText = ResourceProvider.GetString(Resource.String.no_network_text);
            }
            Observables.SetEmptyText?.Invoke(this, noItemsText);

            lock (SyncLock)
            {
                if (StartedFindingPodcasts)
                {
                    Logger.Warning(() => $"DownloadViewModel:FindEpisodesToDownload - ignoring, already initialised");
                    if (CompletedFindingPodcasts)
                    {
                        Observables.SetSyncItems?.Invoke(this, AllItems);
                        SetTitle();
                    }
                    else
                    {
                        Observables.StartProgress?.Invoke(this, FeedCount);
                    }
                    return;
                }
                StartedFindingPodcasts = true;
                MessageStore.Reset();
            }

            foreach (var item in controlFile.GetPodcasts())
            {
                FeedCount++;
            }

            Observables.StartProgress?.Invoke(this, FeedCount);

            // find the episodes to download
            AllItems.Clear();
            int count = 0;

            foreach (var podcastInfo in controlFile.GetPodcasts())
            {
                var episodesInThisFeed = PodcastEpisodeFinder.FindEpisodesToDownload(
                    controlFile.GetSourceRoot(),
                    controlFile.GetRetryWaitInSeconds(),
                    podcastInfo,
                    controlFile.GetDiagnosticRetainTemporaryFiles());
                foreach (var episode in episodesInThisFeed)
                {
                    var line = $"{episode.Id}, {episode.EpisodeTitle}";
                    Logger.Debug(() => $"DownloadViewModel:FindEpisodesToDownload {line}");
                    MessageStore.StoreMessage(episode.Id, line);
                    var item = new DownloadRecyclerItem()
                    {
                        SyncItem           = episode,
                        ProgressPercentage = 0,
                        Podcast            = podcastInfo,
                        Selected           = true
                    };
                    AllItems.Add(item);
                }
                count++;
                AnalyticsEngine.DownloadFeedEvent(episodesInThisFeed.Count);
                Observables.UpdateProgress?.Invoke(this, count);
            }
            CompletedFindingPodcasts = true;
            Observables.EndProgress?.Invoke(this, null);
            Observables.SetSyncItems?.Invoke(this, AllItems);
            SetTitle();
        }
コード例 #6
0
        public void FindItemsToDelete()
        {
            var controlFile = ApplicationControlFileProvider.GetApplicationConfiguration();

            Logger.Debug(() => $"PurgeViewModel:FindItemsToDelete");
            if (controlFile == null)
            {
                Logger.Warning(() => $"PurgeViewModel:FindItemsToDelete - no control file");
                return;
            }

            lock (SyncLock)
            {
                if (StartedFindingItems)
                {
                    Logger.Warning(() => $"PurgeViewModel:FindItemsToDelete - ignoring, already initialised");
                    if (CompletedFindingItems)
                    {
                        Observables.SetPurgeItems?.Invoke(this, AllItems);
                        SetTitle();
                    }
                    else
                    {
                        // we scan each feed twice
                        Observables.StartProgress?.Invoke(this, FeedCount * 2);
                    }
                    return;
                }
                StartedFindingItems = true;
            }

            foreach (var item in controlFile.GetPodcasts())
            {
                FeedCount++;
            }

            Observables.StartProgress?.Invoke(this, FeedCount * 2);

            // find the items to delete
            AllItems.Clear();
            int count = 0;

            // find the episodes to delete
            List <IFileInfo> allFilesToDelete = new List <IFileInfo>(20);

            foreach (var podcastInfo in controlFile.GetPodcasts())
            {
                IList <IFileInfo> filesToDeleteFromThisFeed = EpisodePurger.FindEpisodesToPurge(controlFile.GetSourceRoot(), podcastInfo);
                List <IFileInfo>  sortedFileList            = filesToDeleteFromThisFeed.OrderBy(item => item.Name).ToList();
                foreach (var file in sortedFileList)
                {
                    var line = $"File: {file.FullName}";
                    Logger.Debug(() => $"PurgeViewModel:FindItemsToDelete {line}");
                    var item = new PurgeRecyclerItem()
                    {
                        FileOrDirectoryItem = file,
                        Selected            = true
                    };
                    // this is for the recycler adapter
                    AllItems.Add(item);
                }
                // and this is so we can work out which folder will be empty
                allFilesToDelete.AddRange(filesToDeleteFromThisFeed);
                count++;
                Observables.UpdateProgress?.Invoke(this, count);
            }

            // find folders that can now be deleted
            foreach (var podcastInfo in controlFile.GetPodcasts())
            {
                IList <IDirectoryInfo> foldersToDeleteInThisFeed = EpisodePurger.FindEmptyFoldersToDelete(controlFile.GetSourceRoot(), podcastInfo, allFilesToDelete);
                List <IDirectoryInfo>  sortedDirList             = foldersToDeleteInThisFeed.OrderBy(item => item.FullName).ToList();
                foreach (var dir in sortedDirList)
                {
                    var line = $"Dir: {dir.FullName}";
                    Logger.Debug(() => $"PurgeViewModel:FindItemsToDelete {line}");
                    var item = new PurgeRecyclerItem()
                    {
                        FileOrDirectoryItem = dir,
                        Selected            = true
                    };
                    AllItems.Add(item);
                }
                count++;
                Observables.UpdateProgress?.Invoke(this, count);
            }

            CompletedFindingItems = true;
            Observables.EndProgress?.Invoke(this, null);
            Observables.SetPurgeItems?.Invoke(this, AllItems);
            SetTitle();
            AnalyticsEngine.PurgeScanEvent(GetItemsSelectedCount());
        }