Smino.Bcf.Toolkit
3.1.3
dotnet add package Smino.Bcf.Toolkit --version 3.1.3
NuGet\Install-Package Smino.Bcf.Toolkit -Version 3.1.3
<PackageReference Include="Smino.Bcf.Toolkit" Version="3.1.3" />
paket add Smino.Bcf.Toolkit --version 3.1.3
#r "nuget: Smino.Bcf.Toolkit, 3.1.3"
// Install Smino.Bcf.Toolkit as a Cake Addin #addin nuget:?package=Smino.Bcf.Toolkit&version=3.1.3 // Install Smino.Bcf.Toolkit as a Cake Tool #tool nuget:?package=Smino.Bcf.Toolkit&version=3.1.3
This C# NuGet library allows you to easily build up and 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 BcfToolkit
library via NuGet Package Manager or by adding
it to your project's .csproj file.
nuget install Smino.Bcf.Toolkit
Usage
Creating BCF objects
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:
using BcfToolkit.Builder.Bcf30;
var builder = new BcfBuilder();
var bcf = builder
.AddMarkup(m => m
.SetTitle("Simple title")
.SetDescription("This is a description")
.AddLabel("Architecture")
.SetPriority("Critical")
.SetTopicType("Clash")
.SetTopicStatus("Active")
.AddComment(c => c
.SetComment("This is a comment")
.SetDate(DateTime.Now)
.SetAuthor("jimmy@page.com"))
.AddViewPoint(v => v
.SetPerspectiveCamera(pCam => pCam
.SetCamera(cam => cam
.SetViewPoint(10, 10, 10))),
snapshotData)) // Provide a snapshot data here
.SetExtensions(e => e
.AddPriority("Critical")
.AddPriority("Major")
.AddPriority("Normal")
.AddPriority("Minor")
.AddTopicType("Issue")
.AddTopicType("Fault")
.AddTopicType("Clash")
.AddTopicType("Remark")
.AddTopicLabel("Architecture")
.AddTopicLabel("Structure")
.AddTopicLabel("MEP"))
.SetProject(p => p
.SetProjectId("projectId")
.SetProjectName("My project"))
.SetDocumentInfo(dI => dI
.AddDocument(d => d
.SetFileName("document.pdf")
.SetDescription("This is a document")))
.Build();
The BcfBuilder
class can also consume BCF files as a stream and build up the
model objects.
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);
The default builders can be used if the user prefers not to deal with filling
the required fields. The builder.WithDefaults()
function serves this.
However in certain cases the user may need to replace the component IDs of IFC
objects with the actual GUIDs during the build process.
using BcfToolkit.Builder.Bcf30;
var builder = new BcfBuilder();
var bcf = builder
.WithDefaults()
.Build();
Using BCF worker
The BCF
worker is designed to facilitate the conversion of BCF
files to
JSON
and vice versa using predefined workflows. The appropriate workflow is
selected based on the file extensions of the source and target. For example, if
the source file ends with .bcfzip
, the BcfZipToJson
converter is used.
Basic conversion
using BcfToolkit;
var worker = new Worker();
await worker.Convert(source, target);
Direct converter usage
You can also call specific converters directly for converting between BCF
and
JSON
.
BCF to JSON
using BcfToolkit.Converter.Bcf30;
var converter = new Converter()
converter.BcfZipToJson(source, target);
JSON to BCF
using BcfToolkit.Converter.Bcf30;
var converter = new Converter()
converter.JsonToBcfZip(source, target);
Stream-based conversion
The library supports consuming BCF
archives as streams. The code determines
the version of the source and delegates the conversion to the appropriate nested
converter object, converting it to BCF
3.0 as needed.
BCF from Stream
using BcfToolkit;
await using var stream = new FileStream(source, FileMode.Open, FileAccess.Read);
var worker = new Worker();
var bcf = await worker.BcfFromStream(stream);
BCF to Stream
The worker can generate a file stream from a specified BCF
object, converting
it to the desired version.
IMPORTANT: The user is responsible for disposing of the stream after use.
using BcfToolkit;
var worker = new Worker();
var stream = await worker.ToBcf(bcf, BcfVersionEnum.Bcf30);
// custom code to use the stream...
await stream.FlushAsync();
Specifying Output Stream
You can define an output stream to which the conversion results will be written.
using BcfToolkit;
var worker = new Worker();
var outputStream = new MemoryStream();
worker.ToBcf(bcf, BcfVersionEnum.Bcf30, outputStream);
// custom code to use the stream...
await outputStream.FlushAsync();
Cancellation Support
The worker supports CancellationToken
to allow for the cancellation of
asynchronous operations.
using BcfToolkit;
var worker = new Worker();
var outputStream = new MemoryStream();
var source = new CancellationTokenSource();
var token = source.Token;
worker.ToBcf(bcf, BcfVersionEnum.Bcf30, outputStream, token);
// custom code to use the stream...
await outputStream.FlushAsync();
File Structure
The structure of the BCF is per the standard. There is, however, no standard for the JSON format other than the BCF API specification.
The naming convention for this converter is taken from the BCF API, but the output is opinionated:
There is one JSON for every Markup
and within the structure of the information
follows that of the XML. There are no separate files for screenshots, they are
base64 encoded in the field snapshot_data
of the Viewpoint
. The files are
named using the uuid
of the Topic
within.
|- json
|- 2ea98d1e-77ae-467f-bbc9-1aed1c1785f6.json
|- 3395f1b1-893f-4ca0-8b7d-c2d17d7a9198.json
|- c799e527-a413-43f8-8871-80918a52b0f0.json
|- ...
|- project.json
|- extensions.json
|- documents.json
|- version.json
Development
The development of the tool is ongoing, the table below shows the currently completed features.
BCF 2.0 | BCF 2.1 | BCF 3.0 | JSON 2.0 | JSON 2.1 | JSON 3.0 | |
---|---|---|---|---|---|---|
BCF 2.0 | ||||||
BCF 2.1 | X | |||||
BCF 3.0 | X | |||||
JSON 2.0 | ||||||
JSON 2.1 | X | |||||
JSON 3.0 | X |
The models for the BCF in-memory representation were auto-created from the
latest XSDs using the XmlSchemaClassGenerator
.
~ dotnet tool install --global dotnet-xscgen
~ xscgen -n [namespace] version.xsd
To publish, run the script at dist/publish.sh
.
Contribution
Code style guide can be found in the bcf-toolkit.sln.DotSettings
file.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Json.Net (>= 1.0.33)
- Newtonsoft.Json (>= 13.0.3)
- RecursiveDataAnnotationsValidation (>= 2.0.0)
- Serilog (>= 4.0.0)
- System.CommandLine (>= 2.0.0-beta4.22272.1)
- System.Text.RegularExpressions (>= 4.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.1.3 | 1,526 | 7/31/2024 |
3.1.2 | 62 | 7/30/2024 |
3.1.1 | 72 | 7/26/2024 |
3.1.0 | 92 | 7/26/2024 |
3.0.1 | 148 | 7/22/2024 |
3.0.0 | 62 | 7/19/2024 |
2.3.1 | 151 | 7/12/2024 |
2.3.0 | 62 | 7/4/2024 |
2.2.4 | 80 | 7/2/2024 |
2.2.3 | 64 | 6/28/2024 |
2.2.2 | 62 | 6/27/2024 |
2.2.1 | 62 | 6/26/2024 |
2.2.0 | 54 | 6/25/2024 |
2.1.4 | 63 | 6/13/2024 |
2.1.3 | 71 | 6/5/2024 |
2.1.2 | 58 | 6/4/2024 |
2.1.1 | 63 | 6/3/2024 |
2.1.0 | 84 | 5/22/2024 |
2.0.0 | 73 | 5/8/2024 |
1.0.0 | 90 | 1/29/2024 |
0.0.1 | 151 | 10/13/2023 |