Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:bimspot/bcf-converter into featu…
Browse files Browse the repository at this point in the history
…re/BMSPT-283-delegate-methods

# Conflicts:
#	bcf-toolkit.sln.DotSettings.user
#	src/bcf-toolkit/Builder/Bcf21/Interfaces/IViewPointBuilder.cs
#	src/bcf-toolkit/Builder/Bcf30/Interfaces/IViewPointBuilder.cs
#	src/bcf-toolkit/Builder/Bcf30/ViewPointBuilder.cs
#	src/bcf-toolkit/Converter/Bcf21/Converter.cs
#	src/bcf-toolkit/Converter/Bcf21/FileWriter.cs
#	src/bcf-toolkit/Converter/Bcf21/SchemaConverterToBcf30.cs
#	src/bcf-toolkit/Converter/Bcf30/Converter.cs
#	src/bcf-toolkit/Converter/Bcf30/FileWriter.cs
#	src/bcf-toolkit/Converter/Bcf30/SchemaConverterToBcf21.cs
#	src/bcf-toolkit/Model/Bcf21/MarkupExtensions.cs
#	src/bcf-toolkit/Model/Bcf21/VisInfo.cs
#	src/bcf-toolkit/Model/Bcf30/MarkupExtensions.cs
#	src/bcf-toolkit/Program.cs
#	src/bcf-toolkit/README.md
#	src/bcf-toolkit/Utils/BcfExtensions.cs
#	src/bcf-toolkit/Utils/ZipArchiveEntryExtensions.cs
#	src/bcf-toolkit/Utils/ZipArchiveExtensions.cs
#	src/tests/Converter/Bcf21/FileWriterTest.cs
#	src/tests/Converter/Bcf30/ConverterTests.cs
#	src/tests/Converter/Bcf30/FileWriterTests.cs
#	src/tests/WorkerTests.cs
  • Loading branch information
BalintBende committed Aug 6, 2024
2 parents f7c3488 + 846135b commit 6957093
Show file tree
Hide file tree
Showing 118 changed files with 1,392 additions and 869 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@master

- uses: actions/setup-dotnet@v1
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

Expand All @@ -25,7 +25,7 @@ jobs:
run: dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=./artifacts/test-output.xml"

- name: Publish unit test results
uses: EnricoMi/publish-unit-test-result-action@v1.6
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
59 changes: 59 additions & 0 deletions bcf-toolkit.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
<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/Rider2024.1/resharper-host/temp/Rider/vAny/CoverageData/_bcf-toolkit.-1315391344/Snapshot/snapshot.utdcvr</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=00488d9b_002Ddfb9_002D47fc_002Da7da_002D60da862eab61/@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/=4dc5af78_002D6a8f_002D4f5b_002D8833_002Df0ff81e0c049/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" 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/=64259359_002Daf01_002D4100_002Db5a8_002D06c7d51d9f83/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="BuildMaximumInformationBcfFromStreamTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;NUnit3x::8113526D-8A68-4E3E-B4DB-CE235875DDD1::net8.0::tests.Builder.Bcf21.BcfBuilderTests.BuildMaximumInformationBcfFromStreamTest&lt;/TestId&gt;
&lt;/TestAncestor&gt;
&lt;/SessionState&gt;</s:String>


<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=7d7fd643_002Dccec_002D4fc7_002D8938_002D22e83b255cb0/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="BuildEmptyBcfFromStream" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;NUnit3x::8113526D-8A68-4E3E-B4DB-CE235875DDD1::net8.0::tests.Builder.Bcf21.BcfBuilderTests.BuildEmptyBcfFromStream&lt;/TestId&gt;
&lt;/TestAncestor&gt;
&lt;/SessionState&gt;</s:String>















<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=87607a24_002D24bc_002D46e1_002Da035_002D28c18ba9b643/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>
Expand All @@ -10,6 +45,30 @@



<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=b2d5c176_002Dc751_002D42d4_002Da842_002D3ad7ad02438d/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="WorkerTests" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;NUnit3x::8113526D-8A68-4E3E-B4DB-CE235875DDD1::net8.0::Tests.WorkerTests&lt;/TestId&gt;
&lt;/TestAncestor&gt;
&lt;/SessionState&gt;</s:String>






















Expand Down
2 changes: 1 addition & 1 deletion src/bcf-toolkit/Builder/Bcf21/BcfBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf21;

