diff --git a/implement/PersistentProcess/PersistentProcess.Common/LoadFromLocalFilesystem.cs b/implement/PersistentProcess/PersistentProcess.Common/LoadFromLocalFilesystem.cs new file mode 100644 index 00000000..f993d752 --- /dev/null +++ b/implement/PersistentProcess/PersistentProcess.Common/LoadFromLocalFilesystem.cs @@ -0,0 +1,34 @@ +using System.Collections.Immutable; +using System.IO; +using System.Linq; +using System.Text; + +namespace Kalmit +{ + static public class LoadFromLocalFilesystem + { + static public Composition.TreeComponent LoadTreeFromPath(string path) + { + if (File.Exists(path)) + return new Composition.TreeComponent { BlobContent = File.ReadAllBytes(path).ToImmutableList() }; + + if (!Directory.Exists(path)) + return null; + + var treeEntries = + Directory.EnumerateFileSystemEntries(path) + .Select(fileSystemEntry => + { + var name = (IImmutableList)Encoding.BigEndianUnicode.GetBytes(Path.GetRelativePath(path, fileSystemEntry)).ToImmutableList(); + + return (name, LoadTreeFromPath(fileSystemEntry)); + }) + .ToImmutableList(); + + return new Composition.TreeComponent + { + TreeContent = treeEntries, + }; + } + } +}