Exemplo n.º 1
0
        private void ExecuteInfo(
            FixerLogicParameters parameters,
            ImageFixInfo info,
            string monthDirectory,
            ref int monthCount
            )
        {
            var fileInfo = info.FileInfo;
            var destPath = GetDestFilePath(fileInfo, monthDirectory);

            if (parameters.IsPreview)
            {
                OnNotifyMessage($"Copying {fileInfo.FullName} to {destPath}");
            }

            monthCount++;
            if (!parameters.IsPreview)
            {
                fileInfo.CopyTo(destPath, true);
            }
            //else
            //{
            //    System.Threading.Thread.Sleep(150);
            //}
            OnNotifyProcessed();
        }
Exemplo n.º 2
0
        private void ExecuteYearGroup(
            FixerLogicParameters parameters,
            System.IO.DirectoryInfo outputDirectory,
            IGrouping <int, ImageFixInfo> yearGroup,
            ref int totalCount
            )
        {
            var yearDirectory = System.IO.Path.Combine(outputDirectory.FullName, yearGroup.Key.ToString(CultureInfo.InvariantCulture));

            if (!System.IO.Directory.Exists(yearDirectory))
            {
                OnNotifyMessage($"Creating year directory {yearDirectory}.");
                if (!parameters.IsPreview)
                {
                    System.IO.Directory.CreateDirectory(yearDirectory);
                }
            }

            int yearCount        = 0;
            var yearGroupByMonth = yearGroup.GroupBy(o => new { Month = o.Month, MonthName = o.MonthName });

            foreach (var monthGroup in yearGroupByMonth)
            {
                ExecuteMonthGroup(parameters, yearDirectory, monthGroup.Key.Month, monthGroup.Key.MonthName, monthGroup, ref yearCount);
            }

            OnNotifyMessage($"Copied {yearCount} files to {yearDirectory}.");
            totalCount += yearCount;
        }
Exemplo n.º 3
0
        private void ExecuteMonthGroup(
            FixerLogicParameters parameters,
            string yearDirectory,
            int month, string monthName,
            IEnumerable <ImageFixInfo> monthGroup,
            ref int yearCount
            )
        {
            var dirName        = $"{month.ToString("d2")} {monthName}";
            var monthDirectory = System.IO.Path.Combine(yearDirectory, dirName);

            if (!System.IO.Directory.Exists(monthDirectory))
            {
                OnNotifyMessage($"Creating month directory {monthDirectory}.");

                if (!parameters.IsPreview)
                {
                    System.IO.Directory.CreateDirectory(monthDirectory);
                }
            }

            int monthCount = 0;

            foreach (var info in monthGroup)
            {
                ExecuteInfo(parameters, info, monthDirectory, ref monthCount);
            }

            OnNotifyMessage($"Copied {monthCount} files to {monthDirectory}.");
            yearCount += monthCount;
        }
Exemplo n.º 4
0
        public bool Execute(FixerLogicParameters parameters)
        {
            if (!System.IO.Directory.Exists(parameters.InputDirectory))
            {
                OnNotifyMessage($"Input directory {parameters.InputDirectory} does not exist.");
                return(false);
            }
            if (!System.IO.Directory.Exists(parameters.OutputDirectory))
            {
                OnNotifyMessage($"Output directory {parameters.OutputDirectory} does not exist.");
                return(false);
            }

            var inputDirectory = new System.IO.DirectoryInfo(parameters.InputDirectory);

            var files = EnumerateFiles(parameters, inputDirectory);

            var imageFixInfos = files
                                .Select(GetImageFixInfo)
                                .OrderBy(o => o.DateTaken)
                                .ToList();

            if (imageFixInfos.Count == 0)
            {
                OnNotifyMessage("No images to process.");
                return(false);
            }
            OnNotifyMaxCount(imageFixInfos.Count);

            var imageFixInfosByYear = imageFixInfos
                                      .GroupBy(o => o.Year);

            var outputDirectory = new System.IO.DirectoryInfo(parameters.OutputDirectory);

            int totalCount = 0;

            foreach (var yearGroup in imageFixInfosByYear)
            {
                ExecuteYearGroup(parameters, outputDirectory, yearGroup, ref totalCount);
            }

            OnNotifyMessage($"Copied {totalCount} total files.");

            return(true);
        }
Exemplo n.º 5
0
 private IEnumerable <System.IO.FileInfo> EnumerateFiles(FixerLogicParameters parameters, System.IO.DirectoryInfo inputDirectory)
 {
     return(inputDirectory.EnumerateFiles("*.*", parameters.RecurseInput ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly));
 }