Пример #1
0
        /// <summary>
        /// Compare Rotation and All other tags
        /// </summary>
        /// <param name="changedFileIndexItemName">Per file stored  string{FilePath},
        /// List*string*{FileIndexItem.name (e.g. Tags) that are changed}</param>
        /// <param name="collectionsFileIndexItem">DetailView input, only to display changes</param>
        /// <param name="statusModel">object that include the changes</param>
        /// <param name="append">true= for tags to add</param>
        /// <param name="rotateClock">rotation value 1 left, -1 right, 0 nothing</param>
        public void CompareAllLabelsAndRotation(Dictionary <string, List <string> > changedFileIndexItemName,
                                                FileIndexItem collectionsFileIndexItem, FileIndexItem statusModel, bool append, int rotateClock)
        {
            if (changedFileIndexItemName == null)
            {
                throw new MissingFieldException(nameof(changedFileIndexItemName));
            }

            // compare and add changes to collectionsDetailView
            var comparedNamesList = FileIndexCompareHelper
                                    .Compare(collectionsFileIndexItem, statusModel, append);

            // if requested, add changes to rotation
            collectionsFileIndexItem =
                RotationCompare(rotateClock, collectionsFileIndexItem, comparedNamesList);

            if (!changedFileIndexItemName.ContainsKey(collectionsFileIndexItem.FilePath))
            {
                // add to list
                changedFileIndexItemName.Add(collectionsFileIndexItem.FilePath, comparedNamesList);
                return;
            }

            // overwrite list if already exist
            changedFileIndexItemName[collectionsFileIndexItem.FilePath] = comparedNamesList;
        }
Пример #2
0
        /// <summary>
        /// Create a XMP file when it not exist
        /// </summary>
        /// <param name="updateModel">model</param>
        /// <param name="inputSubPaths">list of paths</param>
        /// <returns>void</returns>
        internal async Task CreateXmpFileIsNotExist(FileIndexItem updateModel, List <string> inputSubPaths)
        {
            foreach (var subPath in inputSubPaths)
            {
                // only for raw files
                if (!ExtensionRolesHelper.IsExtensionForceXmp(subPath))
                {
                    return;
                }

                var withXmp = ExtensionRolesHelper.ReplaceExtensionWithXmp(subPath);

                if (_iStorage.IsFolderOrFile(withXmp) !=
                    FolderOrFileModel.FolderOrFileTypeList.Deleted)
                {
                    continue;
                }

                new ExifCopy(_iStorage, _thumbnailStorage, _exifTool, _readMeta).XmpCreate(withXmp);

                var comparedNames = FileIndexCompareHelper.Compare(new FileIndexItem(), updateModel);
                var command       = ExifToolCommandLineArgs(updateModel, comparedNames, true);

                await _exifTool.WriteTagsAsync(withXmp, command);
            }
        }
Пример #3
0
        private FileIndexItem ReadExifAndXmpFromFileDirect(string subPath)
        {
            if (_iStorage.ExistFile(subPath) &&
                ExtensionRolesHelper.IsExtensionForceGpx(subPath))
            {
                return(ReadMetaGpx.ReadGpxFromFileReturnAfterFirstField(_iStorage.ReadStream(subPath), subPath));
            }

            var fileIndexItemWithPath = new FileIndexItem(subPath);

            // Read first the sidecar file
            var xmpFileIndexItem = _readXmp.XmpGetSidecarFile(fileIndexItemWithPath.Clone());

            if (xmpFileIndexItem.IsoSpeed == 0 ||
                string.IsNullOrEmpty(xmpFileIndexItem.Make) ||
                xmpFileIndexItem.DateTime.Year == 0 || xmpFileIndexItem.ImageHeight == 0)
            {
                // so the sidecar file is not used
                var fileExifItemFile = _readExif.ReadExifFromFile(subPath, fileIndexItemWithPath);

                // overwrite content with incomplete sidecar file (this file can contain tags)
                FileIndexCompareHelper.Compare(fileExifItemFile, xmpFileIndexItem);
                return(fileExifItemFile);
            }

            return(xmpFileIndexItem);
        }
