예제 #1
0
 public virtual void Validate()
 {
     char[] invalid = Path.GetInvalidFileNameChars();
     if (FileInclusions.Any(ext => ext.Any(c => invalid.Contains(c))))
     {
         throw new ArgumentException("One or more file extensions are not valid");
     }
     if (MinSize < 0)
     {
         throw new ArgumentException("The minimum file size must be a positive number");
     }
     if (MaxSize <= MinSize)
     {
         throw new ArgumentException("The maximum size must be greater than the minimum size");
     }
     if (string.IsNullOrEmpty(SourceDirectory) && !SourceDirectoryCurrent)
     {
         throw new ArgumentException("The source directory can't be empty");
     }
     if (SourceDirectoryCurrent && !string.IsNullOrEmpty(SourceDirectory))
     {
         throw new ArgumentException("The --source-current and --source options can't be used at the same time");
     }
     if (!string.IsNullOrEmpty(SourceDirectory))
     {
         invalid = Path.GetInvalidPathChars();
         if (SourceDirectory.Any(c => invalid.Contains(c)))
         {
             throw new ArgumentException("The source directory isn't valid");
         }
         if (!Directory.Exists(SourceDirectory))
         {
             throw new ArgumentException("The source directory doesn't exist");
         }
     }
     if (FileInclusions.Any() && FileExclusions.Any())
     {
         throw new ArgumentException("The list of extensions to exclude must be empty when other extensions to look for are specified");
     }
     if (Preset.HasValue && (FileInclusions.Any() || FileExclusions.Any()))
     {
         throw new ArgumentException("The preset option cannot be used with --include or --exclude");
     }
 }
예제 #2
0
 public void Validate()
 {
     char[] invalid = Path.GetInvalidFileNameChars();
     if (FileInclusions.Any(ext => ext.Any(c => invalid.Contains(c)) || ext.Contains('.')))
     {
         throw new ArgumentException("One or more file extensions are not valid");
     }
     if (FileExclusions.Any(ext => ext.Any(c => invalid.Contains(c)) || ext.Contains('.')))
     {
         throw new ArgumentException("One or more file extensions are not valid");
     }
     invalid = Path.GetInvalidPathChars();
     if (DirExclusions.Any(ext => ext.Contains(Path.DirectorySeparatorChar) || ext.Any(c => invalid.Contains(c))))
     {
         throw new ArgumentException("One or more dir exclusions are not valid");
     }
     if (!string.IsNullOrEmpty(Id) && (Id.Contains(Path.DirectorySeparatorChar) || Id.Any(c => invalid.Contains(c))))
     {
         throw new ArgumentException("The backup id is not valid");
     }
     if (MaxSize <= 100)
     {
         throw new ArgumentException("The maximum size must be at least 100KB");
     }
     if (string.IsNullOrEmpty(SourceDirectory) && !SourceDirectoryCurrent)
     {
         throw new ArgumentException("The source directory can't be empty");
     }
     if (SourceDirectoryCurrent && !string.IsNullOrEmpty(SourceDirectory))
     {
         throw new ArgumentException("The --source-current and --source options can't be used at the same time");
     }
     if (!string.IsNullOrEmpty(SourceDirectory))
     {
         invalid = Path.GetInvalidPathChars();
         if (SourceDirectory.Any(c => invalid.Contains(c)))
         {
             throw new ArgumentException("The source directory isn't valid");
         }
         if (!Directory.Exists(SourceDirectory))
         {
             throw new ArgumentException("The source directory doesn't exist");
         }
     }
     if (!Directory.Exists(TargetDirectory))
     {
         throw new ArgumentException("The target directory doesn't exist");
     }
     if (FileInclusions.Any() && FileExclusions.Any())
     {
         throw new ArgumentException("The list of extensions to exclude must be empty when other extensions to look for are specified");
     }
     if (Preset != ExtensionsPreset.None && (FileInclusions.Any() || FileExclusions.Any()))
     {
         throw new ArgumentException("The preset option cannot be used with --include or --exclude");
     }
     if (Threads == 0 || Threads < -1)
     {
         throw new ArgumentException("Invalid number of threads");
     }
     if (Multithread && Threads == 1)
     {
         throw new ArgumentException("Do you really want to multithread with just a single thread?");
     }
 }