Skip to content

Commit

Permalink
[BMSPT-24] added project, extensions and documents builder
Browse files Browse the repository at this point in the history
  • Loading branch information
BalintBende committed Oct 5, 2023
1 parent ffdf587 commit cf4a311
Show file tree
Hide file tree
Showing 38 changed files with 318 additions and 59 deletions.
3 changes: 2 additions & 1 deletion Tests/Converter/Converter21Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using bcf;
using bcf.Converter;
using NUnit.Framework;

Expand All @@ -9,7 +10,7 @@ namespace Tests.Converter;
public class Converter21Tests {
[SetUp]
public void Setup() {
_converter = new Converter21();
_converter = new bcf.Converter.Bcf21.Converter();
}

private IConverter _converter = null!;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Converter/Converter30Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Tests.Converter;
public class Converter30Tests {
[SetUp]
public void Setup() {
_converter = new Converter30();
_converter = new bcf.Converter.Bcf30.Converter();
}

private IConverter _converter = null!;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Converter/Json/JsonConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ await JsonConverter
var markup = markups.FirstOrDefault()!;
Assert.AreEqual(1, markups.Count);
var documentGuid = markup.Topic.DocumentReferences.FirstOrDefault()?.DocumentGuid;
var document = root.document?.Documents.FirstOrDefault()!;
var document = root.Document?.Documents.FirstOrDefault()!;
Assert.AreEqual("b1d1b7f0-60b9-457d-ad12-16e0fb997bc5", documentGuid);
Assert.AreEqual(documentGuid, document.Guid);
Assert.AreEqual("ThisIsADocument.txt", document.Filename);
Expand Down
5 changes: 5 additions & 0 deletions bcf-converter/Builder/Bcf21/IProjectBuilderExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace bcf.Builder.Bcf21;

public interface IProjectBuilderExtension<out TBuilder> {
TBuilder AddExtensionSchema(string schema);
}
5 changes: 5 additions & 0 deletions bcf-converter/Builder/Bcf21/IVersionBuilderExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace bcf.Builder.Bcf21;

public interface IVersionBuilderExtension<out TBuilder> {
TBuilder AddDetailedVersion(string version);
}
21 changes: 21 additions & 0 deletions bcf-converter/Builder/Bcf21/ProjectBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using bcf.bcf21;

namespace bcf.Builder.Bcf21;

public partial class ProjectBuilder : IProjectBuilder<ProjectBuilder> {
private readonly ProjectExtension _project = new();

public ProjectBuilder AddProjectName(string name) {
_project.Project.Name = name;
return this;
}

public ProjectBuilder AddProjectId(string id) {
_project.Project.ProjectId = id;
return this;
}

public IProject Build() {
return _project;
}
}
8 changes: 8 additions & 0 deletions bcf-converter/Builder/Bcf21/ProjectBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace bcf.Builder.Bcf21;

public partial class ProjectBuilder : IProjectBuilderExtension<ProjectBuilder> {
public ProjectBuilder AddExtensionSchema(string schema) {
_project.ExtensionSchema = schema;
return this;
}
}
16 changes: 16 additions & 0 deletions bcf-converter/Builder/Bcf21/VersionBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using bcf.bcf21;

namespace bcf.Builder.Bcf21;

public partial class VersionBuilder : IVersionBuilder<VersionBuilder> {
private readonly Version _version = new();

public VersionBuilder AddVersionId(string id) {
_version.VersionId = id;
return this;
}

public IVersion Build() {
return _version;
}
}
8 changes: 8 additions & 0 deletions bcf-converter/Builder/Bcf21/VersionBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace bcf.Builder.Bcf21;

public partial class VersionBuilder : IVersionBuilderExtension<VersionBuilder> {
public VersionBuilder AddDetailedVersion(string version) {
_version.DetailedVersion = version;
return this;
}
}
26 changes: 26 additions & 0 deletions bcf-converter/Builder/Bcf30/DocumentBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using bcf.bcf30;

namespace bcf.Builder.Bcf30;

public class DocumentBuilder : IDocumentBuilder<DocumentBuilder> {
private readonly Document _document = new();

public DocumentBuilder AddGuid(string guid) {
_document.Guid = guid;
return this;
}

public DocumentBuilder AddFileName(string name) {
_document.Filename = name;
return this;
}

public DocumentBuilder AddDescription(string description) {
_document.Description = description;
return this;
}

public IDocument Build() {
return _document;
}
}
19 changes: 19 additions & 0 deletions bcf-converter/Builder/Bcf30/DocumentInfoBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using bcf.bcf30;

namespace bcf.Builder.Bcf30;

public class DocumentInfoBuilder : IDocumentInfoBuilder<DocumentInfoBuilder, DocumentBuilder> {
private readonly DocumentInfo _documentInfo = new();

public DocumentInfoBuilder AddDocument(Action<DocumentBuilder> builder) {
var document =
(Document)BuilderUtils.BuildItem<DocumentBuilder, IDocument>(builder);
_documentInfo.Documents.Add(document);
return this;
}

public IDocumentInfo Build() {
return _documentInfo;
}
}
46 changes: 46 additions & 0 deletions bcf-converter/Builder/Bcf30/ExtensionsBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using bcf.bcf30;

namespace bcf.Builder.Bcf30;

public class ExtensionsBuilder : IExtensionsBuilder<ExtensionsBuilder> {
private readonly Extensions _extensions = new();

public ExtensionsBuilder AddTopicType(string type) {
_extensions.TopicTypes.Add(type);
return this;
}

public ExtensionsBuilder AddTopicStatus(string status) {
_extensions.TopicStatuses.Add(status);
return this;
}

public ExtensionsBuilder AddPriority(string priority) {
_extensions.Priorities.Add(priority);
return this;
}

public ExtensionsBuilder AddTopicLabel(string label) {
_extensions.TopicLabels.Add(label);
return this;
}

public ExtensionsBuilder AddUser(string user) {
_extensions.Users.Add(user);
return this;
}

public ExtensionsBuilder AddSnippetType(string type) {
_extensions.SnippetTypes.Add(type);
return this;
}

public ExtensionsBuilder AddStage(string stage) {
_extensions.Stages.Add(stage);
return this;
}

public IExtensions Build() {
return _extensions;
}
}
21 changes: 21 additions & 0 deletions bcf-converter/Builder/Bcf30/ProjectBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using bcf.bcf30;

namespace bcf.Builder.Bcf30;

public class ProjectBuilder : IProjectBuilder<ProjectBuilder> {
private readonly ProjectInfo _project = new();

public ProjectBuilder AddProjectName(string name) {
_project.Project.Name = name;
return this;
}

public ProjectBuilder AddProjectId(string id) {
_project.Project.ProjectId = id;
return this;
}

public IProject Build() {
return _project;
}
}
16 changes: 16 additions & 0 deletions bcf-converter/Builder/Bcf30/VersionBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using bcf.bcf30;

namespace bcf.Builder.Bcf30;

public class VersionBuilder : IVersionBuilder<VersionBuilder> {
private readonly Version _version = new();

public VersionBuilder AddVersionId(string id) {
_version.VersionId = id;
return this;
}

public IVersion Build() {
return _version;
}
}
7 changes: 7 additions & 0 deletions bcf-converter/Builder/IDocumentBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace bcf.Builder;

public interface IDocumentBuilder<out TBuilder> : IBuilder<IDocument> {
TBuilder AddGuid(string guid);
TBuilder AddFileName(string name);
TBuilder AddDescription(string description);
}
7 changes: 7 additions & 0 deletions bcf-converter/Builder/IDocumentInfoBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;

namespace bcf.Builder;

public interface IDocumentInfoBuilder<out TBuilder, out TDocumentBuilder> : IBuilder<IDocumentInfo> {
TBuilder AddDocument(Action<TDocumentBuilder> builder);
}
11 changes: 11 additions & 0 deletions bcf-converter/Builder/IExtensionsBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace bcf.Builder;

public interface IExtensionsBuilder<out TBuilder> : IBuilder<IExtensions> {
TBuilder AddTopicType(string type);
TBuilder AddTopicStatus(string status);
TBuilder AddPriority(string priority);
TBuilder AddTopicLabel(string label);
TBuilder AddUser(string user);
TBuilder AddSnippetType(string type);
TBuilder AddStage(string stage);
}
5 changes: 0 additions & 5 deletions bcf-converter/Builder/IMarkupBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.ObjectModel;

namespace bcf.Builder;

Expand Down Expand Up @@ -29,14 +28,10 @@ public interface IMarkupBuilder<
TBuilder AddDescription(string description);
TBuilder AddStage(string stage);
TBuilder AddBimSnippet(Action<TBimSnippetBuilder> builder);

TBuilder
AddDocumentReference(Action<TDocumentReferenceBuilder> builder);

TBuilder AddComment(Action<TCommentBuilder> builder);

TBuilder AddViewPoint(Action<TViewPointBuilder> viewPointBuilder,
string snapshot);

TBuilder AddRelatedTopic(string relatedTopicGuid);
}
6 changes: 6 additions & 0 deletions bcf-converter/Builder/IProjectBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace bcf.Builder;

public interface IProjectBuilder<out TBuilder> : IBuilder<IProject> {
TBuilder AddProjectName(string name);
TBuilder AddProjectId(string id);
}
5 changes: 5 additions & 0 deletions bcf-converter/Builder/IVersionBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace bcf.Builder;

public interface IVersionBuilder<out TBuilder> : IBuilder<IVersion> {
TBuilder AddVersionId(string id);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Collections.Concurrent;
using System.IO;
using System.Threading.Tasks;
using bcf.bcf21;
using bcf.Converter;

namespace bcf.Converter;
namespace bcf.Converter.Bcf21;

/// <summary>
/// Converter strategy class for converting BCF 2.1 files to JSON
/// and back.
/// </summary>
public class Converter21 : IConverter {
public class Converter : IConverter {
/// <summary>
/// The method parses the BCF file of version 2.1 and writes into JSON.
/// The root of the BCF zip contains the following files:
Expand All @@ -27,7 +29,7 @@ public async Task BcfToJson(string source, string target) {
// Parsing BCF root file structure
var project = await BcfConverter.ParseProject<ProjectExtension>(source);
var root = new Root {
project = project
Project = project
};

// Parsing topics folder (markups)
Expand Down Expand Up @@ -60,9 +62,9 @@ await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(
target, markups, root);
}

// public async Task ToBcf(string target, ConcurrentBag<IMarkup> markups) {
// //TODO fill root
// var root = new Root();
// await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(target, markups, root);
// }
public async Task ToBcf(string target, ConcurrentBag<IMarkup> markups) {
//TODO fill root
var root = new Root();
await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(target, markups, root);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Collections.Concurrent;
using System.Threading.Tasks;
using bcf.bcf30;

namespace bcf.Converter;
namespace bcf.Converter.Bcf30;

/// <summary>
/// Converter strategy class for converting BCF 3.0 files to JSON
/// and back.
/// </summary>
public class Converter30 : IConverter {
public class Converter : IConverter {
/// <summary>
/// The method parses the BCF file of version 3.0 and writes into JSON.
/// The root of the BCF zip contains the following files:
Expand All @@ -30,9 +31,9 @@ public async Task BcfToJson(string source, string target) {
var projectInfo = await BcfConverter.ParseProject<ProjectInfo>(source);
var documentInfo = await BcfConverter.ParseDocuments<DocumentInfo>(source);
var root = new Root {
extensions = extensions,
project = projectInfo,
document = documentInfo
Extensions = extensions,
Project = projectInfo,
Document = documentInfo
};

// Parsing topics folder (markups)
Expand Down Expand Up @@ -60,4 +61,8 @@ public async Task JsonToBcf(string source, string target) {
// Writing bcf files
await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(target, markups, root);
}

public async Task ToBcf(string target, ConcurrentBag<IMarkup> markups, IRoot root) {
await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(target, markups, root);
}
}
Loading

0 comments on commit cf4a311

Please sign in to comment.