예제 #1
0
 public MetaInfo(IQuery query, AppSettings appSettings, ISelectorStorage selectorStorage, IMemoryCache memoryCache)
 {
     _query            = query;
     _iStorage         = selectorStorage.Get(SelectorStorage.StorageServices.SubPath);
     _readMeta         = new ReadMeta(_iStorage, appSettings, memoryCache);
     _statusCodeHelper = new StatusCodesHelper(appSettings);
 }
예제 #2
0
파일: DeleteItem.cs 프로젝트: qdraw/starsky
 public DeleteItem(IQuery query, AppSettings appSettings, ISelectorStorage selectorStorage)
 {
     _query            = query;
     _iStorage         = selectorStorage.Get(SelectorStorage.StorageServices.SubPath);
     _thumbnailStorage = selectorStorage.Get(SelectorStorage.StorageServices.Thumbnail);
     _statusCodeHelper = new StatusCodesHelper(appSettings);
 }
예제 #3
0
        public void IsReadOnlyStatus_DetailView_Null()
        {
            DetailView detailView = null;
            // ReSharper disable once ExpressionIsAlwaysNull
            var status = new StatusCodesHelper(new AppSettings()).IsReadOnlyStatus(detailView);

            Assert.AreEqual(FileIndexItem.ExifStatus.Default, status);
        }
예제 #4
0
        public void IsDeletedStatus_Null_Default()
        {
            DetailView detailView = null;
            // ReSharper disable once ExpressionIsAlwaysNull
            var status = StatusCodesHelper.IsDeletedStatus(detailView);

            Assert.AreEqual(FileIndexItem.ExifStatus.Default, status);
        }
예제 #5
0
        public Tuple <string, List <FileIndexItem> > Preflight(string[] inputFilePaths,
                                                               bool collections = true,
                                                               bool thumbnail   = false)
        {
            // the result list
            var fileIndexResultsList = new List <FileIndexItem>();

            foreach (var subPath in inputFilePaths)
            {
                var detailView = _query.SingleItem(subPath, null, collections, false);
                if (detailView?.FileIndexItem == null)
                {
                    StatusCodesHelper.ReturnExifStatusError(new FileIndexItem(subPath),
                                                            FileIndexItem.ExifStatus.NotFoundNotInIndex,
                                                            fileIndexResultsList);
                    continue;
                }

                if (_iStorage.IsFolderOrFile(detailView.FileIndexItem.FilePath) ==
                    FolderOrFileModel.FolderOrFileTypeList.Deleted)
                {
                    StatusCodesHelper.ReturnExifStatusError(detailView.FileIndexItem,
                                                            FileIndexItem.ExifStatus.NotFoundSourceMissing,
                                                            fileIndexResultsList);
                    continue;
                }

                if (detailView.FileIndexItem.IsDirectory == true)
                {
                    // Collection is only relevant for when selecting one file
                    foreach (var item in
                             _query.GetAllRecursive(detailView.FileIndexItem.FilePath).
                             Where(item => _iStorage.ExistFile(item.FilePath)))
                    {
                        item.Status = FileIndexItem.ExifStatus.Ok;
                        fileIndexResultsList.Add(item);
                    }
                    continue;
                }

                // Now Add Collection based images
                var collectionSubPathList = DetailView.GetCollectionSubPathList(detailView.FileIndexItem, collections, subPath);
                foreach (var item in collectionSubPathList)
                {
                    var itemDetailView = _query.SingleItem(item, null,
                                                           false, false).FileIndexItem;
                    itemDetailView.Status = FileIndexItem.ExifStatus.Ok;
                    fileIndexResultsList.Add(itemDetailView);
                }
            }

            var isThumbnail = thumbnail ? "TN" : "SR";             // has:notHas
            var zipHash     = isThumbnail + GetName(fileIndexResultsList);

            return(new Tuple <string, List <FileIndexItem> >(zipHash, fileIndexResultsList));
        }
예제 #6
0
        public void StatusCodesHelperTest_ReadonlyAllowed_true()
        {
            var statusModel          = new FileIndexItem();
            var statusResults        = FileIndexItem.ExifStatus.ReadOnly;
            var fileIndexResultsList = new List <FileIndexItem>();

            StatusCodesHelper.ReadonlyAllowed(statusModel, statusResults,
                                              fileIndexResultsList);
            Assert.AreEqual(FileIndexItem.ExifStatus.ReadOnly, fileIndexResultsList.FirstOrDefault().Status);
        }
예제 #7
0
        public void StatusCodesHelperTest_ReadonlyDenied_false()
        {
            var statusModel          = new FileIndexItem();
            var statusResults        = FileIndexItem.ExifStatus.Ok;
            var fileIndexResultsList = new List <FileIndexItem>();
            var statusBool           = StatusCodesHelper.ReadonlyDenied(statusModel, statusResults,
                                                                        fileIndexResultsList);

            Assert.AreEqual(false, statusBool);
        }
