Skip to content

Commit 1c91d54

Browse files
[WIP] add serializer class and improce ISerializer interface
1 parent 813e221 commit 1c91d54

4 files changed

Lines changed: 160 additions & 40 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,4 @@ MigrationBackup/
355355
# WinMerge bak files
356356
*.bak
357357
/switcher.json
358+
/.claude/settings.local.json
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="SerializerTestFixture.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
namespace SysML2.NET.Serializer.Xmi.Tests
22+
{
23+
using System;
24+
using System.IO;
25+
using System.Threading;
26+
using System.Threading.Tasks;
27+
28+
using Microsoft.Extensions.DependencyInjection;
29+
using Microsoft.Extensions.Logging;
30+
31+
using SysML2.NET.Serializer.Xmi.Extensions;
32+
using SysML2.NET.Serializer.Xmi.Readers;
33+
34+
[TestFixture]
35+
public class SerializerTestFixture
36+
{
37+
private Serializer serializer;
38+
private XmiDataCache xmiDataCache;
39+
40+
[SetUp]
41+
public void Setup()
42+
{
43+
var serviceProvider = new ServiceCollection()
44+
.AddLogging(x => x.AddConsole())
45+
.BuildServiceProvider();
46+
47+
this.xmiDataCache = new XmiDataCache(new PocoReferenceResolveExtensionsFacade(),serviceProvider.GetRequiredService<ILogger<XmiDataCache>>());
48+
49+
this.serializer = new Serializer(serviceProvider.GetRequiredService<ILoggerFactory>());
50+
}
51+
52+
53+
}
54+
}

SysML2.NET.Serializer.Xmi/ISerializer.cs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,33 @@ namespace SysML2.NET.Serializer.Xmi
2626
using System.Threading.Tasks;
2727

2828
using SysML2.NET.Common;
29+
using SysML2.NET.Core.POCO.Root.Namespaces;
2930

