Example #1
0
        public FileAnalysis(DirectoryAnalysis parent, string filePath, DateTime dateCategoryCurrently, DateTime dateCategoryDetected)
            : this(parent, filePath)
        {
            DateCategoryCurrently = dateCategoryCurrently;
            DateCategoryDetected = dateCategoryDetected;

            if (DateCategoryDetected == DateTime.MinValue)
                DateCategoryDetected = dateCategoryCurrently;

            if (DateCategoryDetected.Date == DateCategoryCurrently.Date)
                return;

            var correctDir = $"{parent.PathToDir}\\{DateCategoryDetected.ToString("yyyy-MM-dd")}\\";

            // If destination already has file then preserve with a unique file name
            CorrectedFilePath = correctDir + Path.GetFileName(filePath);
            var hasConflict = File.Exists(CorrectedFilePath);

            // Rename the file with a GUID if there is a naming conflict in the new category folder
            if (!hasConflict)
                return;

            CorrectedFilePath = $"{correctDir}{Path.GetFileNameWithoutExtension(filePath)}_{Guid.NewGuid()}{Path.GetExtension(filePath)}";
            if (File.Exists(CorrectedFilePath))
            {
                CorrectedFilePath = null; // Don't move it if no new file path can be assigned
                // ERROR!!!
                //throw new InvalidOperationException($"Unable to resolve file conflict as a file with the same resolution name already exists. This is a development issue, please consider raising an issue. File path: '{newFilePath}'");
            }
        }
Example #2
0
        public void AddDirectory(DirectoryAnalysis dirInfo)
        {
            _directories.Add(dirInfo);

            // if the directory has a suffix then add it to the list of possible suffixes to use!
            // this can be used in the UI to allow users to choose from different folders for the same
            // date in the destination
            if (!string.IsNullOrWhiteSpace(dirInfo.Suffix))
            {
                if( !Suffixes.ContainsKey(dirInfo.DateCategory.Date))
                    Suffixes[dirInfo.DateCategory.Date] = new List<DirectoryAnalysis>();

                Suffixes[dirInfo.DateCategory.Date].Add(dirInfo);
            }
        }
Example #3
0
 public FileAnalysis(DirectoryAnalysis parent, string filePath)
 {
     Parent = parent;
     FilePath = filePath;
     DateCategoryCurrently = DateCategoryDetected = DateTime.MinValue;
 }