Пример #4
0
        public static List <FileIndexItem> SearchAndReplace(List <FileIndexItem> fileIndexResultsList,
                                                            string fieldName, string search, string replace)
        {
            foreach (var fileIndexItem in fileIndexResultsList.Where(
                         p => p.Status == FileIndexItem.ExifStatus.Ok ||
                         p.Status == FileIndexItem.ExifStatus.Deleted))
            {
                var searchInObject   = FileIndexCompareHelper.Get(fileIndexItem, fieldName);
                var replacedToObject = new object();

                PropertyInfo[] propertiesA = new FileIndexItem().GetType().GetProperties(
                    BindingFlags.Public | BindingFlags.Instance);
                PropertyInfo property = propertiesA.FirstOrDefault(p => string.Equals(
                                                                       p.Name, fieldName, StringComparison.InvariantCultureIgnoreCase));

                if (property.PropertyType == typeof(string))
                {
                    var searchIn = ( string )searchInObject;

                    // Replace Ignore Case
                    replacedToObject = Regex.Replace(
                        searchIn,
                        Regex.Escape(search),
                        replace.Replace("$", "$$"),
                        RegexOptions.IgnoreCase
                        );
                }

                // only string types are added here, other types are ignored for now
                FileIndexCompareHelper.Set(fileIndexItem, fieldName, replacedToObject);
            }

            return(fileIndexResultsList);
        }
Пример #5
0
        /// <summary>
        /// Copy the metaData over the output path
        /// </summary>
        /// <param name="item">all the meta data</param>
        /// <param name="outputPath">absolute path on host disk</param>
        private async Task MetaData(FileIndexItem item, string outputPath)
        {
            if (!_subPathStorage.ExistFile(item.FilePath))
            {
                return;
            }

            // Write the metadata to the new created file
            var comparedNames = FileIndexCompareHelper.Compare(
                new FileIndexItem(), item);

            // Output has already rotated the image
            var rotation = nameof(FileIndexItem.Orientation).ToLowerInvariant();

            if (comparedNames.Contains(rotation))
            {
                comparedNames.Remove(rotation);
            }

            // Write it back
            await new ExifToolCmdHelper(_exifTool, _hostFileSystemStorage,
                                        _thumbnailStorage, null).UpdateAsync(item,
                                                                             new List <string> {
                outputPath
            }, comparedNames,
                                                                             false, false);
        }
Пример #6
0
        public void FileIndexCompareHelperTest_GetValue_LowerCase()
        {
            var t = new FileIndexItem {
                Tags = "test"
            };
            var result = FileIndexCompareHelper.Get(t, nameof(FileIndexItem.Tags).ToLowerInvariant());

            Assert.AreEqual(t.Tags, result);
        }
Пример #7
0
        public void FileIndexCompareHelperTest_GetValue_NullFieldName()
        {
            var t = new FileIndexItem {
                Tags = "test"
            };
            var result = FileIndexCompareHelper.Get(t, "ThisTagDoesNotExist");

            Assert.AreEqual(null, result);
        }
Пример #8
0
        /// <summary>
        /// Only update an item with updated content form disk
        /// </summary>
        /// <param name="dbItem">database item</param>
        /// <param name="size">byte size</param>
        /// <returns>the updated item</returns>
        public async Task <FileIndexItem> PrepareUpdateFileItem(FileIndexItem dbItem, long size)
        {
            var metaDataItem = _readMeta.ReadExifAndXmpFromFile(dbItem.FilePath);

            FileIndexCompareHelper.Compare(dbItem, metaDataItem);
            dbItem.Size = size;
            await SetFileHashStatus(dbItem.FilePath, dbItem.FileHash, dbItem);

            return(dbItem);
        }
Пример #9
0
        /// <summary>
        /// Keep within the same storage provider
        /// Used for example by Import
        /// </summary>
        /// <param name="fromSubPath"></param>
        /// <param name="toSubPath"></param>
        /// <returns></returns>
        internal async Task <string> CopyExifPublish(string fromSubPath, string toSubPath)
        {
            var updateModel   = _readMeta.ReadExifAndXmpFromFile(fromSubPath);
            var comparedNames = FileIndexCompareHelper.Compare(new FileIndexItem(), updateModel);

            comparedNames.Add(nameof(FileIndexItem.Software));
            updateModel.SetFilePath(toSubPath);
            return((await new ExifToolCmdHelper(_exifTool, _iStorage, _thumbnailStorage, _readMeta).UpdateAsync(updateModel,
                                                                                                                comparedNames, true, false)).Item1);
        }
Пример #10
0
        public void FileIndexCompareHelperTest_String_Tags_AppendCompare()
        {
            var source = new FileIndexItem {
                Tags = "hi"
            };
            var update = new FileIndexItem {
                Tags = "update"
            };

            FileIndexCompareHelper.Compare(source, update, true);
            Assert.AreEqual("hi, update", source.Tags);
        }
