From 9c658fb9419f2926115337e5ca8b9a2501a718c9 Mon Sep 17 00:00:00 2001 From: Jean-Sylvain Boige Date: Wed, 14 Feb 2024 15:28:52 +0100 Subject: [PATCH] optional asynchronous pipeline --- .../AssetConverterConfig.cs | 75 ++++++++++++++++--- .../Mindmapper/MindMapDocumentConfig.cs | 10 ++- .../Ontology/OwlGeneratorConfig.cs | 22 +++++- 3 files changed, 90 insertions(+), 17 deletions(-) diff --git a/Generation/Converters/Argumentum.AssetConverter/AssetConverterConfig.cs b/Generation/Converters/Argumentum.AssetConverter/AssetConverterConfig.cs index f1e83d8c..59a77391 100644 --- a/Generation/Converters/Argumentum.AssetConverter/AssetConverterConfig.cs +++ b/Generation/Converters/Argumentum.AssetConverter/AssetConverterConfig.cs @@ -27,7 +27,7 @@ public class AssetConverterConfig public bool SkipConfigFile { get; set; } = false; - public ConverterMode Mode { get; set; } = ConverterMode.OwlGenerator;// | ConverterMode.WebBasedImageGeneration; + public ConverterMode Mode { get; set; } = ConverterMode.Mindmapper | ConverterMode.OwlGenerator;// | ConverterMode.WebBasedImageGeneration; public bool ForceDebugParams { get; set; } @@ -313,8 +313,8 @@ public string GetBaseTargetDirectory(string language) public bool EnableSVGPrompt { get; set; } = true; - - + + public bool AsynchronousPipeline { get; set; } @@ -384,41 +384,94 @@ public async Task Apply() if (Mode.HasFlag(ConverterMode.BatchImageProcessor)) { + if (AsynchronousPipeline) + { + tasks.Add(Task.Run(() => BatchImageConverterConfig.Apply())); + } + else + { + await BatchImageConverterConfig.Apply(); + } - tasks.Add(Task.Run(() => BatchImageConverterConfig.Apply())); + } if (Mode.HasFlag(ConverterMode.DatasetUpdater)) { - tasks.Add(DatasetUpdaterRootConfig.Apply(this)); + if (AsynchronousPipeline) + { + tasks.Add(Task.Run(() => DatasetUpdaterRootConfig.Apply(this))); + } + else + { + await DatasetUpdaterRootConfig.Apply(this); + } + + } if (Mode.HasFlag(ConverterMode.WebBasedImageGeneration)) { - - tasks.Add(WebBasedGeneratorConfig.Apply(this)); + if (AsynchronousPipeline) + { + tasks.Add(Task.Run(() => WebBasedGeneratorConfig.Apply(this))); + } + else + { + await WebBasedGeneratorConfig.Apply(this); + } + + + } if (Mode.HasFlag(ConverterMode.Mindmapper)) { - tasks.Add(MindMapCreatorConfig.Apply(this)); + if (AsynchronousPipeline) + { + tasks.Add(Task.Run(() => MindMapCreatorConfig.Apply(this))); + } + else + { + await MindMapCreatorConfig.Apply(this); + } + + } if (Mode.HasFlag(ConverterMode.Dnn2sxc)) { - tasks.Add(Task.Run(() => Dnn2sxcConfig.Apply())); + if (AsynchronousPipeline) + { + tasks.Add(Task.Run(() => Dnn2sxcConfig.Apply())); + } + else + { + Dnn2sxcConfig.Apply(); + } + } if (Mode.HasFlag(ConverterMode.OwlGenerator)) { - tasks.Add(OwlGeneratorConfig.Apply(this)); + if (AsynchronousPipeline) + { + tasks.Add(Task.Run(() => OwlGeneratorConfig.Apply(this))); + } + else + { + await OwlGeneratorConfig.Apply(this); + } } + if (AsynchronousPipeline) + { + await Task.WhenAll(tasks); + } - await Task.WhenAll(tasks); // Handling for None or unrecognized values diff --git a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapDocumentConfig.cs b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapDocumentConfig.cs index 3e3afede..01311b81 100644 --- a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapDocumentConfig.cs +++ b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapDocumentConfig.cs @@ -225,7 +225,7 @@ public Func ThumbnailsPathFunc public List FontSizes { get; set; } = new List(new[] { 60, 60, 50, 40, 30, 30, 25, 23, 23, 23, 23 }); - public List EdgeSizes { get; set; } = new List(new[] { 50, 20, 5, 1 }); + public List EdgeSizes { get; set; } = new List(new[] { 20, 10, 5, 1}); public bool InsertCardsThumbnails { get; set; } @@ -425,10 +425,12 @@ private void SetNodeStyle(Node fallacyNode, Fallacy fallacy, int familyNb) if (fallacy.Depth < EdgeSizes.Count) { - fallacyNode.Edge = new Edge() { WIDTH = EdgeSizes[fallacy.Depth].ToString(CultureInfo.InvariantCulture) }; + + if (familyNb > 0) { + fallacyNode.Edge = new Edge() { WIDTH = EdgeSizes[fallacy.Depth - 1].ToString(CultureInfo.InvariantCulture) }; fallacyNode.Edge.COLOR = Colors[familyNb]; fallacyNode.BACKGROUND_COLOR = HLSColor.GetLighterColor(Colors[familyNb]); } @@ -438,6 +440,10 @@ private void SetNodeStyle(Node fallacyNode, Fallacy fallacy, int familyNb) else { fallacyNode.STYLE = "fork"; + if (fallacy.Depth == EdgeSizes.Count) + { + fallacyNode.Edge = new Edge() { WIDTH = EdgeSizes[fallacy.Depth - 1].ToString(CultureInfo.InvariantCulture) }; + } } if (fallacy.Depth <= EdgeSizes.Count) diff --git a/Generation/Converters/Argumentum.AssetConverter/Ontology/OwlGeneratorConfig.cs b/Generation/Converters/Argumentum.AssetConverter/Ontology/OwlGeneratorConfig.cs index 9b72c8e4..7aff611d 100644 --- a/Generation/Converters/Argumentum.AssetConverter/Ontology/OwlGeneratorConfig.cs +++ b/Generation/Converters/Argumentum.AssetConverter/Ontology/OwlGeneratorConfig.cs @@ -84,15 +84,27 @@ public override async Task GenerateFallacyFile(IList fallacies, AssetCo fileName = Path.Combine(targetDirectory, fileName); } - var documentPath = Path.Combine(targetDirectory, DocumentName); + //var documentPath = Path.Combine(targetDirectory, DocumentName); - CreateOwlDocument(fallacies, config, language, documentPath, fileName); + + if (File.Exists(fileName) && !config.OverwriteExistingDocs) + { + Logger.Log($"Skip existing Owl document: {fileName}"); + } + else + { + Logger.Log($"Creating Owl document {DocumentName}"); + CreateOwlDocument(fallacies, config, language, fileName); + } + + + } - private void CreateOwlDocument(IList fallacies, AssetConverterConfig config, string language, string documentPath, string fileName) + private void CreateOwlDocument(IList fallacies, AssetConverterConfig config, string language, string fileName) { - var fallaciesByPath = fallacies.ToDictionary(f => f.Path, f => f); + var fallaciesByPath = fallacies.ToDictionary(f => f.Path, f => f); Fallacy GetParent(Fallacy f) { if (f.Depth <= 1) @@ -307,6 +319,8 @@ Fallacy GetParent(Fallacy f) // WRITE OWL2/XML FILE ontology.ToFile(xmlFormat, fileName); + Logger.LogSuccess($"Owl document {fileName} successfully saved"); + } private RDFResource GetFallacyConcept(Fallacy targetFallacy,