From 42be43c96f30b95d1bf765eecb793e0021804c5c Mon Sep 17 00:00:00 2001 From: Balint Bende Date: Fri, 6 Oct 2023 15:21:57 +0200 Subject: [PATCH] [BMSPT-24] added readme --- README.md | 82 +++++++++++++++++++ bcf-converter.sln.DotSettings.user | 6 +- src/bcf-converter/Builder/BuilderCreator.cs | 37 +++++++++ .../Builder/MarkupBuilderCreator.cs | 7 -- .../Converter/Bcf21/Converter.cs | 21 ++++- .../Converter/Bcf30/Converter.cs | 22 ++++- .../Converter/ConverterContext.cs | 15 +++- src/bcf-converter/Converter/IConverter.cs | 7 ++ src/bcf-converter/Model/Bcf21/Bcf.cs | 5 ++ src/bcf-converter/Model/IBcf.cs | 5 ++ 10 files changed, 188 insertions(+), 19 deletions(-) create mode 100644 src/bcf-converter/Builder/BuilderCreator.cs delete mode 100644 src/bcf-converter/Builder/MarkupBuilderCreator.cs create mode 100644 src/bcf-converter/Model/Bcf21/Bcf.cs create mode 100644 src/bcf-converter/Model/IBcf.cs diff --git a/README.md b/README.md index aeb8a69..b7769c9 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,89 @@ is a zipped file as per the standard. ``` ### As A Library +This C# NuGet library allows you to easily build up convert data into BCF files. +It gives you a straightforward API to build your BCF objects exactly how you want +in your order. +#### Installation +You can install the `BcfConverter` library via NuGet Package Manager or by adding +it to your project's .csproj file. +``` +nuget install BCFConverter +``` + +#### Usage +##### Creating BCF objects +To create a BCF Model, you can use the BuilderCreator class to obtain a builder object. +Then, you can use various functions provided by the builder to fulfill the BCF model +objects. + +**IMPORTANT:** The builder always creates BCF 3.0 models. + +Here's an example: + +```csharp +using BCFConverter; + +// Create a markup builder +var markupBuilder = BuilderCreator.CreateMarkupBuilder(); + +// Build the BCF Markup +var bcfMarkup = markupBuilder + .AddTitle("Simple title") + .AddDescription("This is a description") + .AddLabel("Architecture") + .AddPriority("Critical") + .AddTopicType("Clash") + .AddTopicStatus("Active") + .AddComment(c => c + .AddComment("This is a comment") + .AddDate(DateTime.Now) + .AddAuthor("jimmy@page.com")) + .AddViewPoint(v => v + .AddPerspectiveCamera(pCam => pCam + .AddCamera(cam => cam + .AddViewPoint(10, 10, 10))), + snapshotData) // Provide snapshot data here + .Build(); + +// Create a project builder +var projectBuilder = BuilderCreator.CreateProjectBuilder(); + +// Build the BCF Project +var project = projectBuilder + .AddProjectId("projectId") + .AddProjectName("My project") + .Build(); + +// Create a document builder +var documentBuilder = BuilderCreator.CreateDocumentBuilder(); + +// Build the BCF Document +var document = builder + .AddDocument(d => d + .AddFileName("document.pdf") + .AddDescription("This is a document")) + .Build(); + +// Create an extensions builder +var extBuilder = BuilderCreator.CreateExtensionsBuilder(); + +// Build the BCF Extensions +var extensions = builder + .AddPriority("Critical") + .AddPriority("Major") + .AddPriority("Normal") + .AddPriority("Minor") + .AddTopicType("Issue") + .AddTopicType("Fault") + .AddTopicType("Clash") + .AddTopicType("Remark") + .AddTopicLabel("Architecture") + .AddTopicLabel("Structure") + .AddTopicLabel("MEP") + .Build(); +``` ## File Structure diff --git a/bcf-converter.sln.DotSettings.user b/bcf-converter.sln.DotSettings.user index 5b9561b..64287f3 100644 --- a/bcf-converter.sln.DotSettings.user +++ b/bcf-converter.sln.DotSettings.user @@ -1,8 +1,12 @@  /Users/balintbende/Library/Caches/JetBrains/Rider2022.3/resharper-host/temp/Rider/vAny/CoverageData/_bcf-converter.-403555820/Snapshot/snapshot.utdcvr - <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> <Solution /> </SessionState> + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Solution /> +</SessionState> + diff --git a/src/bcf-converter/Builder/BuilderCreator.cs b/src/bcf-converter/Builder/BuilderCreator.cs new file mode 100644 index 0000000..5b4ddc2 --- /dev/null +++ b/src/bcf-converter/Builder/BuilderCreator.cs @@ -0,0 +1,37 @@ +using BcfConverter.Builder.Bcf30; + +namespace BcfConverter.Builder; + +public static class BuilderCreator { + /// + /// Creates a new instance of `MarkupBuilder` object. + /// + /// + public static MarkupBuilder CreateMarkupBuilder() { + return new MarkupBuilder(); + } + + /// + /// Creates a new instance of `ProjectBuilder` object. + /// + /// + public static ProjectBuilder CreateProjectBuilder() { + return new ProjectBuilder(); + } + + /// + /// Creates a new instance of `ExtensionsBuilder` object. + /// + /// + public static ExtensionsBuilder CreateExtensionsBuilder() { + return new ExtensionsBuilder(); + } + + /// + /// Creates a new instance of `DocumentInfoBuilder` object. + /// + /// + public static DocumentInfoBuilder CreateDocumentBuilder() { + return new DocumentInfoBuilder(); + } +} \ No newline at end of file diff --git a/src/bcf-converter/Builder/MarkupBuilderCreator.cs b/src/bcf-converter/Builder/MarkupBuilderCreator.cs deleted file mode 100644 index 65ff355..0000000 --- a/src/bcf-converter/Builder/MarkupBuilderCreator.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace BcfConverter.Builder; - -public static class MarkupBuilderCreator { - public static Bcf30.MarkupBuilder CreateBuilder() { - return new Bcf30.MarkupBuilder(); - } -} \ No newline at end of file diff --git a/src/bcf-converter/Converter/Bcf21/Converter.cs b/src/bcf-converter/Converter/Bcf21/Converter.cs index 4a6b5ce..4354aba 100644 --- a/src/bcf-converter/Converter/Bcf21/Converter.cs +++ b/src/bcf-converter/Converter/Bcf21/Converter.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using System.IO; +using System.Linq; using System.Threading.Tasks; using BcfConverter.Model; using BcfConverter.Model.Bcf21; @@ -62,9 +63,21 @@ await BcfConverter.WriteBcf( target, markups, root); } - public async Task ToBcf(string target, ConcurrentBag markups, IRoot root) { - //TODO fill root - //var root = new Root(); - //await BcfConverter.WriteBcf(target, markups, root); + /// + /// The method writes the specified BCF 2.1 models to BCF 2.1 files. + /// + /// The target path where the BCF is written. + /// Array of `IMarkup` interface objects. + /// The `IRoot` interface of the BCF, it contains all the root info. + /// + public async Task ToBcf( + string target, + ConcurrentBag markups, + IRoot root) { + var convertedMarkups = + new ConcurrentBag(markups.Select(m => (Markup)m)); + var convertedRoot = (Root)root; + await BcfConverter.WriteBcf( + target, convertedMarkups, convertedRoot); } } \ No newline at end of file diff --git a/src/bcf-converter/Converter/Bcf30/Converter.cs b/src/bcf-converter/Converter/Bcf30/Converter.cs index 275682c..58524f9 100644 --- a/src/bcf-converter/Converter/Bcf30/Converter.cs +++ b/src/bcf-converter/Converter/Bcf30/Converter.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Linq; using System.Threading.Tasks; using BcfConverter.Model; using BcfConverter.Model.Bcf30; @@ -60,10 +61,25 @@ public async Task JsonToBcf(string source, string target) { var markups = await JsonConverter.ParseMarkups(source); // Writing bcf files - await BcfConverter.WriteBcf(target, markups, root); + await BcfConverter.WriteBcf( + target, markups, root); } - public async Task ToBcf(string target, ConcurrentBag markups, IRoot root) { - //await BcfConverter.WriteBcf(target, markups, root); + /// + /// The method writes the specified BCF 3.0 models to BCF 3.0 files. + /// + /// The target path where the BCF is written. + /// Array of `IMarkup` interface objects. + /// The `IRoot` interface of the BCF, it contains all the root info. + /// + public async Task ToBcf( + string target, + ConcurrentBag markups, + IRoot root) { + var convertedMarkups = + new ConcurrentBag(markups.Select(m => (Markup)m)); + var convertedRoot = (Root)root; + await BcfConverter.WriteBcf( + target, convertedMarkups, convertedRoot); } } \ No newline at end of file diff --git a/src/bcf-converter/Converter/ConverterContext.cs b/src/bcf-converter/Converter/ConverterContext.cs index 1cdc2a7..051d8de 100644 --- a/src/bcf-converter/Converter/ConverterContext.cs +++ b/src/bcf-converter/Converter/ConverterContext.cs @@ -25,7 +25,7 @@ public class ConverterContext { /// private IConverter Converter { get; set; } - private IBuilder Builder { get; set; } + //public IBuilder Builder { get; set; } // private IMarkupBuilder _markupBuilder; @@ -47,11 +47,11 @@ private void Init(BcfVersionEnum version) { switch (version) { case BcfVersionEnum.Bcf21: Converter = new Converter.Bcf21.Converter(); - Builder = new Builder.Bcf21.MarkupBuilder(); + //Builder = new Builder.Bcf21.MarkupBuilder(); break; case BcfVersionEnum.Bcf30: Converter = new Converter.Bcf30.Converter(); - Builder = new Builder.Bcf30.MarkupBuilder(); + //Builder = new Builder.Bcf30.MarkupBuilder(); break; default: throw new ArgumentException($"Unsupported BCF version: {version}"); @@ -70,7 +70,14 @@ public async Task Convert(string source, string target) { await Converter.JsonToBcf(source, target)!; } - internal Task ToBcf(string target, ConcurrentBag markups, IRoot root) { + /// + /// The method writes the specified BCF models to BCF files. + /// + /// The target path where the BCF is written. + /// Array of `IMarkup` interface objects. + /// The `IRoot` interface of the BCF, it contains all the root info. + /// + public Task ToBcf(string target, ConcurrentBag markups, IRoot root) { return Converter.ToBcf(target, markups, root); } } \ No newline at end of file diff --git a/src/bcf-converter/Converter/IConverter.cs b/src/bcf-converter/Converter/IConverter.cs index 008c52a..a9cd9a6 100644 --- a/src/bcf-converter/Converter/IConverter.cs +++ b/src/bcf-converter/Converter/IConverter.cs @@ -24,5 +24,12 @@ public interface IConverter { /// Task JsonToBcf(string source, string target); + /// + /// The method writes the specified BCF models to BCF files. + /// + /// The target path where the BCF is written. + /// Array of `IMarkup` interface objects. + /// The `IRoot` interface of the BCF, it contains all the root info. + /// Task ToBcf(string target, ConcurrentBag markups, IRoot root); } \ No newline at end of file diff --git a/src/bcf-converter/Model/Bcf21/Bcf.cs b/src/bcf-converter/Model/Bcf21/Bcf.cs new file mode 100644 index 0000000..e784dab --- /dev/null +++ b/src/bcf-converter/Model/Bcf21/Bcf.cs @@ -0,0 +1,5 @@ +namespace BcfConverter.Model.Bcf21; + +public class Bcf { + +} \ No newline at end of file diff --git a/src/bcf-converter/Model/IBcf.cs b/src/bcf-converter/Model/IBcf.cs new file mode 100644 index 0000000..0a806a2 --- /dev/null +++ b/src/bcf-converter/Model/IBcf.cs @@ -0,0 +1,5 @@ +namespace BcfConverter.Model; + +public class IBcf { + +} \ No newline at end of file