Expand Down
70 changes: 70 additions & 0 deletions src/bcf-toolkit/Builder/Bcf21/BcfBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;
using BcfToolkit.Utils;
using IBcfBuilderDelegate = BcfToolkit.Builder.Bcf21.Interfaces.IBcfBuilderDelegate;
Expand Down Expand Up @@ -37,6 +41,7 @@ public async Task<Bcf> BuildInMemoryFromStream(Stream source) {
_bcf.Markups =
await BcfExtensions.ParseMarkups<Markup, VisualizationInfo>(source);
_bcf.Project = await BcfExtensions.ParseProject<ProjectExtension>(source);
SetDocumentDataFromReferences(source);
return BuilderUtils.ValidateItem(_bcf);
}

Expand All @@ -49,4 +54,69 @@ public BcfBuilder SetProject(ProjectExtension? project) {
_bcf.Project = project;
return this;
}

/// <summary>
/// It sets the document file name and base64 data from the specified
/// document data dictionary.
/// </summary>
/// <param name="documentData">
/// Dictionary contains document guid as the key and a tuple of document
/// file name and file data as the value
/// </param>
/// <returns></returns>
public BcfBuilder SetDocumentData(
Dictionary<string, Tuple<string, FileData>>? documentData) {
if (documentData is null) return this;
var documentReferences =
_bcf.Markups.SelectMany(m => m.Topic.DocumentReference).ToList();
foreach (var data in documentData) {
var documentReference =
documentReferences.FirstOrDefault(r =>
r.ReferencedDocument.Equals(data.Key));
if (documentReference is null) continue;
//It is recommended to put files in a folder called Documents in the root
//folder of the zip archive.
documentReference.ReferencedDocument = $"../documents/{data.Value.Item1}";
documentReference.DocumentData = data.Value.Item2;
}
return this;
}

