Esempio n. 1
0
        public override CriterionResult Validate(string path)
        {
            //setup the full path by safely adding the extra path.
            string fullPath = Path.Combine(path, SubPath?.Trim('\\') ?? "");

            //check the base type which sees if the directory in the sub path exists first.
            CriterionResult baseResult = base.Validate(path);

            if (!baseResult.IsValid)
            {
                return(baseResult);
            }
            //grab the directories in the path
            var directories = Directory.GetDirectories(fullPath);

            if (directories != null && directories.Length == Count)
            {
                return(new CriterionResult()
                {
                    IsValid = true,
                    Description = Description,
                    Message = $"You have {Count} directories in your {SubPath} folder, good job!"
                });
            }
            else
            {
                return(new CriterionResult()
                {
                    IsValid = false,
                    Description = Description,
                    Message = $"You have {directories?.Length ?? 0} directories in your {SubPath} folder, but you should have {Count}."
                });
            }
        }
Esempio n. 2
0
        public override CriterionResult Validate(string path)
        {
            CriterionResult baseResult = base.Validate(path);

            if (!baseResult.IsValid)
            {
                return(baseResult);
            }
            //setup the full path by safely adding the extra path.
            string fullPath = Path.Combine(path, SubPath?.Trim('\\') ?? "");
            //next step down directories based on the depth specified
            var directories = fullPath.GetDirectoriesAtDepth(Depth);
            var patterns    = FileNamePattern.Split(',');

            if (directories != null && directories.Any())
            {
                //check the file pattern
                foreach (var dir in directories)
                {
                    foreach (var pattern in patterns)
                    {
                        if (Directory.GetFiles(dir, pattern).Any())
                        {
                            return(new CriterionResult()
                            {
                                Description = Description,
                                IsValid = true,
                                Message = $"You have a '{FileNamePattern}' file {Depth} folders deep in your in your '{SubPath}' folder."
                            });
                        }
                    }
                }
            }
            //if we end up here the file is not found
            return(new CriterionResult()
            {
                Description = Description,
                IsValid = false,
                Message = $"Could not find a file like '{FileNamePattern}' {Depth} folders down from the '{SubPath}' folder."
            });
        }