/// <summary> /// When the file is not supported or does not exist return status /// </summary> /// <param name="subPath">relative path</param> /// <returns>item with status</returns> private FileIndexItem CheckForStatusNotOk(string subPath) { var statusItem = new FileIndexItem(subPath) { Status = FileIndexItem.ExifStatus.Ok }; // File extension is not supported if (!ExtensionRolesHelper.IsExtensionSyncSupported(subPath)) { statusItem.Status = FileIndexItem.ExifStatus.OperationNotSupported; return(statusItem); } // File check if jpg #not corrupt var imageFormat = ExtensionRolesHelper.GetImageFormat(_subPathStorage.ReadStream(subPath, 160)); if (imageFormat == ExtensionRolesHelper.ImageFormat.notfound) { statusItem.Status = FileIndexItem.ExifStatus.NotFoundSourceMissing; return(statusItem); } // ReSharper disable once InvertIf if (!ExtensionRolesHelper.ExtensionSyncSupportedList.Contains(imageFormat.ToString())) { statusItem.Status = FileIndexItem.ExifStatus.OperationNotSupported; return(statusItem); } return(statusItem); }
// Define the event handlers. /// <summary> /// Specify what is done when a file is changed. e.FullPath /// </summary> /// <param name="source"></param> /// <param name="e"></param> internal void OnChanged(object source, FileSystemEventArgs e) { if (e.FullPath.EndsWith(".tmp") || !ExtensionRolesHelper.IsExtensionSyncSupported(e.FullPath)) { return; } _webLogger.LogDebug($"[DiskWatcher] " + $"{e.FullPath} OnChanged ChangeType is: {e.ChangeType} " + DateTimeDebug()); _queueProcessor.QueueInput(e.FullPath, null, e.ChangeType); // Specify what is done when a file is changed, created, or deleted. }
public Task <List <ImportIndexItem> > Preflight(List <string> inputFileFullPaths, ImportSettingsModel importSettings) { var results = new List <ImportIndexItem>(); foreach (var inputFileFullPath in inputFileFullPaths) { // if the item fails var importIndexFileError = new ImportIndexItem { FilePath = "/" + FilenamesHelper.GetFileName(inputFileFullPath), SourceFullFilePath = "~/temp/test", FileHash = "FAKE", MakeModel = "added if the item fails", Status = ImportStatus.FileError }; // Check if extension is correct if (!ExtensionRolesHelper.IsExtensionSyncSupported(inputFileFullPath)) { results.Add(importIndexFileError); } // Check if the file is correct var imageFormat = ExtensionRolesHelper.GetImageFormat( _selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem) .ReadStream(inputFileFullPath, 160)); if (!ExtensionRolesHelper.ExtensionSyncSupportedList.Contains($"{imageFormat}")) { results.Add(importIndexFileError); } results.Add(new ImportIndexItem { Id = 4, SourceFullFilePath = inputFileFullPath, FilePath = inputFileFullPath, Status = ImportStatus.Ok, FileHash = "FAKE", MakeModel = "added okay", FileIndexItem = new FileIndexItem() { FileHash = "FAKE_OK", FilePath = inputFileFullPath } }); } PreflightList.AddRange(results); return(Task.FromResult(results)); }
/// <summary> /// Specify what is done when a file is renamed. e.OldFullPath to e.FullPath /// </summary> /// <param name="source">object source (ignored)</param> /// <param name="e">arguments</param> internal void OnRenamed(object source, RenamedEventArgs e) { _webLogger.LogInformation($"DiskWatcher {e.OldFullPath} OnRenamed to: {e.FullPath}" + DateTimeDebug()); if (e.OldFullPath.EndsWith(".tmp") || !ExtensionRolesHelper.IsExtensionSyncSupported(e.OldFullPath)) { _queueProcessor.QueueInput(e.FullPath, null, WatcherChangeTypes.Created); return; } if (e.FullPath.EndsWith(".tmp") || !ExtensionRolesHelper.IsExtensionSyncSupported(e.FullPath)) { _queueProcessor.QueueInput(e.OldFullPath, null, WatcherChangeTypes.Deleted); return; } _queueProcessor.QueueInput(e.OldFullPath, e.FullPath, WatcherChangeTypes.Renamed); }
internal async Task <ImportIndexItem> PreflightPerFile(KeyValuePair <string, bool> inputFileFullPath, ImportSettingsModel importSettings) { if (_appSettings.ImportIgnore.Any(p => inputFileFullPath.Key.Contains(p))) { if (_appSettings.IsVerbose()) { _console.WriteLine($"❌ skip due rules: {inputFileFullPath.Key} "); } return(new ImportIndexItem { Status = ImportStatus.Ignore, FilePath = inputFileFullPath.Key, SourceFullFilePath = inputFileFullPath.Key, AddToDatabase = DateTime.UtcNow }); } if (!inputFileFullPath.Value || !_filesystemStorage.ExistFile(inputFileFullPath.Key)) { if (_appSettings.IsVerbose()) { _console.WriteLine($"❌ not found: {inputFileFullPath.Key}"); } return(new ImportIndexItem { Status = ImportStatus.NotFound, FilePath = inputFileFullPath.Key, SourceFullFilePath = inputFileFullPath.Key, AddToDatabase = DateTime.UtcNow }); } var imageFormat = ExtensionRolesHelper.GetImageFormat( _filesystemStorage.ReadStream(inputFileFullPath.Key, 160)); // Check if extension is correct && Check if the file is correct if (!ExtensionRolesHelper.IsExtensionSyncSupported(inputFileFullPath.Key) || !ExtensionRolesHelper.IsExtensionSyncSupported($".{imageFormat}")) { if (_appSettings.IsVerbose()) { _console.WriteLine($"❌ extension not supported: {inputFileFullPath.Key}"); } return(new ImportIndexItem { Status = ImportStatus.FileError, FilePath = inputFileFullPath.Key, SourceFullFilePath = inputFileFullPath.Key }); } var hashList = await new FileHash(_filesystemStorage).GetHashCodeAsync(inputFileFullPath.Key); if (!hashList.Value) { if (_appSettings.IsVerbose()) { _console.WriteLine($"❌ FileHash error {inputFileFullPath.Key}"); } return(new ImportIndexItem { Status = ImportStatus.FileError, FilePath = inputFileFullPath.Key, SourceFullFilePath = inputFileFullPath.Key }); } if (importSettings.IndexMode && await _importQuery !.IsHashInImportDbAsync(hashList.Key)) { if (_appSettings.IsVerbose()) { _console.WriteLine($"🤷 Ignored, exist already {inputFileFullPath.Key}"); } return(new ImportIndexItem { Status = ImportStatus.IgnoredAlreadyImported, FilePath = inputFileFullPath.Key, FileHash = hashList.Key, AddToDatabase = DateTime.UtcNow, SourceFullFilePath = inputFileFullPath.Key }); } // Only accept files with correct meta data // Check if there is a xmp file that contains data var fileIndexItem = _readMetaHost.ReadExifAndXmpFromFile(inputFileFullPath.Key); // Parse the filename and create a new importIndexItem object var importIndexItem = ObjectCreateIndexItem(inputFileFullPath.Key, imageFormat, hashList.Key, fileIndexItem, importSettings.ColorClass, _filesystemStorage.Info(inputFileFullPath.Key).Size); // Update the parent and filenames importIndexItem = ApplyStructure(importIndexItem, importSettings.Structure); return(importIndexItem); }