From 6c2ae5cc336260243ccb48eb60048a1c54a4c0fe Mon Sep 17 00:00:00 2001 From: Baudin Date: Sun, 22 Dec 2019 11:21:57 +0100 Subject: [PATCH] Refactoring the File Watcher and working on the JSON schema generation --- APIStrategy.archimate | 45 ++++++ ApplicationTests/CreateModuleInProject.cs | 12 +- ApplicationTests/ModuleStream_tests.cs | 42 ++++++ ApplicationTests/ProjectFileWatcher.cs | 1 + CLI/{wwwroot => Assets}/mermaid.min.js | 0 CLI/{wwwroot => Assets}/mermaid.min.js.map | 0 CLI/CLI.csproj | 7 + CLI/Commands/Commands.Watch.cs | 3 + CLI/Controllers/ModuleController.cs | 2 +- CLI/Module.cs | 58 ++++++-- CLI/ModuleStream.cs | 81 +++++++++++ CLI/ModuleStreamMessage.cs | 48 +++++++ CLI/Project.CarConfig.cs | 18 --- CLI/Project.Watch.cs | 68 ++++++++++ CLI/Project.cs | 151 ++++----------------- CLI/ProjectWatcher.cs | 123 +++++++++++++++++ CLI/Transpiler.cs | 8 +- CLI/wwwroot/build/bundle.css | 2 +- CLI/wwwroot/build/bundle.css.map | 6 +- CLI/wwwroot/index.html | 2 - CompilerTests/JSON/JsonTests.cs | 13 +- CompilerTests/ParserTests_Recursive.cs | 9 +- Configuration/CarConfig.cs | 38 ++---- Configuration/DefaultRestrictions.cs | 36 +++++ Configuration/ErdConfig.cs | 8 ++ Configuration/JsonConfig.cs | 15 ++ Configuration/LexiconConfig.cs | 12 ++ Configuration/XsdConfig.cs | 8 ++ Mapper.HTML/HTMLMapper.cs | 1 + Mapper.HTML/HtmlTableMapper.cs | 45 ++++++ Mapper.JSON/ASTAliasToJSchema.cs | 68 ++++++++++ Mapper.JSON/ASTTypeToJSchema.cs | 68 +++------- Mapper.JSON/JsonMapper.cs | 105 +++++++++++--- Mapper.JSON/Mapper.JSON.csproj | 1 + web/src/main.js | 11 -- 35 files changed, 843 insertions(+), 272 deletions(-) create mode 100644 APIStrategy.archimate create mode 100644 ApplicationTests/ModuleStream_tests.cs rename CLI/{wwwroot => Assets}/mermaid.min.js (100%) rename CLI/{wwwroot => Assets}/mermaid.min.js.map (100%) create mode 100644 CLI/ModuleStream.cs create mode 100644 CLI/ModuleStreamMessage.cs delete mode 100644 CLI/Project.CarConfig.cs create mode 100644 CLI/Project.Watch.cs create mode 100644 CLI/ProjectWatcher.cs create mode 100644 Configuration/DefaultRestrictions.cs create mode 100644 Configuration/ErdConfig.cs create mode 100644 Configuration/JsonConfig.cs create mode 100644 Configuration/LexiconConfig.cs create mode 100644 Configuration/XsdConfig.cs create mode 100644 Mapper.JSON/ASTAliasToJSchema.cs diff --git a/APIStrategy.archimate b/APIStrategy.archimate new file mode 100644 index 0000000..fccf945 --- /dev/null +++ b/APIStrategy.archimate @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Dit is de API/EndPoint waar wij een beschrijving va nodig hebben. + + + + diff --git a/ApplicationTests/CreateModuleInProject.cs b/ApplicationTests/CreateModuleInProject.cs index 3582509..715fd7f 100644 --- a/ApplicationTests/CreateModuleInProject.cs +++ b/ApplicationTests/CreateModuleInProject.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using CLI; using Xunit; @@ -11,6 +12,15 @@ public class CreateModuleInProject: IDisposable readonly Project project; public CreateModuleInProject() { + try + { + Directory.Delete(dir, true); + } + catch (Exception) + { + Debug.WriteLine("Delete Directory failed in unit test."); + } + Directory.CreateDirectory(dir); project = new Project(dir); } @@ -33,7 +43,7 @@ public void CreateModule() public void Dispose() { project.Dispose(); - Directory.Delete(dir, true); + //Directory.Delete(dir, true); } private string path(string add) diff --git a/ApplicationTests/ModuleStream_tests.cs b/ApplicationTests/ModuleStream_tests.cs new file mode 100644 index 0000000..e774c72 --- /dev/null +++ b/ApplicationTests/ModuleStream_tests.cs @@ -0,0 +1,42 @@ +using System; +using System.Threading.Tasks; +using CLI; +using Xunit; + +namespace ApplicationTests +{ + + public class ModuleStream_tests : IDisposable + { + ModuleStream moduleStream; + + public ModuleStream_tests() + { + moduleStream = new ModuleStream(); + } + + [Fact] + public Task CreateModuleStream() + { + var tcs = new TaskCompletionSource(); + moduleStream.Subscribe("Logger", message => + { + Assert.NotNull(message); + Assert.Equal("First Message", message.ModuleName); + Assert.Equal("Path", message.FileFullPath); + Assert.Equal(MessageType.ModuleChanged, message.MessageType); + + tcs.TrySetResult(true); + }); + + moduleStream.Publish(new ModuleStreamMessage("First Message", "Path", MessageType.ModuleChanged)); + + return tcs.Task; + } + + public void Dispose() + { + moduleStream.Dispose(); + } + } +} diff --git a/ApplicationTests/ProjectFileWatcher.cs b/ApplicationTests/ProjectFileWatcher.cs index 09944cc..96f2380 100644 --- a/ApplicationTests/ProjectFileWatcher.cs +++ b/ApplicationTests/ProjectFileWatcher.cs @@ -21,6 +21,7 @@ public ProjectFileWatcher(ITestOutputHelper output) } catch (Exception) { Debug.WriteLine("Delete Directory failed in unit test."); } + Directory.CreateDirectory(dir); this.output = output; project = new Project(dir); diff --git a/CLI/wwwroot/mermaid.min.js b/CLI/Assets/mermaid.min.js similarity index 100% rename from CLI/wwwroot/mermaid.min.js rename to CLI/Assets/mermaid.min.js diff --git a/CLI/wwwroot/mermaid.min.js.map b/CLI/Assets/mermaid.min.js.map similarity index 100% rename from CLI/wwwroot/mermaid.min.js.map rename to CLI/Assets/mermaid.min.js.map diff --git a/CLI/CLI.csproj b/CLI/CLI.csproj index c601cf8..9fd5e16 100644 --- a/CLI/CLI.csproj +++ b/CLI/CLI.csproj @@ -25,6 +25,7 @@ + @@ -35,6 +36,8 @@ + + @@ -44,4 +47,8 @@ PreserveNewest + + + + diff --git a/CLI/Commands/Commands.Watch.cs b/CLI/Commands/Commands.Watch.cs index ab0c70a..e9b667b 100644 --- a/CLI/Commands/Commands.Watch.cs +++ b/CLI/Commands/Commands.Watch.cs @@ -48,6 +48,9 @@ To quit the application press 'q' project.Watch(); + while (Console.ReadKey().Key != ConsoleKey.Q) { } + Console.WriteLine(); + SignalSingleton.ExitSignal.Dispatch(); return 0; }); diff --git a/CLI/Controllers/ModuleController.cs b/CLI/Controllers/ModuleController.cs index 2cf3514..b569a54 100644 --- a/CLI/Controllers/ModuleController.cs +++ b/CLI/Controllers/ModuleController.cs @@ -93,7 +93,7 @@ public IActionResult GetModuleText(string module) var m = Project.Current?.FindModule(module); if (m is null) return NotFound(); - return Ok(m.Generator.Code); + return Ok(m.Code); } [HttpPost("/api/module/{module}")] diff --git a/CLI/Module.cs b/CLI/Module.cs index 7174433..4051458 100644 --- a/CLI/Module.cs +++ b/CLI/Module.cs @@ -12,7 +12,7 @@ namespace CLI public class Module : IDisposable { public string Name { get; } - public string Path { get; } + public string FilePath { get; } public string BasePath { get; } public string OutPath { get; } public Project Project { get; } @@ -21,9 +21,23 @@ public class Module : IDisposable public ASTGenerator Generator { get; private set; } public DateTime LastParsed { get; private set; } + public string Code + { + get + { + if (Generator.Code == String.Empty) + { + return ReadModuleText(); + } else + { + return Generator.Code; + } + } + } + public Module(string path, string basePath, Project project) { - this.Path = path; + this.FilePath = path; this.BasePath = basePath; this.Name = CreateModuleName(); this.OutPath = System.IO.Path.GetFullPath($"out/{Name}", basePath); @@ -45,7 +59,7 @@ public void Parse() public void SaveModuleOutput(bool decend = true, bool suppressMessage = false) { - this.Transpiler.StartTranspilation(this.Name, Project.CarConfig?.ErdConfig ?? new ErdConfig()); + this.Transpiler.StartTranspilation(this.Name); if (!suppressMessage) { Console.WriteLine($"Perfectly parsed: {Name}"); @@ -58,13 +72,14 @@ public void SaveModuleOutput(bool decend = true, bool suppressMessage = false) SaveResult(key, value); } - // Trickery to no regenerate infinately... + // Trickery to not parse infinately... // TODO: replace with propper topological order... if (decend) { // We would now also want to resolve the other modules // which depend upon this module so that they are automatically // regenerated and their output changed. + // TODO: notice circular dependencies, remove diamond of death... this.Project .Modules .ToList() @@ -76,6 +91,17 @@ public void SaveModuleOutput(bool decend = true, bool suppressMessage = false) }); } } + public void Clean() + { + try + { + System.IO.Directory.Delete(OutPath); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } public IEnumerable GetDescriptions() { @@ -89,7 +115,7 @@ public bool SaveCode(string source) try { - System.IO.File.WriteAllText(this.Path, source); + System.IO.File.WriteAllText(this.FilePath, source); return true; } catch (Exception ex) @@ -103,7 +129,7 @@ private string ReadModuleText() { try { - using (var fs = new FileStream(this.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var fs = new FileStream(this.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var sr = new StreamReader(fs)) { @@ -128,25 +154,31 @@ private void SaveResult(string fileName, string source) private string CreateModuleName() { - var p = Path.Replace(BasePath, "").Replace("/", ".").Replace("\\", ".").Replace(".car", ""); - if (p.StartsWith(".", StringComparison.Ordinal)) - { - p = p.Substring(1); - } - return p; + return Module.FromPathToName(this.FilePath, this.BasePath); } public override string ToString() { return $@" Module: {Name} -Path: {Path} +Path: {FilePath} Dir: {BasePath} LastParsed: {LastParsed} "; } public void Dispose(){} + + public static string FromPathToName(string path, string basePath) + { + var p = path.Replace(basePath, "").Replace("/", ".").Replace("\\", ".").Replace(".car", ""); + if (p.StartsWith(".", StringComparison.Ordinal)) + { + p = p.Substring(1); + } + return p; + } + } public static class DictionaryHelpers diff --git a/CLI/ModuleStream.cs b/CLI/ModuleStream.cs new file mode 100644 index 0000000..a764e3a --- /dev/null +++ b/CLI/ModuleStream.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Linq; +using System.Reactive.Subjects; + +namespace CLI +{ + public class ModuleStream : IDisposable + { + + private Subject moduleMessageSubject; + private IDictionary subscribers; + + public ModuleStream() + { + moduleMessageSubject = new Subject(); + subscribers = new Dictionary(); + } + + public void Dispose() + { + if (moduleMessageSubject != null) + { + moduleMessageSubject.Dispose(); + } + + foreach (var subscriber in subscribers) + { + subscriber.Value.Dispose(); + } + } + + + /// + /// Publish a ModuleStreamMessage, triggering the subscriptions. + /// + /// + public void Publish(ModuleStreamMessage moduleMessage) + { + moduleMessageSubject.OnNext(moduleMessage); + } + + + /// + /// Subscribe to all publications of a ModuleStreamMessage + /// + /// + /// + public void Subscribe(string subscriberName, Action action) + { + if (!subscribers.ContainsKey(subscriberName)) + { + subscribers.Add(subscriberName, moduleMessageSubject.Subscribe(action)); + } + } + + + /// + /// Only subscribe to messages with a certain message type. This way you + /// can filter out those messages which will be handled by other systems. + /// + /// Simple unique name of the subscriber + /// The message type you would like to subscribe to + /// The action which you'd want to take one a valid message is published. + public void Subscribe(string subscriberName, MessageType messageType, Action action) + { + if (!subscribers.ContainsKey(subscriberName)) + { + subscribers.Add( + subscriberName, + moduleMessageSubject + .Where(msm => msm.MessageType == messageType) + .Subscribe(action) + ); + } + } + + + } + +} diff --git a/CLI/ModuleStreamMessage.cs b/CLI/ModuleStreamMessage.cs new file mode 100644 index 0000000..7dae24c --- /dev/null +++ b/CLI/ModuleStreamMessage.cs @@ -0,0 +1,48 @@ +using System; +namespace CLI +{ + public class ModuleStreamMessage + { + public string ModuleName { get; } + public string FileFullPath { get; } + public MessageType MessageType { get; } + public string? OldModuleName { get; } + public string? OldFileFullPath { get; } + + public ModuleStreamMessage(string moduleName, string fileFullpath, MessageType messageType) + { + this.ModuleName = moduleName; + this.FileFullPath = fileFullpath; + this.MessageType = messageType; + } + public ModuleStreamMessage(string moduleName, string fileFullpath, string oldModuleName, string oldFileFullPath, MessageType messageType) + { + this.ModuleName = moduleName; + this.FileFullPath = fileFullpath; + this.OldModuleName = oldModuleName; + this.OldFileFullPath = oldFileFullPath; + this.MessageType = messageType; + } + + + public override string ToString() + { + if (OldModuleName is null) + { + return $"{MessageType.ToString("g")}: {ModuleName}"; + } + else + { + return $"{MessageType.ToString("g")}: from {OldModuleName}, to {ModuleName}"; + } + } + } + + public enum MessageType + { + ModuleCreated, + ModuleChanged, + ModuleDeleted, + ModuleMoved + } +} diff --git a/CLI/Project.CarConfig.cs b/CLI/Project.CarConfig.cs deleted file mode 100644 index dc34337..0000000 --- a/CLI/Project.CarConfig.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Configuration; - -namespace CLI -{ - public partial class Project - { - private void InitCarConfig() - { - this.CarConfig = CarConfig.Load(this.ConfigPath); - if (this.CarConfig is null) - { - this.CarConfig = new CarConfig(); - this.CarConfig.Save(this.ConfigPath); - } - } - } -} diff --git a/CLI/Project.Watch.cs b/CLI/Project.Watch.cs new file mode 100644 index 0000000..394bfa4 --- /dev/null +++ b/CLI/Project.Watch.cs @@ -0,0 +1,68 @@ +using System; +using System.Linq; +using CLI.Signals; + +namespace CLI +{ + public partial class Project + { + public void Watch() + { + var projectWatcher = new ProjectFilesWatcher(this.BasePath); + projectWatcher.Start(); + SignalSingleton.ExitSignal.Subscribe(() => + { + projectWatcher.Dispose(); + }); + + projectWatcher.ModuleStream.Subscribe("Logger", msm => + { + Console.WriteLine($"{msm}"); + }); + + projectWatcher.ModuleStream.Subscribe("OnChange", MessageType.ModuleChanged, msm => + { + var module = this.Modules.FirstOrDefault(m => m.Name == msm.ModuleName); + if (module != null) + { + module.Parse(); + module.SaveModuleOutput(false); + } + }); + + projectWatcher.ModuleStream.Subscribe("OnCreate", MessageType.ModuleCreated, msm => + { + var module = Modules.FirstOrDefault(m => m.Name == msm.ModuleName); + if (module is null) + { + module = new Module(msm.FileFullPath, this.BasePath, this); + Modules.Add(module); + } + }); + + projectWatcher.ModuleStream.Subscribe("OnDelete", MessageType.ModuleDeleted, msm => + { + var module = Modules.FirstOrDefault(m => m.Name == msm.ModuleName); + if (!(module is null)) + { + module.Clean(); + Modules.Remove(module); + } + }); + + projectWatcher.ModuleStream.Subscribe("OnMove", MessageType.ModuleMoved, msm => + { + var moduleOld = Modules.FirstOrDefault(m => m.Name == msm.ModuleName); + if (!(moduleOld is null)) + { + moduleOld.Clean(); + Modules.Remove(moduleOld); + } + var module = new Module(msm.FileFullPath, this.BasePath, this); + Modules.Add(module); + module.Parse(); + module.SaveModuleOutput(); + }); + } + } +} diff --git a/CLI/Project.cs b/CLI/Project.cs index 6bc88ea..52e92db 100644 --- a/CLI/Project.cs +++ b/CLI/Project.cs @@ -14,19 +14,35 @@ namespace CLI { public partial class Project : IDisposable { + public static Project? Current { get; private set; } - public string Path { get; } = ""; + /// + /// The Directory in which the project is created. This is the root path, + /// the path where the zdragon.json file is located. + /// + public string BasePath { get; } = ""; + + /// + /// Where the assets, the results are published to. + /// public string OutPath { get; } = ""; + + /// + /// Where the zdragon.json file is located. + /// public string ConfigPath { get; } = ""; - public CarConfig? CarConfig { get; private set; } + + + public CarConfig CarConfig { get; private set; } public ObservableCollection Modules { get; } = new ObservableCollection(); public Project(string path) { - this.Path = path; - this.OutPath = System.IO.Path.GetFullPath($"out", this.Path); - this.ConfigPath = System.IO.Path.GetFullPath("zdragon.json", this.Path); + this.BasePath = path; + this.OutPath = Path.GetFullPath($"out", this.BasePath); + this.ConfigPath = Path.GetFullPath("zdragon.json", this.BasePath); + this.CarConfig = CarConfig.Load(this.ConfigPath); Directory.CreateDirectory(OutPath); @@ -38,7 +54,6 @@ public Project(string path) module.Parse(); } - InitCarConfig(); CreateAssets(); Project.Current = this; @@ -68,14 +83,15 @@ public void Parse() private void CreateAssets() { - // Nothing yet + Helpers.ReadAndWriteAsset("mermaid.min.js", this.OutPath); + Helpers.ReadAndWriteAsset("mermaid.min.js.map", this.OutPath); } public void CreateModule(string name) { var fileName = String.Join("/", name.Split(".").Select(UppercaseFirst)) + ".car"; - var modulePath = System.IO.Path.GetFullPath(fileName, this.Path); + var modulePath = System.IO.Path.GetFullPath(fileName, this.BasePath); var directoryName = System.IO.Path.GetDirectoryName(modulePath); Directory.CreateDirectory(directoryName); try @@ -131,119 +147,7 @@ internal List GetAstForModule(string moduleName) return this.Modules.FirstOrDefault(m => m.Name == name); } - public int Watch() - { - // Create a new FileSystemWatcher and set its properties. - using var watcher = new FileSystemWatcher - { - IncludeSubdirectories = true, - Path = this.Path, - - // Watch for changes in LastAccess and LastWrite times, and - // the renaming of files or directories. - NotifyFilter = NotifyFilters.LastAccess - | NotifyFilters.LastWrite - | NotifyFilters.FileName - | NotifyFilters.DirectoryName, - - // Only watch text files. - Filter = "*.car" - }; - - // Add event handlers. - watcher.Changed += OnChanged; - watcher.Created += OnCreate; - watcher.Deleted += OnDelete; - watcher.Renamed += OnRenamed; - - SignalSingleton.ExitSignal.Subscribe(() => - { - Console.WriteLine("Disposing the file watcher..."); - watcher.Dispose(); - }); - - // Begin watching. - watcher.EnableRaisingEvents = true; - while (Console.ReadKey().Key != ConsoleKey.Q) { } - Console.WriteLine(); - - return SignalSingleton.ExitSignal.Dispatch(); - } - - - // Define the event handlers. - private void OnChanged(object source, FileSystemEventArgs e) - { - try - { - var module = Modules.FirstOrDefault(m => m.Path == e.FullPath); - if (!(module is null)) - { - module.Parse(); - module.SaveModuleOutput(); - } - else - { - module = new Module(e.FullPath, this.Path, this); - module.Parse(); - module.SaveModuleOutput(); - Modules.Add(module); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - private void OnCreate(object source, FileSystemEventArgs e) - { - try - { - var module = Modules.FirstOrDefault(m => m.Path == e.FullPath); - if (module is null) - { - Console.WriteLine($"{e.ChangeType}: {e.FullPath}"); - module = new Module(e.FullPath, this.Path, this); - Modules.Add(module); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - private void OnDelete(object source, FileSystemEventArgs e) - { - try - { - Console.WriteLine($"{e.ChangeType}: {e.FullPath}"); - Modules.Remove(Modules.FirstOrDefault(m => m.Path == e.FullPath)); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - private void OnRenamed(object source, RenamedEventArgs e) - { - try - { - Console.WriteLine($"{e.ChangeType}: {e.OldFullPath} renamed to {e.FullPath}"); - Modules.Remove(Modules.FirstOrDefault(m => m.Path == e.OldFullPath)); - - var module = new Module(e.FullPath, this.Path, this); - Modules.Add(module); - module.Parse(); - module.SaveModuleOutput(false); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } + public void Dispose() { @@ -255,7 +159,7 @@ private static class Helpers public static string ReadAsset(string name) { var assembly = Assembly.GetExecutingAssembly(); - var resourceName = name; + var resourceName = "CLI.Assets." + name; using (var stream = assembly.GetManifestResourceStream(resourceName)) { @@ -283,7 +187,8 @@ public static void WriteAsset(string path, string content) public static void ReadAndWriteAsset(string assetName, string outPath) { - Helpers.WriteAsset(outPath, Helpers.ReadAsset(assetName)); + var outName = System.IO.Path.GetFullPath(assetName, outPath); + Helpers.WriteAsset(outName, Helpers.ReadAsset(assetName)); } } diff --git a/CLI/ProjectWatcher.cs b/CLI/ProjectWatcher.cs new file mode 100644 index 0000000..b01e817 --- /dev/null +++ b/CLI/ProjectWatcher.cs @@ -0,0 +1,123 @@ +using System; +using System.IO; + +namespace CLI +{ + public class ProjectFilesWatcher : IDisposable + { + public string BasePath { get; } + private FileSystemWatcher? watcher; + public ModuleStream ModuleStream { get; } = new ModuleStream(); + + public ProjectFilesWatcher(string basePath) + { + this.BasePath = basePath; + } + + public void Start() + { + // Create a new FileSystemWatcher and set its properties. + this.watcher = new FileSystemWatcher + { + IncludeSubdirectories = true, + Path = this.BasePath, + + // Watch for changes in LastAccess and LastWrite times, and + // the renaming of files or directories. + NotifyFilter = NotifyFilters.LastAccess + | NotifyFilters.LastWrite + | NotifyFilters.FileName + | NotifyFilters.DirectoryName, + + // Only watch text files. + Filter = "*.car" + }; + + // Add event handlers. + watcher.Changed += OnChanged; + watcher.Created += OnCreate; + watcher.Deleted += OnDelete; + watcher.Renamed += OnRenamed; + + // Begin watching. + watcher.EnableRaisingEvents = true; + } + + // Define the event handlers. + private void OnChanged(object source, FileSystemEventArgs e) + { + try + { + ModuleStream.Publish(new ModuleStreamMessage( + Module.FromPathToName(e.FullPath, this.BasePath), + e.FullPath, + MessageType.ModuleChanged + )); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + private void OnCreate(object source, FileSystemEventArgs e) + { + try + { + ModuleStream.Publish(new ModuleStreamMessage( + Module.FromPathToName(e.FullPath, this.BasePath), + e.FullPath, + MessageType.ModuleCreated + )); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + private void OnDelete(object source, FileSystemEventArgs e) + { + try + { + ModuleStream.Publish(new ModuleStreamMessage( + Module.FromPathToName(e.FullPath, this.BasePath), + e.FullPath, + MessageType.ModuleDeleted + )); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + private void OnRenamed(object source, RenamedEventArgs e) + { + try + { + ModuleStream.Publish(new ModuleStreamMessage( + Module.FromPathToName(e.FullPath, this.BasePath), + e.FullPath, + Module.FromPathToName(e.OldFullPath, this.BasePath), + e.OldFullPath, + MessageType.ModuleMoved + )); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + public void Dispose() { + Console.WriteLine("Disposing of the Project Watcher"); + if (watcher != null) + { + watcher.EnableRaisingEvents = false; + watcher.Dispose(); + } + } + } + +} diff --git a/CLI/Transpiler.cs b/CLI/Transpiler.cs index 24e15f7..654568d 100644 --- a/CLI/Transpiler.cs +++ b/CLI/Transpiler.cs @@ -34,7 +34,7 @@ public Transpiler(ASTGenerator generator, Project project) this.Project = project; XsdMapper = new XSDMapper(generator); HtmlMapper = new HtmlMapper(generator); - JsonMapper = new JsonMapper(generator); + JsonMapper = new JsonMapper(generator, project.CarConfig); DescriptionMapper = new DescriptionMapper(generator); } @@ -64,7 +64,7 @@ public Dictionary JsonToString() } - public void StartTranspilation(string moduleName, ErdConfig erdConfig) + public void StartTranspilation(string moduleName) { this.Imports = ImportResolver.ResolveImports(this.Generator); this.Generator.Resolve(this.Imports); @@ -72,10 +72,10 @@ public void StartTranspilation(string moduleName, ErdConfig erdConfig) this.XsdMapper = new XSDMapper(this.Generator); this.XsdMapper.Start().ToList(); - this.HtmlMapper = new HtmlMapper(this.Generator, erdConfig); + this.HtmlMapper = new HtmlMapper(this.Generator, this.Project.CarConfig.ErdConfig); this.HtmlMapper.Start().ToList(); - this.JsonMapper = new JsonMapper(this.Generator); + this.JsonMapper = new JsonMapper(this.Generator, this.Project.CarConfig); this.JsonMapper.Start(); } diff --git a/CLI/wwwroot/build/bundle.css b/CLI/wwwroot/build/bundle.css index dc130f9..685ff8a 100644 --- a/CLI/wwwroot/build/bundle.css +++ b/CLI/wwwroot/build/bundle.css @@ -1,7 +1,7 @@ main.svelte-1kds1eb{text-align:center;padding:1em;max-width:240px;margin:0 auto}@media(min-width: 640px){main.svelte-1kds1eb{max-width:none}} -tr.svelte-1aug0lv:hover{cursor:pointer} textarea.svelte-nhavks{width:750px;min-height:250px} .preview.svelte-9zwial{height:calc(100% - 60px)}iframe.svelte-9zwial{width:100%;margin:2rem 0;height:100%;border:none} +tr.svelte-1aug0lv:hover{cursor:pointer} .errors.svelte-1l9twu{position:fixed;right:1rem;top:6rem}.error.svelte-1l9twu{min-width:300px;max-width:700px}.error.svelte-1l9twu pre.svelte-1l9twu{overflow-wrap:break-word}.editor-container.svelte-1l9twu{margin-top:1rem}.editor-container.svelte-1l9twu,#editor.svelte-1l9twu{height:calc(100% - 4rem)} .topology.svelte-sq8u03{height:calc(100% - 4rem)}#topology.svelte-sq8u03{height:100%}#topology>.svelte-sq8u03:focus{outline:none !important}.options-form.svelte-sq8u03{position:fixed;right:10px;bottom:10px} ul.svelte-wjec8i{list-style:none;text-align:left} diff --git a/CLI/wwwroot/build/bundle.css.map b/CLI/wwwroot/build/bundle.css.map index 7b14041..4c32a26 100644 --- a/CLI/wwwroot/build/bundle.css.map +++ b/CLI/wwwroot/build/bundle.css.map @@ -3,9 +3,9 @@ "file": "bundle.css", "sources": [ "../../../web/src/App.svelte", - "../../../web/src/Lexicon.svelte", "../../../web/src/LexiconAdmin.svelte", "../../../web/src/Preview.svelte", + "../../../web/src/Lexicon.svelte", "../../../web/src/Editor.svelte", "../../../web/src/ModuleTopology.svelte", "../../../web/src/FileTree.svelte", @@ -14,9 +14,9 @@ ], "sourcesContent": [ "\n\n\n\n
\n\n navigator.navigate('index')}>\n Home\n \n navigator.navigate('module-topology')}>\n Topology\n \n navigator.navigate('lexicon')}>\n Lexicon\n \n {#if navigator.module}\n navigator.navigate('editor')}>\n Editor\n \n navigator.navigate('preview')}>\n Preview\n \n {/if}\n
\n\n{#if route === 'index'}\n \n{:else if route === 'lexicon'}\n \n{:else if route === 'add-lexicon'}\n \n{:else if route === 'edit-lexicon'}\n \n{:else if route === 'lexicon-admin'}\n \n{:else if route === 'preview'}\n \n{:else if route === 'editor'}\n \n{:else if route === 'config'}\n \n{:else if route === 'module-topology'}\n \n{:else if route === 'module-create'}\n \n{:else}\n \n{/if}\n", - "\n\n\n\n
\n

Search your lexicon!

\n
\n {\n navigator.navigate('add-lexicon');\n }}>\n Create\n \n

Search your lexicon:

\n e.code === 'Enter' && onkeyup(e.target.value)}\n on:change={e => findData(e.target.value)} />\n
\n
\n\n \n \n \n \n \n \n {#each data as d}\n navigator.navigate('edit-lexicon', d.id)}>\n \n \n \n \n {/each}\n \n
DomainNameDescription
{d.domain}{d.name}{d.description}
\n", "\n\n\n\n

Domains

\n

Please give the domains you would like to restrict your lexicon to.

\n