Esempio n. 1
0
        public void ExifToolCmdHelper_Update_UpdateLocationAltitudeCommandTest()
        {
            var updateModel = new FileIndexItem
            {
                LocationAltitude = -41,
            };
            var comparedNames = new List <string> {
                nameof(FileIndexItem.LocationAltitude).ToLowerInvariant(),
            };

            var folderPaths = new List <string> {
                "/"
            };

            var inputSubPaths = new List <string> {
                "/test.jpg"
            };

            var storage =
                new FakeIStorage(folderPaths, inputSubPaths, null);
            var fakeExifTool = new FakeExifTool(storage, _appSettings);

            var helperResult = new ExifToolCmdHelper(fakeExifTool,
                                                     storage, storage,
                                                     new FakeReadMeta()).Update(updateModel, inputSubPaths, comparedNames);

            Assert.AreEqual(true, helperResult.Contains("-GPSAltitude=\"-41"));
            Assert.AreEqual(true, helperResult.Contains("gpsaltituderef#=\"1"));
        }
Esempio n. 2
0
        public void ExifToolCmdHelper_UpdateTest()
        {
            var updateModel = new FileIndexItem
            {
                Tags             = "tags",
                Description      = "Description",
                Latitude         = 52,
                Longitude        = 3,
                LocationAltitude = 41,
                LocationCity     = "LocationCity",
                LocationState    = "LocationState",
                LocationCountry  = "LocationCountry",
                Title            = "Title",
                ColorClass       = ColorClassParser.Color.Trash,
                Orientation      = FileIndexItem.Rotation.Rotate90Cw,
                DateTime         = DateTime.Now,
            };
            var comparedNames = new List <string> {
                nameof(FileIndexItem.Tags).ToLowerInvariant(),
                nameof(FileIndexItem.Description).ToLowerInvariant(),
                nameof(FileIndexItem.Latitude).ToLowerInvariant(),
                nameof(FileIndexItem.Longitude).ToLowerInvariant(),
                nameof(FileIndexItem.LocationAltitude).ToLowerInvariant(),
                nameof(FileIndexItem.LocationCity).ToLowerInvariant(),
                nameof(FileIndexItem.LocationState).ToLowerInvariant(),
                nameof(FileIndexItem.LocationCountry).ToLowerInvariant(),
                nameof(FileIndexItem.Title).ToLowerInvariant(),
                nameof(FileIndexItem.ColorClass).ToLowerInvariant(),
                nameof(FileIndexItem.Orientation).ToLowerInvariant(),
                nameof(FileIndexItem.DateTime).ToLowerInvariant(),
            };

            var inputSubPaths = new List <string>
            {
                "/test.jpg"
            };
            var storage = new FakeIStorage(new List <string> {
                "/"
            }, new List <string> {
                "/test.jpg"
            }, new List <byte[]>());

            var fakeExifTool = new FakeExifTool(storage, _appSettings);
            var helperResult = new ExifToolCmdHelper(fakeExifTool, storage, storage,
                                                     new FakeReadMeta()).Update(updateModel, inputSubPaths, comparedNames);

            Assert.AreEqual(true, helperResult.Contains(updateModel.Tags));
            Assert.AreEqual(true, helperResult.Contains(updateModel.Description));
            Assert.AreEqual(true, helperResult.Contains(updateModel.Latitude.ToString(CultureInfo.InvariantCulture)));
            Assert.AreEqual(true, helperResult.Contains(updateModel.Longitude.ToString(CultureInfo.InvariantCulture)));
            Assert.AreEqual(true, helperResult.Contains(updateModel.LocationAltitude.ToString(CultureInfo.InvariantCulture)));
            Assert.AreEqual(true, helperResult.Contains(updateModel.LocationCity));
            Assert.AreEqual(true, helperResult.Contains(updateModel.LocationState));
            Assert.AreEqual(true, helperResult.Contains(updateModel.LocationCountry));
            Assert.AreEqual(true, helperResult.Contains(updateModel.Title));
        }
Esempio n. 3
0
        public void ExifToolCommandLineArgsImageStabilisation()
        {
            var updateModel = new FileIndexItem
            {
                ImageStabilisation = ImageStabilisationType.On         // < - - - - include here
            };
            var comparedNames = new List <string> {
                nameof(FileIndexItem.ImageStabilisation).ToLowerInvariant(),
            };

            var exifToolCmdHelper = new ExifToolCmdHelper(null, null, null, null);

            var result = exifToolCmdHelper.ExifToolCommandLineArgs(updateModel,
                                                                   comparedNames, true);

            Assert.AreEqual("-json -overwrite_original -ImageStabilization=\"On\"", result);
        }
Esempio n. 4
0
        public void ExifToolCommandLineArgsImageStabilisationUnknown()
        {
            var updateModel = new FileIndexItem
            {
                ImageStabilisation = ImageStabilisationType.Unknown         // < - - - - include here
            };
            var comparedNames = new List <string> {
                nameof(FileIndexItem.ImageStabilisation).ToLowerInvariant(),
            };

            var exifToolCmdHelper = new ExifToolCmdHelper(null, null, null, null);

            var result = exifToolCmdHelper.ExifToolCommandLineArgs(updateModel,
                                                                   comparedNames, true);

            Assert.AreEqual(string.Empty, result);
        }
Esempio n. 5
0
        /// <summary>
        /// Update ExifTool, Thumbnail, Database and if needed rotateClock
        /// </summary>
        /// <param name="fileIndexItem">output database object</param>
        /// <param name="comparedNamesList">name of fields updated by exifTool</param>
        /// <param name="rotateClock">rotation value (if needed)</param>
        private async Task UpdateWriteDiskDatabase(FileIndexItem fileIndexItem, List <string> comparedNamesList, int rotateClock = 0)
        {
            // do rotation on thumbs
            await RotationThumbnailExecute(rotateClock, fileIndexItem);

            if (fileIndexItem.IsDirectory != true &&
                ExtensionRolesHelper.IsExtensionExifToolSupported(fileIndexItem.FileName))
            {
                // feature to exif update
                var exifUpdateFilePaths = new List <string>
                {
                    fileIndexItem.FilePath
                };
                var exifTool = new ExifToolCmdHelper(_exifTool, _iStorage, _thumbnailStorage, _readMeta);

                // to avoid diskWatcher catch up
                _query.SetGetObjectByFilePathCache(fileIndexItem.FilePath, fileIndexItem, TimeSpan.FromSeconds(10));

                // Do an Exif Sync for all files, including thumbnails
                var(exifResult, newFileHashes) = await exifTool.UpdateAsync(fileIndexItem,
                                                                            exifUpdateFilePaths, comparedNamesList, true, true);

                await ApplyOrGenerateUpdatedFileHash(newFileHashes, fileIndexItem);

                _logger.LogInformation(string.IsNullOrEmpty(exifResult)
                                        ? $"[UpdateWriteDiskDatabase] ExifTool result is Nothing or " +
                                       $"Null for: path:{fileIndexItem.FilePath} {DateTime.UtcNow.ToShortTimeString()}"
                                        : $"[UpdateWriteDiskDatabase] ExifTool result: {exifResult} path:{fileIndexItem.FilePath}");
            }
            else
            {
                await new FileIndexItemJsonParser(_iStorage).WriteAsync(fileIndexItem);
            }

            // Do a database sync + cache sync
            // Clone to avoid reference when cache exist
            await _query.UpdateItemAsync(fileIndexItem.Clone());

            // > async > force you to read the file again
            // do not include thumbs in MetaCache
            // only the full path url of the source image
            _readMeta.RemoveReadMetaCache(fileIndexItem.FilePath);
        }