public ValidationErrors Validate()
        {
            var validationErrors = new ValidationErrors();

            validationErrors.AddErrorsFor(this.SourceFolder.UUID, this.SourceFolder.Validate());

            foreach (var target in this.TargetFolders)
            {
                validationErrors.AddErrorsFor(target.UUID, target.Validate());

                if (target.IntersectsWith(this.SourceFolder))
                {
                    validationErrors.AddErrorFor(target.UUID, "Selected folder intersects with source folder");
                }

                if (this.TargetFolders.Any(it => it.UUID != target.UUID && it.IntersectsWith(target)))
                {
                    validationErrors.AddErrorFor(target.UUID, "Specified folder is a subpath of one of the added folders");
                }
            }

            var duplicateIds = this.TargetFolders
                               .GroupBy(it => it.FolderPath.ToLowerInvariant())
                               .SelectMany(grp => grp.Skip(1))
                               .Select(it => it.UUID);

            foreach (var duplicateId in duplicateIds)
            {
                validationErrors.AddErrorFor(duplicateId, "Folder duplicated");
            }

            return(validationErrors);
        }
Beispiel #2
0
        public ValidationErrors Validate()
        {
            var errors = new ValidationErrors();

            try
            {
                if (!Directory.Exists(this.FolderPath))
                {
                    errors.AddErrorFor(nameof(this.FolderPath), "Directory not found");
                }
            }
            catch (Exception exception)
            {
                errors.AddErrorFor(nameof(this.FolderPath), $"Exception: {exception.Message}");
            }

            return(errors);
        }
Beispiel #3
0
        public ValidationErrors ValidateAddTarget(string targetPath)
        {
            var validationErrors = new ValidationErrors();
            var irc = StringComparison.InvariantCultureIgnoreCase;

            if (this.FolderSettings.TargetFolders.Any(it => string.Equals(it.FolderPath, targetPath, irc)))
            {
                validationErrors.AddErrorFor("", "Specified folder already added to the list");
            }

            if (this.FolderSettings.TargetFolders.Any(it => it.IntersectsWith(targetPath)))
            {
                validationErrors.AddErrorFor("", "Specified folder is a subpath of one of the added folders");
            }

            if (this.FolderSettings.SourceFolder.IntersectsWith(targetPath))
            {
                validationErrors.AddErrorFor("", "Selected folder intersects with source folder");
            }

            return(validationErrors);
        }