예제 #8
0
        public void StatusCodesHelperTest_ReturnExifStatusError_ReadOnly()
        {
            var statusModel          = new FileIndexItem();
            var statusResults        = FileIndexItem.ExifStatus.ReadOnly;
            var fileIndexResultsList = new List <FileIndexItem>();
            var statusBool           = StatusCodesHelper.ReturnExifStatusError(statusModel, statusResults,
                                                                               fileIndexResultsList);

            Assert.AreEqual(true, statusBool);
        }
예제 #9
0
        public void StatusCodesHelperTest_ReturnExifStatusError_NotFoundSourceMissing()
        {
            var appSettings          = new AppSettings();
            var statusModel          = new FileIndexItem();
            var statusResults        = FileIndexItem.ExifStatus.NotFoundSourceMissing;
            var fileIndexResultsList = new List <FileIndexItem>();
            var statusBool           = StatusCodesHelper.ReturnExifStatusError(statusModel, statusResults,
                                                                               fileIndexResultsList);

            Assert.AreEqual(true, statusBool);
        }
예제 #10
0
 internal static void Update(string[] inputFilePaths, List <FileIndexItem> fileIndexResultsList)
 {
     foreach (var subPath in inputFilePaths)
     {
         // when item is not in the database
         if (fileIndexResultsList.All(p => p.FilePath != subPath))
         {
             StatusCodesHelper.ReturnExifStatusError(new FileIndexItem(subPath),
                                                     FileIndexItem.ExifStatus.NotFoundNotInIndex,
                                                     fileIndexResultsList);
         }
     }
 }
예제 #11
0
        public void IsReadOnlyStatus_FileIndexItem_DirReadOnly()
        {
            // this is the only diff -->>
            var appSettings = new AppSettings {
                ReadOnlyFolders = new List <string> {
                    "/"
                }
            };
            var detailView = new FileIndexItem
            {
                IsDirectory = true,
                FilePath    = "/"
            };
            var status = new StatusCodesHelper(appSettings).IsReadOnlyStatus(detailView);

            Assert.AreEqual(FileIndexItem.ExifStatus.DirReadOnly, status);
        }
예제 #12
0
        public void StatusCodesHelperTest_InjectFakeIStorage_FileDeletedTag()
        {
            var appSettings = new AppSettings();
            var detailView  = new DetailView
            {
                IsDirectory   = false,
                SubPath       = "/test.jpg",
                FileIndexItem = new FileIndexItem {
                    ParentDirectory = "/",
                    Tags            = "!delete!", FileName = "test.jpg", CollectionPaths = new List <string> {
                        "/test.jpg"
                    }
                }
            };
            var istorage = new FakeIStorage(new List <string> {
                "/"
            },
                                            new List <string> {
                "/test.jpg"
            });
            var status = StatusCodesHelper.IsDeletedStatus(detailView);

            Assert.AreEqual(FileIndexItem.ExifStatus.Deleted, status);
        }
