Ejemplo n.º 1
0
        public void Setup()
        {
            ResetObservedResults();

            MockApplication = A.Fake <Application>();
            A.CallTo(() => MockApplication.PackageName).Returns("com.andrewandderek.podcastutilities");
            MockLogger           = A.Fake <ILogger>();
            MockResourceProvider = A.Fake <IResourceProvider>();
            MockFileUtilities    = A.Fake <IFileUtilities>();
            MockApplicationControlFileProvider = A.Fake <IApplicationControlFileProvider>();
            MockCrashReporter   = A.Fake <ICrashReporter>();
            MockAnalyticsEngine = A.Fake <IAnalyticsEngine>();
            MockEpisodePurger   = A.Fake <IEpisodePurger>();

            SetupResources();

            ViewModel = new PurgeViewModel(
                MockApplication,
                MockLogger,
                MockResourceProvider,
                MockApplicationControlFileProvider,
                MockEpisodePurger,
                MockFileUtilities,
                MockCrashReporter,
                MockAnalyticsEngine
                );
            ViewModel.Observables.Title          += SetTitle;
            ViewModel.Observables.StartProgress  += StartProgress;
            ViewModel.Observables.UpdateProgress += UpdateProgress;
            ViewModel.Observables.EndProgress    += EndProgress;
            ViewModel.Observables.SetPurgeItems  += SetPurgeItems;
            ViewModel.Observables.DisplayMessage += DisplayMessage;
        }
Ejemplo n.º 2
0
 public PurgeViewModel(
     Application app,
     ILogger logger,
     IResourceProvider resourceProvider,
     IApplicationControlFileProvider applicationControlFileProvider,
     IEpisodePurger episodePurger,
     IFileUtilities fileUtilities,
     ICrashReporter crashReporter,
     IAnalyticsEngine analyticsEngine) : base(app)
 {
     Logger           = logger;
     ResourceProvider = resourceProvider;
     ApplicationControlFileProvider = applicationControlFileProvider;
     EpisodePurger   = episodePurger;
     FileUtilities   = fileUtilities;
     CrashReporter   = crashReporter;
     AnalyticsEngine = analyticsEngine;
 }
Ejemplo n.º 3
0
        private static void DoDelete(IList <IFileInfo> files, IList <IDirectoryInfo> folders)
        {
            IFileUtilities fileUtilities        = _iocContainer.Resolve <IFileUtilities>();
            IEpisodePurger podcastEpisodePurger = _iocContainer.Resolve <IEpisodePurger>();

            foreach (IFileInfo fileInfo in files)
            {
                fileUtilities.FileDelete(fileInfo.FullName);
            }
            foreach (IDirectoryInfo folder in folders)
            {
                try
                {
                    podcastEpisodePurger.PurgeFolder(folder);
                }
                catch (Exception exception)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Cannot delete folder: {0}", folder.FullName);
                    Console.WriteLine(exception.ToString());
                    Console.ResetColor();
                }
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            DisplayBanner();
            if (args.Length < 1)
            {
                DisplayHelp();
                return;
            }

            _iocContainer = InitializeIocContainer();
            _control      = new ReadOnlyControlFile(args[0]);
            if (args.Count() > 1)
            {
                _quiet = args[1].Contains('q');
            }

            // find the episodes to delete
            List <IFileInfo> allFilesToDelete     = new List <IFileInfo>(20);
            IEpisodePurger   podcastEpisodePurger = _iocContainer.Resolve <IEpisodePurger>();

            foreach (PodcastInfo podcastInfo in _control.GetPodcasts())
            {
                IList <IFileInfo> filesToDeleteFromThisFeed = podcastEpisodePurger.FindEpisodesToPurge(_control.GetSourceRoot(), podcastInfo);
                allFilesToDelete.AddRange(filesToDeleteFromThisFeed);
            }
            // find folders that can now be deleted
            List <IDirectoryInfo> allFoldersToDelete = new List <IDirectoryInfo>(10);

            foreach (PodcastInfo podcastInfo in _control.GetPodcasts())
            {
                IList <IDirectoryInfo> foldersToDeleteInThisFeed = podcastEpisodePurger.FindEmptyFoldersToDelete(_control.GetSourceRoot(), podcastInfo, allFilesToDelete);
                allFoldersToDelete.AddRange(foldersToDeleteInThisFeed);
            }

            if (allFilesToDelete.Count == 0 && allFoldersToDelete.Count == 0)
            {
                Console.WriteLine("There is nothing to delete");
                return;
            }

            if (_quiet)
            {
                DoDelete(allFilesToDelete, allFoldersToDelete);
            }
            else
            {
                if (allFilesToDelete.Count > 0)
                {
                    Console.WriteLine("Files:");
                    foreach (IFileInfo fileInfo in allFilesToDelete)
                    {
                        Console.WriteLine("{0}", fileInfo.FullName);
                    }
                }
                if (allFoldersToDelete.Count > 0)
                {
                    Console.WriteLine("Folders:");
                    foreach (IDirectoryInfo folder in allFoldersToDelete)
                    {
                        Console.WriteLine("{0}", folder.FullName);
                    }
                }
                Console.WriteLine("OK to delete {0} files and {1} folders? (y/n) ", allFilesToDelete.Count, allFoldersToDelete.Count);
                string answer;
                do
                {
                    char key = Convert.ToChar(Console.Read());
                    answer = key.ToString().ToLower();
                } while (answer != "y" && answer != "n");
                if (answer == "y")
                {
                    Console.WriteLine("Deleting {0} files and {1} folders", allFilesToDelete.Count, allFoldersToDelete.Count);
                    DoDelete(allFilesToDelete, allFoldersToDelete);
                }
                else
                {
                    Console.WriteLine("No files deleted");
                }
            }

            Console.WriteLine("Done");
        }