/// <summary>
/// It turns the additional file data that are referenced as internal
/// document in markups into the DocumentInfo.
/// </summary>
/// <param name="stream">The file stream of the BCFzip.</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
private void SetDocumentDataFromReferences(Stream stream) {
if (stream is null || !stream.CanRead)
throw new ArgumentException("Source stream is not readable.");

Log.Debug($"\nProcessing documents\n");

using var archive = new ZipArchive(stream, ZipArchiveMode.Read, true);

// These additional files can be referenced by other files via their
// relative paths. It is recommended to put them in a folder called
// Documents in the root folder of the zip archive.
var documentReferences = _bcf
.Markups
.SelectMany(m => m.Topic.DocumentReference)
.ToList();

documentReferences
.Where(d => !d.IsExternal)
.ToList()
.ForEach(d => {
var fileName = Path.GetFileName(d.ReferencedDocument);
var entry = archive.DocumentEntry(fileName);
if (entry is null) return;
Log.Debug(entry.FullName);
d.SetDocumentData(entry);
});

// Stream must be positioned back to 0 in order to use it again
stream.Position = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf21;

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

namespace BcfToolkit.Builder.Bcf21.Interfaces;
Expand Down Expand Up @@ -173,7 +174,7 @@ public interface IMarkupBuilder<
TBuilder AddViewPoint(
string viewpoint,
string snapshot,
string snapshotData,
FileData snapshotData,
int index,
string guid,
Action<TVisualizationInfoBuilder> builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;

namespace BcfToolkit.Builder.Bcf21.Interfaces;
Expand Down Expand Up @@ -28,7 +29,7 @@ public interface IViewPointBuilder<out TBuilder, out TVisualizationInfoBuilder>
/// </summary>
/// <param name="snapshotData">Base64 string of snapshot data.</param>
/// <returns>Returns the builder object.</returns>
TBuilder SetSnapshotData(string snapshotData);
TBuilder SetSnapshotData(FileData snapshotData);

/// <summary>
/// Returns the builder object set with the `Index`, which is the
Expand Down
3 changes: 2 additions & 1 deletion src/bcf-toolkit/Builder/Bcf21/MarkupBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf21;

Expand Down Expand Up @@ -136,7 +137,7 @@ public MarkupBuilder AddComment(Action<CommentBuilder> builder) {
}

public MarkupBuilder AddViewPoint(string viewpoint, string snapshot,
string snapshotData, int index, string guid,
FileData snapshotData, int index, string guid,
Action<VisualizationInfoBuilder> builder) {
var visInfo =
(VisualizationInfo)BuilderUtils
Expand Down
3 changes: 2 additions & 1 deletion src/bcf-toolkit/Builder/Bcf21/ViewPointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf21;

Expand Down Expand Up @@ -43,7 +44,7 @@ public ViewPointBuilder SetGuid(string guid) {
return this;
}

public ViewPointBuilder SetSnapshotData(string? snapshotData) {
public ViewPointBuilder SetSnapshotData(FileData? snapshotData) {
_viewPoint.SnapshotData = snapshotData;
return this;
}
Expand Down
1 change: 1 addition & 0 deletions src/bcf-toolkit/Builder/Bcf21/VisibilityBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BcfToolkit.Builder.Bcf21.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf21;

Expand Down
1 change: 1 addition & 0 deletions src/bcf-toolkit/Builder/Bcf21/VisualizationInfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf21;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf21;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf30;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf30;

Expand Down
7 changes: 5 additions & 2 deletions src/bcf-toolkit/Builder/Bcf30/DocumentBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System;
using BcfToolkit.Builder.Bcf30.Interfaces;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf30;

namespace BcfToolkit.Builder.Bcf30;

public class DocumentBuilder :
public partial class DocumentBuilder :
IDocumentBuilder<DocumentBuilder>,
IDefaultBuilder<DocumentBuilder> {
private readonly Document _document = new();
private readonly Document _document = new() {
DocumentData = new FileData()
};

public DocumentBuilder SetGuid(string guid) {
_document.Guid = guid;
Expand Down
10 changes: 10 additions & 0 deletions src/bcf-toolkit/Builder/Bcf30/DocumentBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using BcfToolkit.Model;

namespace BcfToolkit.Builder.Bcf30;

public partial class DocumentBuilder {
public DocumentBuilder SetDocumentData(FileData data) {
_document.DocumentData = data;
return this;
}
}
1 change: 1 addition & 0 deletions src/bcf-toolkit/Builder/Bcf30/DocumentInfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BcfToolkit.Builder.Bcf30.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf30;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf30;

Expand Down
2 changes: 1 addition & 1 deletion src/bcf-toolkit/Builder/Bcf30/DocumentReferenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DocumentReferenceBuilder SetGuid(string guid) {
return this;
}

public DocumentReferenceBuilder SetDescription(string description) {
public DocumentReferenceBuilder SetDescription(string? description) {
_documentReference.Description = description;
return this;
}
Expand Down
3 changes: 2 additions & 1 deletion src/bcf-toolkit/Builder/Bcf30/Interfaces/IMarkupBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf30;

namespace BcfToolkit.Builder.Bcf30.Interfaces;
Expand Down Expand Up @@ -173,7 +174,7 @@ public interface IMarkupBuilder<
TBuilder AddViewPoint(
string viewpoint,
string snapshot,
string snapshotData,
FileData snapshotData,
int index,
string guid,
Action<TVisualizationInfoBuilder> builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf30;

namespace BcfToolkit.Builder.Bcf30.Interfaces;
Expand Down Expand Up @@ -28,7 +29,7 @@ public interface IViewPointBuilder<out TBuilder, out TVisualizationInfoBuilder>
/// </summary>
/// <param name="snapshotData">Base64 string of snapshot data.</param>
/// <returns>Returns the builder object.</returns>
TBuilder SetSnapshotData(string snapshotData);
TBuilder SetSnapshotData(FileData snapshotData);

/// <summary>
/// Returns the builder object set with the `Index`, which is the
Expand Down
3 changes: 2 additions & 1 deletion src/bcf-toolkit/Builder/Bcf30/MarkupBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BcfToolkit.Builder.Interfaces;
using BcfToolkit.Model;
using BcfToolkit.Model.Bcf30;
using BcfToolkit.Model.Interfaces;

namespace BcfToolkit.Builder.Bcf30;

Expand Down Expand Up @@ -138,7 +139,7 @@ public MarkupBuilder AddComment(Action<CommentBuilder> builder) {
public MarkupBuilder AddViewPoint(
string viewpoint,
string snapshot,
string snapshotData,
FileData snapshotData,
int index,
string guid,
Action<VisualizationInfoBuilder> builder) {
Expand Down
Loading

0 comments on commit 6957093

Please sign in to comment.