/// <summary>
 /// Inserts a ScannedFile into the storage backend
 /// </summary>
 /// <param name="scannedFile">The ScannedFile to insert</param>
 public async Task InsertScannedFileAsync(ScannedFile scannedFile)
 {
     if (!await ScannedFilesContains(scannedFile))
     {
         _scannedFiles.InsertData(scannedFile);
     }
 }
예제 #2
0
        public override bool Equals(object obj)
        {
            ScannedFileHashComparer comparer         = new ScannedFileHashComparer();
            ScannedFile             otherScannedFile = obj as ScannedFile;

            bool isEqual = this.Name.Equals(otherScannedFile.Name) &&
                           this.Path.Equals(otherScannedFile.Path) &&
                           this.Length.Equals(otherScannedFile.Length) &&
                           comparer.Equals(this.Hash, otherScannedFile.Hash);

            return(isEqual);
        }
        /// <summary>
        /// Iterate through the ScannedFiles to determine if there is an equal ScannedFile
        /// </summary>
        /// <param name="scannedFile">The ScannedFile to compare against the ScannedFiles in the data cache</param>
        /// <returns>true/false if the ScannedFile is contained in the data cache</returns>
        private async Task <bool> ScannedFilesContains(ScannedFile scannedFile)
        {
            Task <bool> task = Task.Run(() =>
            {
                bool contains = false;
                foreach (ScannedFile contextScannedFile in _scannedFiles.ListData())
                {
                    contains |= contextScannedFile.Equals(scannedFile);
                }
                return(contains);
            });

            return(await task);
        }
        /// <summary>
        /// Scan a file to the storage backend and update the progress
        /// </summary>
        /// <param name="filePath">The location to add to the storage backend</param>
        /// <param name="progress">The IProgress to update the progress on.
        /// Progress is updated with the following formula: index * 100 / totalCount</param>
        internal async Task ScanFile(string filePath, IProgress <int> progress, int index, int totalCount)
        {
            if (_fileSystem.File.Exists(filePath))
            {
                FileHash    fileHash    = new FileHash(_fileSystem);
                ScannedFile scannedFile = new ScannedFile();
                scannedFile.Name = _fileSystem.Path.GetFileName(filePath);
                scannedFile.Path = _fileSystem.Path.GetFullPath(filePath);
                scannedFile.Hash = await fileHash.ComputeFileHashAsync(filePath);

                await _service.InsertScannedFileAsync(scannedFile);
            }
            if (progress != null)
            {
                progress.Report(index * 100 / totalCount);
            }
        }