예제 #13
0
파일: DeleteItem.cs 프로젝트: qdraw/starsky
        public List <FileIndexItem> Delete(string f, bool collections)
        {
            var inputFilePaths = PathHelper.SplitInputFilePaths(f);

            // the result list
            var fileIndexResultsList             = new List <FileIndexItem>();
            var collectionAndInsideDirectoryList = new List <string>();

            foreach (var subPath in inputFilePaths)
            {
                var detailView =
                    _query.SingleItem(subPath, null, collections, false);

                if (detailView?.FileIndexItem == null)
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        new FileIndexItem(subPath),
                        FileIndexItem.ExifStatus.NotFoundNotInIndex,
                        fileIndexResultsList);
                    continue;
                }

                if (_iStorage.IsFolderOrFile(detailView.FileIndexItem
                                             .FilePath) ==
                    FolderOrFileModel.FolderOrFileTypeList.Deleted)
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        detailView.FileIndexItem,
                        FileIndexItem.ExifStatus.NotFoundSourceMissing,
                        fileIndexResultsList);
                    continue;
                }

                // Dir is readonly / don't delete
                if (_statusCodeHelper.IsReadOnlyStatus(detailView)
                    == FileIndexItem.ExifStatus.ReadOnly)
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        detailView.FileIndexItem,
                        FileIndexItem.ExifStatus.ReadOnly,
                        fileIndexResultsList);
                    continue;
                }

                // Status should be deleted before you can delete the item
                if (StatusCodesHelper.IsDeletedStatus(detailView)
                    != FileIndexItem.ExifStatus.Deleted)
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        detailView.FileIndexItem,
                        FileIndexItem.ExifStatus.OperationNotSupported,
                        fileIndexResultsList);
                    continue;
                }

                collectionAndInsideDirectoryList.AddRange(DetailView.GetCollectionSubPathList(detailView.FileIndexItem, collections, subPath));

                // For deleting content of an entire directory
                if (detailView.FileIndexItem.IsDirectory != true)
                {
                    continue;
                }

                // when deleting a folder the collections setting does nothing
                collectionAndInsideDirectoryList.AddRange(
                    _query.GetAllFiles(detailView.FileIndexItem.FilePath).Select(itemInDirectory => itemInDirectory.FilePath)
                    );
            }

            // collectionAndInsideDirectoryList should not have duplicate items
            foreach (var collectionSubPath in new HashSet <string>(collectionAndInsideDirectoryList))
            {
                var detailViewItem = _query.SingleItem(collectionSubPath,
                                                       null, false, false);

                // null only happens when some other process also delete this item
                if (detailViewItem == null)
                {
                    continue;
                }

                // return a Ok, which means the file is deleted
                detailViewItem.FileIndexItem.Status = FileIndexItem.ExifStatus.Ok;

                // remove thumbnail from disk
                _thumbnailStorage.FileDelete(detailViewItem.FileIndexItem.FileHash);

                fileIndexResultsList.Add(detailViewItem.FileIndexItem.Clone());

                // remove item from db
                _query.RemoveItem(detailViewItem.FileIndexItem);

                RemoveXmpSideCarFile(detailViewItem);
                RemoveJsonSideCarFile(detailViewItem);
                RemoveFileOrFolderFromDisk(detailViewItem);

                // the child directories are still stored in the database
                if (detailViewItem.FileIndexItem.IsDirectory != true)
                {
                    continue;
                }

                foreach (var item in _query.GetAllRecursive(collectionSubPath).Where(p => p.IsDirectory == true))
                {
                    item.Status = FileIndexItem.ExifStatus.Deleted;
                    fileIndexResultsList.Add(item.Clone());
                    _query.RemoveItem(item);
                }
            }
            return(fileIndexResultsList);
        }
예제 #14
0
        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);
        }
예제 #15
0
        public List <FileIndexItem> GetInfo(List <string> inputFilePaths, bool collections)
        {
            // the result list
            var fileIndexResultsList = new List <FileIndexItem>();

            foreach (var subPath in inputFilePaths)
            {
                var detailView = _query.SingleItem(subPath, null, collections, false);

                if (detailView?.FileIndexItem == null)
                {
                    StatusCodesHelper.ReturnExifStatusError(new FileIndexItem(subPath),
                                                            FileIndexItem.ExifStatus.NotFoundNotInIndex,
                                                            fileIndexResultsList);
                    continue;
                }

                if (!_iStorage.ExistFile(detailView.FileIndexItem.FilePath))
                {
                    StatusCodesHelper.ReturnExifStatusError(detailView.FileIndexItem,
                                                            FileIndexItem.ExifStatus.NotFoundSourceMissing,
                                                            fileIndexResultsList);
                    continue;
                }

                // Check if extension is supported for ExtensionExifToolSupportedList
                // Not all files are able to write with exifTool
                if (!ExtensionRolesHelper.IsExtensionExifToolSupported(detailView.FileIndexItem.FileName))
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        new FileIndexItemJsonParser(_iStorage).Read(detailView.FileIndexItem),
                        FileIndexItem.ExifStatus.ExifWriteNotSupported,
                        fileIndexResultsList);
                    continue;
                }

                var statusResults = StatusCodesHelper.IsDeletedStatus(detailView);
                // only when default status to avoid unneeded checks
                if (statusResults == FileIndexItem.ExifStatus.Default)
                {
                    statusResults = _statusCodeHelper.IsReadOnlyStatus(detailView);
                }
                // when everything is checked, it should be good
                if (statusResults == FileIndexItem.ExifStatus.Default)
                {
                    statusResults = FileIndexItem.ExifStatus.Ok;
                }

                var collectionSubPathList = DetailView.GetCollectionSubPathList(detailView.FileIndexItem, collections, subPath);

                foreach (var collectionSubPath in collectionSubPathList)
                {
                    var collectionItem = _readMeta.ReadExifAndXmpFromFile(collectionSubPath);

                    collectionItem.Status          = statusResults;
                    collectionItem.CollectionPaths = collectionSubPathList;
                    collectionItem.ImageFormat     =
                        ExtensionRolesHelper.MapFileTypesToExtension(collectionSubPath);
                    collectionItem.Size = _iStorage.Info(collectionSubPath).Size;
                    fileIndexResultsList.Add(collectionItem);
                }
            }

            return(fileIndexResultsList);
        }
예제 #16
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);
        }