Skip to content

Commit

Permalink
Feature/bmspt 174 upgrade bcf (#14)
Browse files Browse the repository at this point in the history
* [BMSPT-174] refactored bcf extensions to utils

* [BMSPT-174] refactoring of builder interfaces, distinct

* [BMSPT-174] get version, added collection utils

* [BMSPT-174] refactoring of worker and converter, added schema converter, upgrade 2.1 -> 3.0

* [BMSPT-174] updated tests

* [BMSPT-174] added viewpoint converter, updated builders, small fixes

* [BMSPT-174] fixed schema converter

* [BMSPT-174] document update

* [BMSPT-174] reformat BcfBuilder

* [BMSPT-174] added saple tests

* [BMSPT-174] refactoring, fixed comments, added project info conversion

* [BMSPT-174] refactoring, JsonExtension static regex pattern

* [BMSPT-174] fixed converter, get version from json, added different init of converter in worker, updated Readme
  • Loading branch information
BalintBende authored May 8, 2024
1 parent 943ca9e commit 97153dc
Show file tree
Hide file tree
Showing 150 changed files with 2,918 additions and 1,294 deletions.
69 changes: 40 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@ Collaboration Format) files into `json` and vice versa.

The tool converts `BCF` information across formats ~~and versions~~.

## Usage

## Requirements

- dotnet 8

### CLI

The command line interface accepts three arguments:
* the source bcf file or json folder
* the target bcf file or json folder
The command line interface accepts 3 arguments:
* the source bcf file or json folder [REQUIRED]
* the target bcf file or json folder [REQUIRED]
* the target version of bcf [OPTIONAL]

The json representation is one file for every `Markup`, while the BCF format
is a zipped file as per the standard.

```
~ bcf-converter /path/to/source.bcfzip /path/to/target/json/folder
~ bcf-toolkit /path/to/source.bcfzip /path/to/target/json/folder

~ bcf-converter /path/to/source/json/folder /path/to/target.bcfzip
~ bcf-toolkit /path/to/source/json/folder /path/to/target.bcfzip
```

### As A Library
Expand All @@ -32,15 +31,15 @@ BCF files. It gives a straightforward API to build the BCF objects exactly in
the order of the user's choice.

#### Installation
`BcfConverter` library can be installed via NuGet Package Manager or by adding
`Smino.Bcf.Toolkit` library can be installed via NuGet Package Manager or by adding
it to the project's .csproj file.
```
nuget install BCFConverter
nuget install Smino.Bcf.Toolkit
```

#### Usage
##### Creating BCF objects
To create a BCF Model, `BuilderBuilder` class can be used. Then, various
To create a BCF Model, `BcfBuilder` class can be used. Then, various
functions provided by the builder can be used to fulfill the BCF model objects.

Here are some examples:
Expand Down Expand Up @@ -97,7 +96,7 @@ using BcfToolkit.Builder.Bcf30;
await using var stream = new FileStream(source, FileMode.Open, FileAccess.Read);
var builder = new BcfBuilder();
var bcf = await builder
.BuildFromStream(stream);
.BuildFromStream(stream);
```

The default builders can be used if the user prefers not to deal with filling
Expand All @@ -110,38 +109,49 @@ using BcfToolkit.Builder.Bcf30;

var builder = new BcfBuilder();
var bcf = builder
.WithDefaults()
.Build();
.WithDefaults()
.Build();
```
##### Using BCF workers
The workers are implemented to use predefined workflows to convert `BCF` files
into `json`. The aimed BCF version must be set first then `ConverterContext`
class lets the nested object to do the conversion accordingly.
##### Using BCF worker
The worker is implemented to use predefined workflows to convert `BCF` files
into `json` and back. The function decides which workflow must be used according
to the source and target. If the source ends with `.bcfzip` the converter uses
the `BcfZipToJson` for example.

```csharp
using BcfToolkit;
using BcfToolkit.Model;

var version = BcfVersion.Parse(arguments.TargetVersion);
var context = new ConverterContext(version);
await context.Convert("sourcePath", "targetPath");
var worker = new Worker();
await worker.Convert(source, target);
```
The exact converter can be called directly as well for both converting
directions, `BCF` into `json` and back.

The exact worker can be called directly as well for both converting directions,
`BCF` into `json` and back.
```csharp
using BcfToolkit.Converter.Bcf30;

var converter = new Converter()
converter.BcfZipToJson(source, target);
```

