Exemple #1
0
        public void TestRuntimeSettingsOptionsImagesSourcePathSubstitution()
        {
            string[] args                = { "something", "cool" };
            var      options             = new Options();
            var      optionsParseSuccess = Parser.Default.ParseArguments(args, options);

            runtimeSettings = new RuntimeSettings(imagesDirectory, destinationBaseDirPhotos,
                                                  destinationBaseDirVideos);
            // test options substitution by overriding imagesSourcePath
            options.ImagesSourcePath = imagesDirectory2;
            Assert.AreNotEqual(runtimeSettings.FullPathToMedia, options.ImagesSourcePath);
            runtimeSettings.Activate(options);
            // now after substituion they will be equal
            Assert.AreEqual(runtimeSettings.FullPathToMedia, options.ImagesSourcePath);
        }
Exemple #2
0
        public void TestRuntimeSettingsFilterSubstitution()
        {
            string[] args                = { "something", "cool" };
            var      options             = new Options();
            var      optionsParseSuccess = Parser.Default.ParseArguments(args, options);

            runtimeSettings = new RuntimeSettings(imagesDirectory, destinationBaseDirPhotos,
                                                  destinationBaseDirVideos);
            // test filter substitution
            options.FilterDay = 1;
            Assert.AreNotEqual(runtimeSettings.FilterDay, options.FilterDay);
            runtimeSettings.Activate(options);
            // now after substituion they will be equal
            Assert.AreEqual(runtimeSettings.FilterDay, options.FilterDay);
        }
Exemple #3
0
        public void TestRuntimeSettingsActivateCheckThatPathsExist()
        {
            string[] args                = { "something", "cool" };
            var      options             = new Options();
            var      optionsParseSuccess = Parser.Default.ParseArguments(args, options);

            runtimeSettings = new RuntimeSettings(imagesDirectory, destinationBaseDirPhotos,
                                                  destinationBaseDirVideos);
            // use defined but non-existant directory
            options.ImagesDestinationPath = destinationBaseDirSubstitutionTest2;
            var exception =
                Assert.Throws <DirectoryNotFoundException>(() => runtimeSettings.Activate(options));

            Assert.That(exception.Message, Is.EqualTo($"Directory {destinationBaseDirSubstitutionTest2} not found."));
        }
Exemple #4
0
        public static List <MediaFile> FindPics()
        {
            string[] args                = { "something", "cool" };
            var      options             = new Options();
            var      optionsParseSuccess = Parser.Default.ParseArguments(args, options);
            var      settings            = new Settings();

            var runtimeSettings = new RuntimeSettings(settings.sourcePath, settings.photosDestinationPath,
                                                      settings.videosDestinationPath);

            runtimeSettings.Activate(options);
            var imagesFiltered = Images.FindImagesFiltered(runtimeSettings);

            return(imagesFiltered);
        }
Exemple #5
0
        public static void MovePics()
        {
            string[] args                = { "something", "cool" };
            var      options             = new Options();
            var      optionsParseSuccess = Parser.Default.ParseArguments(args, options);
            var      settings            = new Settings();

            var runtimeSettings = new RuntimeSettings(settings.sourcePath, settings.photosDestinationPath,
                                                      settings.videosDestinationPath);

            runtimeSettings.Activate(options);
            var imagesFiltered = Images.FindImagesFiltered(runtimeSettings);

            foreach (var image in imagesFiltered)
            {
                Images.Move(image, runtimeSettings.DestinationBaseDirPhotos,
                            runtimeSettings.DestinationBaseDirVideos, false);
            }
        }
Exemple #6
0
        private static void Main(string[] args)
        {
            // Parse arguments using CommandLine module
            var options             = new Options();
            var optionsParseSuccess = Parser.Default.ParseArguments(args, options);

            if (!optionsParseSuccess)
            {
                Die("Invalid options specified, please see above for supported options.");
            }

            // read settings
            var settings = new Settings();

            // handle "FirstRun" case where the user is running the app for the first time or the settings have been wiped
            FirstRun(settings);
            // create run time settings
            var runtimeSettings = new RuntimeSettings(settings.sourcePath, settings.photosDestinationPath,
                                                      settings.videosDestinationPath);

            try
            {
                runtimeSettings.Activate(options);
            }
            catch (DirectoryNotFoundException e)
            {
                Die(e.Message);
            }

            // search for images and videos
            Console.WriteLine($"Searching in {runtimeSettings.FullPathToMedia}");
            var imagesFiltered = Images.FindImagesFiltered(runtimeSettings);

            if (imagesFiltered.Count == 0)
            {
                Console.WriteLine("No images found matching the filter criteria");
                Environment.Exit(0);
            }
            Console.WriteLine($" {imagesFiltered.Count} images found");
            var imagesCount = imagesFiltered.Count;

            // present to the user the picture list and ask for confirmation to move
            foreach (var image in imagesFiltered)
            {
                try
                {
                    Images.Move(image, runtimeSettings.DestinationBaseDirPhotos,
                                runtimeSettings.DestinationBaseDirVideos);
                }
                catch (Exception ex)
                {
                    if (ex is FilesAreTheSameException)
                    {
                        Console.WriteLine($"Files are the same: {image}");
                        imagesCount -= 1;
                    }
                    else if (ex is FilesAreTheSameButContentsDifferException)
                    {
                        Console.WriteLine($"Files are the same, but contents are different: {image}");
                        Console.WriteLine("This is not normal and needs checking.");
                        imagesCount -= 1;
                    }
                }
            }
            if (imagesCount < imagesFiltered.Count)
            {
                Console.WriteLine("Please handle the exceptions. Not all images can be moved.");
                Environment.Exit(0);
            }
            var response = ConfirmContinue("Do you want to continue and move these images?");

            if (response)
            {
                foreach (var image in imagesFiltered)
                {
                    Images.Move(image, runtimeSettings.DestinationBaseDirPhotos,
                                runtimeSettings.DestinationBaseDirVideos, false);
                }
            }
            else
            {
                Console.WriteLine("Move aborted.");
                Environment.Exit(0);
            }
        }