3031
/// <summary>
31-
/// The purpose of the <see cref="ISerializer"/> is to write an <see cref="IData"/> and <see cref="IEnumerable{IData}"/>
32+
/// The purpose of the <see cref="ISerializer"/> is to write an <see cref="INamespace"/>
3233
/// as XMI to a <see cref="Stream"/>
3334
/// </summary>
3435
public interface ISerializer
3536
{
3637
/// <summary>
37-
/// Serialize an <see cref="IEnumerable{IData}"/> as XMI to a target <see cref="Stream"/>
38+
/// Serialize an <see cref="INamespace"/> as XMI to a target <see cref="Stream"/>
3839
/// </summary>
39-
/// <param name="dataItems">
40-
/// The <see cref="IEnumerable{IData}"/> that shall be serialized
40+
/// <param name="namespace">
41+
/// The <see cref="INamespace"/> that shall be serialized
4142
/// </param>
4243
/// <param name="includeDerivedProperties">
4344
/// Asserts that derived properties should also be part of the serialization
4445
/// </param>
4546
/// <param name="stream">
4647
/// The target <see cref="Stream"/>
4748
/// </param>
48-
void Serialize(IEnumerable<IData> dataItems, bool includeDerivedProperties, Stream stream);
49+
void Serialize(INamespace @namespace, bool includeDerivedProperties, Stream stream);
4950

5051
/// <summary>
51-
/// Serialize an <see cref="IData"/> as XMI to a target <see cref="Stream"/>
52+
/// Asynchronously serialize an <see cref="INamespace"/> as XMI to a target <see cref="Stream"/>
5253
/// </summary>
53-
/// <param name="dataItem">
54-
/// The <see cref="IData"/> that shall be serialized
55-
/// </param>
56-
/// <param name="includeDerivedProperties">
57-
/// Asserts that derived properties should also be part of the serialization
58-
/// </param>
59-
/// <param name="stream">
60-
/// The target <see cref="Stream"/>
61-
/// </param>
62-
void Serialize(IData dataItem, bool includeDerivedProperties, Stream stream);
63-
64-
/// <summary>
65-
/// Asynchronously serialize an <see cref="IEnumerable{IData}"/> as XMI to a target <see cref="Stream"/>
66-
/// </summary>
67-
/// <param name="dataItems">
68-
/// The <see cref="IEnumerable{IData}"/> that shall be serialized
54+
/// <param name="namespace">
55+
/// The <see cref="INamespace"/> that shall be serialized
6956
/// </param>
7057
/// <param name="stream">
7158
/// The target <see cref="Stream"/>
@@ -76,23 +63,6 @@ public interface ISerializer
7663
/// <param name="cancellationToken">
7764
/// The <see cref="CancellationToken"/> used to cancel the operation
7865
/// </param>
79-
Task SerializeAsync(IEnumerable<IData> dataItems, bool includeDerivedProperties, Stream stream, CancellationToken cancellationToken);
80-
81-
/// <summary>
82-
/// Asynchronously serialize an <see cref="IData"/> as XMI to a target <see cref="Stream"/>
83-
/// </summary>
84-
/// <param name="dataItem">
85-
/// The <see cref="IData"/> that shall be serialized
86-
/// </param>
87-
/// <param name="includeDerivedProperties">
88-
/// Asserts that derived properties should also be part of the serialization
89-
/// </param>
90-
/// <param name="stream">
91-
/// The target <see cref="Stream"/>
92-
/// </param>
93-
/// <param name="cancellationToken">
94-
/// The <see cref="CancellationToken"/> used to cancel the operation
95-
/// </param>
96-
Task SerializeAsync(IData dataItem, bool includeDerivedProperties, Stream stream, CancellationToken cancellationToken);
66+
Task SerializeAsync(INamespace @namespace, bool includeDerivedProperties, Stream stream, CancellationToken cancellationToken);
9767
}
9868
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="Serializer.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
namespace SysML2.NET.Serializer.Xmi
22+
{
23+
using System.Collections.Generic;
24+
using System.IO;
25+
using System.Threading;
26+
using System.Threading.Tasks;
27+
28+
using Microsoft.Extensions.Logging;
29+
using Microsoft.Extensions.Logging.Abstractions;
30+
31+
using SysML2.NET.Common;
32+
using SysML2.NET.Core.POCO.Root.Namespaces;
33+
34+
/// <summary>
35+
/// The purpose of the <see cref="ISerializer"/> is to write an <see cref="INamespace"/>
36+
/// as XMI to a <see cref="Stream"/>
37+
/// </summary>
38+
public class Serializer : ISerializer
39+
{
40+
/// <summary>
41+
/// The injected <see cref="ILogger{Serializer}" /> to produce logs statement
42+
/// </summary>
43+
private readonly ILogger<Serializer> logger;
44+
45+
/// <summary>
46+
/// The injected <see cref="ILoggerFactory " /> used to set up logging
47+
/// </summary>
48+
private readonly ILoggerFactory loggerFactory;
49+
50+
/// <summary>Initializes a new instance of the <see cref="Serializer"></see> class.</summary>
51+
/// <param name="loggerFactory">The injected <see cref="ILoggerFactory " /> used to set up logging</param>
52+
public Serializer(ILoggerFactory loggerFactory)
53+
{
54+
this.loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
55+
this.logger = this.loggerFactory.CreateLogger<Serializer>();
56+
}
57+
58+
/// <summary>
59+
/// Serialize an <see cref="INamespace"/> as XMI to a target <see cref="Stream"/>
60+
/// </summary>
61+
/// <param name="namespace">
62+
/// The <see cref="INamespace"/> that shall be serialized
63+
/// </param>
64+
/// <param name="includeDerivedProperties">
65+
/// Asserts that derived properties should also be part of the serialization
66+
/// </param>
67+
/// <param name="stream">
68+
/// The target <see cref="Stream"/>
69+
/// </param>
70+
public void Serialize(INamespace @namespace, bool includeDerivedProperties, Stream stream)
71+
{
72+
throw new System.NotImplementedException();
73+
}
74+
75+
/// <summary>
76+
/// Asynchronously serialize an <see cref="INamespace"/> as XMI to a target <see cref="Stream"/>
77+
/// </summary>
78+
/// <param name="namespace">
79+
/// The <see cref="INamespace"/> that shall be serialized
80+
/// </param>
81+
/// <param name="stream">
82+
/// The target <see cref="Stream"/>
83+
/// </param>
84+
/// <param name="includeDerivedProperties">
85+
/// Asserts that derived properties should also be part of the serialization
86+
/// </param>
87+
/// <param name="cancellationToken">
88+
/// The <see cref="CancellationToken"/> used to cancel the operation
89+
/// </param>
90+
public Task SerializeAsync(INamespace @namespace, bool includeDerivedProperties, Stream stream, CancellationToken cancellationToken)
91+
{
92+
throw new System.NotImplementedException();
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)