/// <summary>
        /// Prepares a Archive without hashing any files.</summary>
        /// <param name="directoryPath">The directory thas should be scanned.</param>
        /// <param name="cancellationToken">Cancellation token for the async operation.</param>
        /// <param name="progress">Progress object used to report the progress of the operation.</param>
        /// <param name="statusText">Progress object used to provide feedback over the current status of the operation.</param>
        /// <param name="label">The display name for the new archive.</param>
        private async Task <Archive> PrepareArchiveAsync(DirectoryInfo directoryPath, CancellationToken cancellationToken, IProgress <int> progress, IProgress <string> statusText, string label = "")
        {
            if (!Directory.Exists(directoryPath.FullName))
            {
                MessageService.SendMessage(this, "ScanLogicException", new ApplicationException("Directory " + directoryPath.FullName + "could not be found."));

                return(null);
            }

            if (statusText != null)
            {
                statusText.Report("Scanning logical volumes");
            }

            var stagingVolume = new LogicalVolume(directoryPath);

            if (stagingVolume.SerialNumber is null || stagingVolume.MountPoint is null || stagingVolume.IsConnected == false)
            {
                MessageService.SendMessage(this, "ScanLogicException", new ApplicationException("Could not scan the logical volume for " + directoryPath.FullName));
                return(null);
            }

            var stagingArchive = new Archive(directoryPath, stagingVolume, Exclusions.ToList());

            if (!string.IsNullOrWhiteSpace(label))
            {
                stagingArchive.Label = label;
            }

            // Up to this point the function should be fast enough that we don't need
            // to check for task cancellation

            if (statusText != null)
            {
                statusText.Report("Getting file list");
            }

            await stagingArchive.ScanFilesAsync(cancellationToken, statusText);

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var stagingArchiveNodes = stagingArchive.GetFileDirectories();

            stagingArchiveNodes.AddRange(stagingArchive.GetFileNodes());
            if (stagingArchiveNodes is null || stagingArchiveNodes.Count == 0)
            {
                // There is either an issue with the provided directory or it's
                // on the exclusion list. In either case, abort the function
                MessageService.SendMessage(this, "ScanLogicException", new ApplicationException("Could not access the scan directory: " + directoryPath.FullName));
                return(null);
            }

            return(stagingArchive);
        }
        /// <summary>
        /// Adds the specified string collection of file exclusions.</summary>
        /// <param name="writeToDb">If true, the object will be written to the Database.</param>
        public async Task <LogicalVolume> AddLogicalVolume(LogicalVolume volume, bool writeToDb)
        {
            if (LogicalVolumes.Contains(volume))
            {
                return(LogicalVolumes.First(x => x.Equals(volume)));
            }

            LogicalVolumes.Add(volume);
            if (writeToDb)
            {
                await Database.InsertLogicalVolumeAsync(volume);
            }

            return(volume);
        }
Beispiel #3
0
        public Archive(DirectoryInfo directory, LogicalVolume drive, List <string> exclusions) : this()
        {
            this.Volume = drive;
            var pathRoot = Path.GetPathRoot(directory.FullName);

            if (directory.FullName == pathRoot)
            {
                // Selected path is the root of a drive
                this.rootDirectoryPath = @"\";
            }
            else
            {
                this.RootDirectoryPath = directory.FullName.Substring(Path.GetPathRoot(directory.FullName).Length);
            }

            //this.RootDirectory = directory.FullName.Substring(Path.GetPathRoot(directory.FullName).Length);
            this.exclusions = exclusions;

            if (string.IsNullOrWhiteSpace(this.Label))
            {
                this.Label = drive.MountPoint;
            }
        }