Preflight(FileIndexItem inputModel, string[] inputFilePaths, bool append, bool collections, int rotateClock) { // the result list var fileIndexUpdateList = new List <FileIndexItem>(); // Per file stored key = string[fileHash] item => List <string> // FileIndexItem.name (e.g. Tags) that are changed var changedFileIndexItemName = new Dictionary <string, List <string> >(); // Prefill cache to avoid fast updating issues await new AddParentCacheIfNotExist(_query, _logger).AddParentCacheIfNotExistAsync(inputFilePaths); var resultFileIndexItemsList = await _query.GetObjectsByFilePathAsync( inputFilePaths.ToList(), collections); foreach (var fileIndexItem in resultFileIndexItemsList) { // Files that are not on disk if (_iStorage.IsFolderOrFile(fileIndexItem.FilePath) == FolderOrFileModel.FolderOrFileTypeList.Deleted) { StatusCodesHelper.ReturnExifStatusError(fileIndexItem, FileIndexItem.ExifStatus.NotFoundSourceMissing, fileIndexUpdateList); continue; } // Dir is readonly / don't edit if (new StatusCodesHelper(_appSettings).IsReadOnlyStatus(fileIndexItem) == FileIndexItem.ExifStatus.ReadOnly) { StatusCodesHelper.ReturnExifStatusError(fileIndexItem, FileIndexItem.ExifStatus.ReadOnly, fileIndexUpdateList); continue; } CompareAllLabelsAndRotation(changedFileIndexItemName, fileIndexItem, inputModel, append, rotateClock); // this one is good :) if (fileIndexItem.Status == FileIndexItem.ExifStatus.Default || fileIndexItem.Status == FileIndexItem.ExifStatus.OkAndSame) { fileIndexItem.Status = FileIndexItem.ExifStatus.Ok; } // Deleted is allowed but the status need be updated if ((StatusCodesHelper.IsDeletedStatus(fileIndexItem) == FileIndexItem.ExifStatus.Deleted)) { fileIndexItem.Status = FileIndexItem.ExifStatus.Deleted; } // The hash in FileIndexItem is not correct // Clone to not change after update fileIndexUpdateList.Add(fileIndexItem); } // update database cache and cloned due reference _query.CacheUpdateItem(fileIndexUpdateList); AddNotFoundInIndexStatus.Update(inputFilePaths, fileIndexUpdateList); return(fileIndexUpdateList, changedFileIndexItemName); }
/// <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); }