diff --git a/src/YamlValidator/YamlLoader.cs b/src/YamlValidator/YamlLoader.cs index 682e350c..48bf81d2 100644 --- a/src/YamlValidator/YamlLoader.cs +++ b/src/YamlValidator/YamlLoader.cs @@ -4,26 +4,44 @@ using System.Collections.ObjectModel; namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator; + public class YamlLoader { public IReadOnlyDictionary Load(string filePath, string pathType) { var deserializedYaml = new Dictionary(); + if (pathType == Constants.FileTypeName) { var fileName = Path.GetFileName(filePath); var yamlText = Utility.ReadFileData(filePath); deserializedYaml.Add(fileName, yamlText); - return new ReadOnlyDictionary(deserializedYaml); } - - // to do: address edge case of .yml files - var files = Directory.GetFiles(filePath, $"*{Constants.YamlFileExtension}"); - foreach (var file in files) + else if (pathType == Constants.FolderTypeName) { - var fileName = Path.GetFileName(file); - var yamlText = Utility.ReadFileData(file); - deserializedYaml.Add(fileName, yamlText); + // TODO: Determine if argument flag should be required to specify recursive folder search + try + { + var yamlFiles = Directory.EnumerateFiles(filePath, "*" + Constants.YamlFileExtension, SearchOption.AllDirectories); + foreach (var filename in yamlFiles) + { + var fileName = Path.GetFileName(filename); + var yamlText = Utility.ReadFileData(filename); + deserializedYaml.Add(fileName, yamlText); + } + } + catch (UnauthorizedAccessException ex) + { + Console.WriteLine($"Unauthorized access exception: {ex.Message}"); + } + catch (IOException ex) + { + Console.WriteLine($"IO exception: {ex.Message}"); + } + } + else + { + throw new ArgumentException("Invalid path type"); } return new ReadOnlyDictionary(deserializedYaml);