Exemple #1
0
        public override HealthCheck Check()
        {
            var rootFolders = _authorService.AllAuthorPaths()
                              .Select(s => _rootFolderService.GetBestRootFolderPath(s.Value))
                              .Distinct();

            var missingRootFolders = rootFolders.Where(s => !_diskProvider.FolderExists(s))
                                     .ToList();

            missingRootFolders.AddRange(_importListFactory.All()
                                        .Select(s => s.RootFolderPath)
                                        .Distinct()
                                        .Where(s => !_diskProvider.FolderExists(s))
                                        .ToList());

            missingRootFolders = missingRootFolders.Distinct().ToList();

            if (missingRootFolders.Any())
            {
                if (missingRootFolders.Count == 1)
                {
                    return(new HealthCheck(GetType(), HealthCheckResult.Error, "Missing root folder: " + missingRootFolders.First(), "#missing_root_folder"));
                }

                var message = string.Format("Multiple root folders are missing: {0}", string.Join(" | ", missingRootFolders));
                return(new HealthCheck(GetType(), HealthCheckResult.Error, message, "#missing_root_folder"));
            }

            return(new HealthCheck(GetType()));
        }
Exemple #2
0
        public override HealthCheck Check()
        {
            var rootFolders = _authorService.AllAuthorPaths()
                              .Select(s => _rootFolderService.GetBestRootFolderPath(s.Value))
                              .Distinct();

            var missingRootFolders = rootFolders.Where(s => !_diskProvider.FolderExists(s))
                                     .ToList();

            missingRootFolders.AddRange(_importListFactory.All()
                                        .Select(s => s.RootFolderPath)
                                        .Distinct()
                                        .Where(s => !_diskProvider.FolderExists(s))
                                        .ToList());

            missingRootFolders = missingRootFolders.Distinct().ToList();

            if (missingRootFolders.Any())
            {
                if (missingRootFolders.Count == 1)
                {
                    return(new HealthCheck(GetType(), HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("RootFolderCheckSingleMessage"), missingRootFolders.First()), "#missing-root-folder"));
                }

                var message = string.Format(_localizationService.GetLocalizedString("RootFolderCheckMultipleMessage"), string.Join(" | ", missingRootFolders));
                return(new HealthCheck(GetType(), HealthCheckResult.Error, message, "#missing-root-folder"));
            }

            return(new HealthCheck(GetType()));
        }
        public void HandleAsync(AuthorDeletedEvent message)
        {
            if (message.DeleteFiles)
            {
                var author     = message.Author;
                var allAuthors = _authorService.AllAuthorPaths();

                foreach (var s in allAuthors)
                {
                    if (s.Key == author.Id)
                    {
                        continue;
                    }

                    if (author.Path.IsParentPath(s.Value))
                    {
                        _logger.Error("Author path: '{0}' is a parent of another author, not deleting files.", author.Path);
                        return;
                    }

                    if (author.Path.PathEquals(s.Value))
                    {
                        _logger.Error("Author path: '{0}' is the same as another author, not deleting files.", author.Path);
                        return;
                    }
                }

                if (_diskProvider.FolderExists(message.Author.Path))
                {
                    _recycleBinProvider.DeleteFolder(message.Author.Path);
                }
            }
        }
Exemple #4
0
        protected override bool IsValid(PropertyValidatorContext context)
        {
            if (context.PropertyValue == null)
            {
                return(true);
            }

            return(!_authorService.AllAuthorPaths().Any(s => context.PropertyValue.ToString().IsParentPath(s.Value)));
        }
        protected override bool IsValid(PropertyValidatorContext context)
        {
            if (context.PropertyValue == null)
            {
                return(true);
            }

            dynamic instance   = context.ParentContext.InstanceToValidate;
            var     instanceId = (int)instance.Id;

            return(!_authorService.AllAuthorPaths().Any(s => s.Value.PathEquals(context.PropertyValue.ToString()) && s.Key != instanceId));
        }
Exemple #6
0
        public override HealthCheck Check()
        {
            // Not best for optimization but due to possible symlinks and junctions, we get mounts based on series path so internals can handle mount resolution.
            var mounts = _authorService.AllAuthorPaths()
                         .Select(p => _diskProvider.GetMount(p.Value))
                         .Where(m => m != null && m.MountOptions != null && m.MountOptions.IsReadOnly)
                         .DistinctBy(m => m.RootDirectory)
                         .ToList();

            if (mounts.Any())
            {
                return(new HealthCheck(GetType(), HealthCheckResult.Error, _localizationService.GetLocalizedString("MountCheckMessage") + string.Join(", ", mounts.Select(m => m.Name)), "#author-mount-ro"));
            }

            return(new HealthCheck(GetType()));
        }
Exemple #7
0
        public void HandleAsync(AuthorDeletedEvent message)
        {
            if (message.DeleteFiles)
            {
                var author = message.Author;

                var rootFolder = _rootFolderService.GetBestRootFolder(message.Author.Path);
                var isCalibre  = rootFolder.IsCalibreLibrary && rootFolder.CalibreSettings != null;

                if (!isCalibre)
                {
                    var allAuthors = _authorService.AllAuthorPaths();

                    foreach (var s in allAuthors)
                    {
                        if (s.Key == author.Id)
                        {
                            continue;
                        }

                        if (author.Path.IsParentPath(s.Value))
                        {
                            _logger.Error("Author path: '{0}' is a parent of another author, not deleting files.", author.Path);
                            return;
                        }

                        if (author.Path.PathEquals(s.Value))
                        {
                            _logger.Error("Author path: '{0}' is the same as another author, not deleting files.", author.Path);
                            return;
                        }
                    }

                    if (_diskProvider.FolderExists(message.Author.Path))
                    {
                        _recycleBinProvider.DeleteFolder(message.Author.Path);
                    }

                    _eventAggregator.PublishEvent(new DeleteCompletedEvent());
                }
            }
        }
Exemple #8
0
        public void Clean()
        {
            if (!_configService.CleanupMetadataImages)
            {
                return;
            }

            var authors         = _authorService.AllAuthorPaths();
            var imageExtensions = new List <string> {
                ".jpg", ".png", ".gif"
            };

            foreach (var author in authors)
            {
                var images = _metaFileService.GetFilesByAuthor(author.Key)
                             .Where(c => c.LastUpdated > new DateTime(2014, 12, 27) && imageExtensions.Any(x => c.RelativePath.EndsWith(x, StringComparison.InvariantCultureIgnoreCase)));

                foreach (var image in images)
                {
                    try
                    {
                        var path = Path.Combine(author.Value, image.RelativePath);
                        if (!IsValid(path))
                        {
                            _logger.Debug("Deleting invalid image file " + path);
                            DeleteMetadata(image.Id, path);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Error(e, "Couldn't validate image {0}", image.RelativePath);
                    }
                }
            }

            _configService.CleanupMetadataImages = false;
        }