Пример #11
0
        public void FileIndexCompareHelperTest_Rotation_Compare()
        {
            var source = new FileIndexItem {
                Orientation = FileIndexItem.Rotation.Horizontal
            };
            var update = new FileIndexItem {
                Orientation = FileIndexItem.Rotation.Rotate90Cw
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual(source.Orientation, FileIndexItem.Rotation.Rotate90Cw);
        }
Пример #12
0
        public void FileIndexCompareHelperTest_double_Compare()
        {
            var source = new FileIndexItem {
                Aperture = 0
            };
            var update = new FileIndexItem {
                Aperture = 1
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual(1, source.Aperture);
        }
Пример #13
0
        public void FileIndexCompareHelperTest_ushort_Compare()
        {
            var source = new FileIndexItem {
                IsoSpeed = 0
            };
            var update = new FileIndexItem {
                IsoSpeed = 1
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual(1, source.IsoSpeed);
        }
Пример #14
0
        public void FileIndexCompareHelperTest_bool_Compare()
        {
            var source = new FileIndexItem {
                IsDirectory = false
            };
            var update = new FileIndexItem {
                IsDirectory = true
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual(true, source.IsDirectory);
        }
Пример #15
0
        public void FileIndexCompareHelperTest_String_Description_AppendCompare()
        {
            var source = new FileIndexItem {
                Description = "hi"
            };
            var update = new FileIndexItem {
                Description = "update"
            };

            FileIndexCompareHelper.Compare(source, update, true);
            Assert.AreEqual("hi update", source.Description);
        }
Пример #16
0
        public void FileIndexCompareHelperTest_ImageStabilisationType_Compare_ShouldUpdate()
        {
            var source = new FileIndexItem {
                ImageStabilisation = ImageStabilisationType.Unknown
            };
            var update = new FileIndexItem {
                ImageStabilisation = ImageStabilisationType.Off
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual(ImageStabilisationType.Off, source.ImageStabilisation);
        }
Пример #17
0
        public void FileIndexCompareHelperTest_colorClass_Compare()
        {
            var source = new FileIndexItem {
                ColorClass = ColorClassParser.Color.None
            };
            var update = new FileIndexItem {
                ColorClass = ColorClassParser.Color.Winner
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual(ColorClassParser.Color.Winner, source.ColorClass);
        }
Пример #18
0
        public void FileIndexCompareHelperTest_DateTime_Compare()
        {
            // source= null> update is new overwrite
            var source = new FileIndexItem {
                DateTime = new DateTime()
            };
            var update = new FileIndexItem {
                DateTime = DateTime.Now
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual(update.DateTime, source.DateTime);
        }
Пример #19
0
        public void FileIndexCompareHelperTest_FilePath_Compare()
        {
            // this one is ignored
            var source = new FileIndexItem {
                FilePath = "/test"
            };
            var update = new FileIndexItem {
                FilePath = "/ignore"
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual("/test", source.FilePath);
        }
Пример #20
0
        public void FileIndexCompareHelperTest_SetCompare()
        {
            var source = new FileIndexItem {
                DateTime = new DateTime()
            };
            var update = new FileIndexItem {
                DateTime = DateTime.Now
            };
            var result = FileIndexCompareHelper.SetCompare(source, update, new List <string>
            {
                "DateTime"
            });

            Assert.AreEqual(update.DateTime, result.DateTime);
        }
Пример #21
0
        public void FileIndexCompareHelperTest_StringList_Compare()
        {
            var source = new FileIndexItem {
                CollectionPaths = new List <string> {
                    "source"
                }
            };
            var update = new FileIndexItem {
                CollectionPaths = new List <string> {
                    "update"
                }
            };

            FileIndexCompareHelper.Compare(source, update);
            Assert.AreEqual("update", source.CollectionPaths[0]);
        }
Пример #22
0
        /// <summary>
        /// Perform database updates
        /// </summary>
        /// <param name="metaDataItem">to update to</param>
        /// <returns>updated item</returns>
        private async Task <FileIndexItem> SyncItem(FileIndexItem metaDataItem)
        {
            var itemFromDatabase = await _query.GetObjectByFilePathAsync(metaDataItem.FilePath);

            if (itemFromDatabase == null)
            {
                AddOrRemoveXmpSidecarFileToDatabase(metaDataItem);
                await _query.AddItemAsync(metaDataItem);

                return(metaDataItem);
            }

            FileIndexCompareHelper.Compare(itemFromDatabase, metaDataItem);
            AddOrRemoveXmpSidecarFileToDatabase(metaDataItem);

            await _query.UpdateItemAsync(itemFromDatabase);

            return(itemFromDatabase);
        }
Пример #23
0
 public void FileIndexCompareHelperTest__SetValue_UnknownValue()
 {
     // try database type that does not exist
     Assert.AreEqual(string.Empty, FileIndexCompareHelper.Set(null, "ThisTagDoesNotExist", "value").Tags);
 }
Пример #24
0
 public void FileIndexCompareHelperTest__CheckIfPropertyExist_Tags_True()
 {
     Assert.AreEqual(true, FileIndexCompareHelper.CheckIfPropertyExist(nameof(FileIndexItem.Tags)));
 }
Пример #25
0
        /// <summary>
        /// Search and replace in string based fields (only Getting and replacing)
        /// </summary>
        /// <param name="f">subPath (split by dot comma ;)</param>
        /// <param name="search"></param>
        /// <param name="replace"></param>
        /// <param name="fieldName"></param>
        /// <param name="collections"></param>
        public async Task <List <FileIndexItem> > Replace(string f, string fieldName, string search, string replace, bool collections)
        {
            // when you search for nothing, your fast done
            if (string.IsNullOrEmpty(search))
            {
                return new List <FileIndexItem>
                       {
                           new FileIndexItem {
                               Status = FileIndexItem.ExifStatus.OperationNotSupported
                           }
                       }
            }
            ;

            // escaping null values
            if (string.IsNullOrEmpty(replace))
            {
                replace = string.Empty;
            }

            if (!FileIndexCompareHelper.CheckIfPropertyExist(fieldName))
            {
                return new List <FileIndexItem>
                       {
                           new FileIndexItem {
                               Status = FileIndexItem.ExifStatus.OperationNotSupported
                           }
                       }
            }
            ;
            var inputFilePaths = PathHelper.SplitInputFilePaths(f);

            // the result list
            var fileIndexUpdatedList = new List <FileIndexItem>();

            // Prefill cache to avoid fast updating issues
            await new AddParentCacheIfNotExist(_query, _logger).AddParentCacheIfNotExistAsync(inputFilePaths);

            // Assumes that this give status Ok back by default
            var queryFileIndexItemsList = await _query.GetObjectsByFilePathAsync(
                inputFilePaths.ToList(), collections);

            // to collect
            foreach (var fileIndexItem in queryFileIndexItemsList)
            {
                if (_iStorage.IsFolderOrFile(fileIndexItem.FilePath) == FolderOrFileModel.FolderOrFileTypeList.Deleted)                   // folder deleted
                {
                    StatusCodesHelper.ReturnExifStatusError(fileIndexItem,
                                                            FileIndexItem.ExifStatus.NotFoundSourceMissing,
                                                            fileIndexUpdatedList);
                    continue;
                }

                // Dir is readonly / don't edit
                if (new StatusCodesHelper(_appSettings).IsReadOnlyStatus(fileIndexItem)
                    == FileIndexItem.ExifStatus.ReadOnly)
                {
                    StatusCodesHelper.ReturnExifStatusError(fileIndexItem,
                                                            FileIndexItem.ExifStatus.ReadOnly,
                                                            fileIndexUpdatedList);
                    continue;
                }
                fileIndexUpdatedList.Add(fileIndexItem);
            }

            fileIndexUpdatedList = SearchAndReplace(fileIndexUpdatedList, fieldName, search, replace);

            AddNotFoundInIndexStatus.Update(inputFilePaths, fileIndexUpdatedList);

            var fileIndexResultList = new List <FileIndexItem>();

            foreach (var fileIndexItem in fileIndexUpdatedList)
            {
                // Status Ok is already set

                // Deleted is allowed but the status need be updated
                if ((fileIndexItem.Status == FileIndexItem.ExifStatus.Ok) &&
                    StatusCodesHelper.IsDeletedStatus(fileIndexItem) ==
                    FileIndexItem.ExifStatus.Deleted)
                {
                    fileIndexItem.Status = FileIndexItem.ExifStatus.Deleted;
                }

                fileIndexResultList.Add(fileIndexItem);
            }

            return(fileIndexResultList);
        }
Пример #26
0
 public void FileIndexCompareHelperTest__CheckIfPropertyExist_False()
 {
     Assert.AreEqual(false, FileIndexCompareHelper.CheckIfPropertyExist("45678987654"));
 }
Пример #27
0
 public void FileIndexCompareHelperTest__SetValue_Tags()
 {
     Assert.AreEqual("value", FileIndexCompareHelper.Set(null, nameof(FileIndexItem.Tags), "value").Tags);
 }
Пример #28
0
 public void FileIndexCompareHelperTest__SetValue_Tags_LowerCase()
 {
     Assert.AreEqual("value", FileIndexCompareHelper.Set(null, nameof(FileIndexItem.Tags).ToLowerInvariant(), "value").Tags);
 }
Пример #29
0
 public void FileIndexCompareHelperTest__SetValue_WrongTypeCast()
 {
     // wrong types are ignored by default
     Assert.AreEqual(string.Empty, FileIndexCompareHelper.Set(null, nameof(FileIndexItem.Tags), 1).Tags);
 }
Пример #30
0
        public void FileIndexCompareHelperTest_GetValue_NullFileIndexItem()
        {
            var result = FileIndexCompareHelper.Get(null, nameof(FileIndexItem.Tags));

            Assert.AreEqual(null, result);
        }