From e4c5fd8b27e6034a082ab79d4f7747dcf17b994c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20R=C3=A4tzel?= Date: Thu, 13 Feb 2020 13:13:46 +0000 Subject: [PATCH] Implementation to load composition from files --- .../LoadFromLocalFilesystem.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 implement/PersistentProcess/PersistentProcess.Common/LoadFromLocalFilesystem.cs 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, + }; + } + } +}