```csharp
using BcfToolkit.Worker.Bcf30;
using BcfToolkit.Converter.Bcf30;

var worker = new ConverterWorker()
worker.BcfZipToJson(source, target);
var converter = new Converter()
converter.JsonToBcfZip(source, target);
```

Furthermore `BCF` archive can be consumed as a stream. The version of the source
is established by the code, the aimed BCF version must be set. Then the class
lets the nested converter object to do the conversion accordingly.

```csharp
using BcfToolkit.Worker.Bcf30;
using BcfToolkit;

await using var stream = new FileStream(source, FileMode.Open, FileAccess.Read);

var worker = new ConverterWorker()
worker.JsonToBcfZip(source, target);
var worker = new Worker();
await worker.BuildBcfFromStream(stream);
```

## File Structure
Expand All @@ -166,6 +176,7 @@ named using the `uuid` of the `Topic` within.
|- project.json
|- extensions.json
|- documents.json
|- version.json
```

## Development
Expand Down
1 change: 1 addition & 0 deletions bcf-toolkit.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/SuppressNullableWarningFix/Enabled/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BCF/@EntryIndexedValue">BCF</s:String></wpf:ResourceDictionary>
34 changes: 33 additions & 1 deletion bcf-toolkit.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">/Users/balintbende/Library/Caches/JetBrains/Rider2023.3/resharper-host/temp/Rider/vAny/CoverageData/_bcf-toolkit.-1315391344/Snapshot/snapshot.utdcvr</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=1b697a4b_002Da4a7_002D4127_002Db4e7_002D073d2e2c8d00/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=10e924f2_002Ddfad_002D4c9c_002Dbceb_002Dba57c3e92114/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution #4" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>

<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=1d23a89c_002D2836_002D406a_002Db3d1_002Dba9b60b999b4/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>



<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=69156f6d_002D4f0a_002D4f92_002Dae69_002Da7ef11a55cba/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=7a62edfe_002D16d6_002D4e96_002Db9b6_002D1ade5b4476da/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution #6" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c0a1909e_002Dfdff_002D4140_002D9bbd_002D6a59a9ba0492/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution #5" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>



<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=f23341d3_002De9f8_002D4cc8_002Db98f_002Dd4283d5ad0db/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=f3181371_002Dc3d6_002D478f_002Daaf3_002Dea0fbd47107c/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution #4" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>











Expand Down
42 changes: 17 additions & 25 deletions src/bcf-toolkit/Builder/Bcf21/BcfBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,45 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using BcfToolkit.Converter;
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;

namespace BcfToolkit.Builder.Bcf21;

public class BcfBuilder : IBcfBuilder<
BcfBuilder,
MarkupBuilder,
ProjectBuilder>,
public partial class BcfBuilder : IBcfBuilder<
BcfBuilder,
MarkupBuilder,
ProjectExtensionBuilder>,
IDefaultBuilder<BcfBuilder> {

private readonly Bcf _bcf = new();

public BcfBuilder() {
_bcf.Version = new VersionBuilder()
.WithDefaults()
.Build();
}

public BcfBuilder AddMarkup(Action<MarkupBuilder> builder) {
var markup =
(Markup)BuilderUtils.BuildItem<MarkupBuilder, IMarkup>(builder);
_bcf.Markups.Add(markup);
return this;
}

public BcfBuilder AddMarkups(List<Markup> markups) {
markups.ForEach(m => _bcf.Markups.Add(m));
return this;
}

public BcfBuilder SetProject(Action<ProjectBuilder> builder) {
public BcfBuilder SetProject(Action<ProjectExtensionBuilder> builder) {
var project =
(ProjectExtension)BuilderUtils.BuildItem<ProjectBuilder, IProject>(builder);
(ProjectExtension)BuilderUtils.BuildItem<ProjectExtensionBuilder, IProject>(
builder);
_bcf.Project = project;
return this;
}

public BcfBuilder WithDefaults() {
this
.AddMarkup(m => m.WithDefaults());
this.AddMarkup(m => m.WithDefaults());
return this;
}

public async Task<IBcf> BuildFromStream(Stream source) {
_bcf.Markups = await BcfConverter.ParseMarkups<Markup, VisualizationInfo>(source);
_bcf.Project = await BcfConverter.ParseProject<ProjectExtension>(source);
return BuilderUtils.ValidateItem(_bcf);
}

public IBcf Build() {
public Bcf Build() {
return BuilderUtils.ValidateItem(_bcf);
}
}
21 changes: 21 additions & 0 deletions src/bcf-toolkit/Builder/Bcf21/BcfBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using BcfToolkit.Model.Bcf21;
using BcfToolkit.Utils;

namespace BcfToolkit.Builder.Bcf21;

public partial class BcfBuilder {
public async Task<Bcf> BuildFromStream(Stream source) {
_bcf.Markups =
await BcfExtensions.ParseMarkups<Markup, VisualizationInfo>(source);
_bcf.Project = await BcfExtensions.ParseProject<ProjectExtension>(source);
return BuilderUtils.ValidateItem(_bcf);
}

public BcfBuilder AddMarkups(List<Markup> markups) {
markups.ForEach(m => _bcf.Markups.Add(m));
return this;
}
}
6 changes: 4 additions & 2 deletions src/bcf-toolkit/Builder/Bcf21/BimSnippetBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BcfToolkit.Model;
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model.Bcf21;

namespace BcfToolkit.Builder.Bcf21;
Expand All @@ -7,6 +8,7 @@ public class BimSnippetBuilder :
IBimSnippetBuilder<BimSnippetBuilder>,
IDefaultBuilder<BimSnippetBuilder> {
private readonly BimSnippet _snippet = new();

public BimSnippetBuilder SetSnippetType(string type) {
_snippet.SnippetType = type;
return this;
Expand Down Expand Up @@ -36,7 +38,7 @@ public BimSnippetBuilder WithDefaults() {
return this;
}

public IBimSnippet Build() {
public BimSnippet Build() {
return BuilderUtils.ValidateItem(_snippet);
}
}
5 changes: 3 additions & 2 deletions src/bcf-toolkit/Builder/Bcf21/BitmapBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using BcfToolkit.Model;
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model.Bcf21;

namespace BcfToolkit.Builder.Bcf21;
Expand Down Expand Up @@ -56,7 +57,7 @@ public BitmapBuilder WithDefaults() {
return this;
}

public IBitmap Build() {
public VisualizationInfoBitmap Build() {
return BuilderUtils.ValidateItem(_bitmap);
}
}
2 changes: 2 additions & 0 deletions src/bcf-toolkit/Builder/Bcf21/CameraBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model.Bcf21;

namespace BcfToolkit.Builder.Bcf21;
Expand Down
5 changes: 3 additions & 2 deletions src/bcf-toolkit/Builder/Bcf21/ClippingPlaneBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BcfToolkit.Model;
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model.Bcf21;

namespace BcfToolkit.Builder.Bcf21;
Expand Down Expand Up @@ -29,7 +30,7 @@ public ClippingPlaneBuilder WithDefaults() {
return this;
}

public IClippingPlane Build() {
public ClippingPlane Build() {
return BuilderUtils.ValidateItem(_clippingPlane);
}
}
7 changes: 4 additions & 3 deletions src/bcf-toolkit/Builder/Bcf21/CommentBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using BcfToolkit.Model;
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model.Bcf21;

namespace BcfToolkit.Builder.Bcf21;
Expand Down Expand Up @@ -29,7 +30,7 @@ public CommentBuilder SetComment(string comment) {
return this;
}

public CommentBuilder SetViewPoint(string guid) {
public CommentBuilder SetViewPointGuid(string guid) {
_comment.Viewpoint.Guid = guid;
return this;
}
Expand All @@ -53,7 +54,7 @@ public CommentBuilder WithDefaults() {
return this;
}

public IComment Build() {
public Comment Build() {
return BuilderUtils.ValidateItem(_comment);
}
}
5 changes: 3 additions & 2 deletions src/bcf-toolkit/Builder/Bcf21/ComponentBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BcfToolkit.Model;
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model.Bcf21;

namespace BcfToolkit.Builder.Bcf21;
Expand Down Expand Up @@ -28,7 +29,7 @@ public ComponentBuilder WithDefaults() {
return this;
}

public IComponent Build() {
public Component Build() {
return BuilderUtils.ValidateItem(_component);
}
}
Loading

0 comments on commit 97153dc

Please sign in to comment.