public async Task UpdateTransformations_ShouldUpdate_Description_IndexModeOn() { var storage = new FakeIStorage( new List <string> { "/" }, new List <string> { "/test.jpg", "/test.xmp" }, new List <byte[]> { CreateAnPng.Bytes, CreateAnXmp.Bytes }); var appSettings = new AppSettings(); var updateImportTransformations = new UpdateImportTransformations(new FakeIWebLogger(), new FakeExifTool(storage, appSettings), new FakeSelectorStorage(storage), appSettings); var query = new FakeIQuery(); await query.AddItemAsync(new FileIndexItem("/test.jpg"){ FileHash = "test" }); UpdateImportTransformations.QueryUpdateDelegate updateItemAsync = query.UpdateItemAsync; await updateImportTransformations.UpdateTransformations(updateItemAsync, new FileIndexItem("/test.jpg"){ Description = "test-ung" }, -1, true, true); var updatedItem = await query.GetObjectByFilePathAsync("/test.jpg"); Assert.AreEqual("test-ung", updatedItem.Description); }
public async Task UpdateTransformations_ShouldNotUpdate_IndexOff() { var storage = new FakeIStorage( new List <string> { "/" }, new List <string> { "/test.jpg", "/test.xmp" }, new List <byte[]> { CreateAnPng.Bytes, CreateAnXmp.Bytes }); var appSettings = new AppSettings(); var updateImportTransformations = new UpdateImportTransformations(new FakeIWebLogger(), new FakeExifTool(storage, appSettings), new FakeSelectorStorage(storage), appSettings); var query = new FakeIQuery(); await query.AddItemAsync(new FileIndexItem("/test.jpg"){ FileHash = "test" }); UpdateImportTransformations.QueryUpdateDelegate updateItemAsync = query.UpdateItemAsync; await updateImportTransformations.UpdateTransformations(updateItemAsync, new FileIndexItem("/test.jpg"){ ColorClass = ColorClassParser.Color.Typical }, 0, false, false); var updatedItem = await query.GetObjectByFilePathAsync("/test.jpg"); // Are NOT equal! Assert.AreNotEqual(ColorClassParser.Color.Typical, updatedItem.ColorClass); }
internal async Task <ImportIndexItem> Importer(ImportIndexItem importIndexItem, ImportSettingsModel importSettings) { if (importIndexItem.Status != ImportStatus.Ok) { return(importIndexItem); } // True when exist and file type is raw var xmpExistForThisFileType = ExistXmpSidecarForThisFileType(importIndexItem); if (xmpExistForThisFileType || (_appSettings.ExifToolImportXmpCreate && ExtensionRolesHelper.IsExtensionForceXmp(importIndexItem.FilePath))) { // When a xmp file already exist (only for raws) // AND when this created afterwards with the ExifToolImportXmpCreate setting (only for raws) importIndexItem.FileIndexItem.AddSidecarExtension("xmp"); } // Add item to database await AddToQueryAndImportDatabaseAsync(importIndexItem, importSettings); // Copy if (_appSettings.IsVerbose()) { _logger.LogInformation("[Import] Next Action = Copy" + $" {importIndexItem.SourceFullFilePath} {importIndexItem.FilePath}"); } using (var sourceStream = _filesystemStorage.ReadStream(importIndexItem.SourceFullFilePath)) await _subPathStorage.WriteStreamAsync(sourceStream, importIndexItem.FilePath); // Copy the sidecar file if (xmpExistForThisFileType) { var xmpSourceFullFilePath = ExtensionRolesHelper.ReplaceExtensionWithXmp(importIndexItem.SourceFullFilePath); var destinationXmpFullPath = ExtensionRolesHelper.ReplaceExtensionWithXmp(importIndexItem.FilePath); _filesystemStorage.FileCopy(xmpSourceFullFilePath, destinationXmpFullPath); } await CreateSideCarFile(importIndexItem, xmpExistForThisFileType); // Run Exiftool to Update for example colorClass UpdateImportTransformations.QueryUpdateDelegate?updateItemAsync = null; if (importSettings.IndexMode) { updateItemAsync = new QueryFactory( new SetupDatabaseTypes(_appSettings), _query, _memoryCache, _appSettings, _logger).Query() !.UpdateItemAsync; } importIndexItem.FileIndexItem = await _updateImportTransformations.UpdateTransformations(updateItemAsync, importIndexItem.FileIndexItem, importSettings.ColorClass, importIndexItem.DateTimeFromFileName, importSettings.IndexMode); DeleteFileAfter(importSettings, importIndexItem); if (_appSettings.IsVerbose()) { _console.Write("+"); } return(importIndexItem); }