Skip to content

Commit

Permalink
[SonarQube] improvements
Browse files Browse the repository at this point in the history
[Rename] Task methods to ...Async
  • Loading branch information
samatstariongroup committed Dec 6, 2024
1 parent d5a994d commit b27644e
Show file tree
Hide file tree
Showing 26 changed files with 76 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task SetUp()

await using var fileStream = new FileStream(reqifPath, FileMode.Open);
this.reqIFLoaderService = new ReqIFLoaderService(reqIfDeserializer);
await this.reqIFLoaderService.Load(fileStream, supportedFileExtensionKind, cts.Token);
await this.reqIFLoaderService.LoadAsync(fileStream, supportedFileExtensionKind, cts.Token);

this.reqIf = this.reqIFLoaderService.ReqIFData.Single();
}
Expand All @@ -74,7 +74,7 @@ public async Task Verify_that_QueryBase64Payloads_returns_expected_results()
{
var specObject = this.reqIf.CoreContent.SpecObjects.Single(x => x.Identifier == "_3.4.2.2.2_BrLeft_2_BrRight_._BrLeft_f_BrRight_1");

var base64Payloads = await specObject.QueryBase64Payloads(this.reqIFLoaderService);
var base64Payloads = await specObject.QueryBase64PayloadsAsync(this.reqIFLoaderService);

var base64Payload = base64Payloads.Single();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task SetUp()
await using var fileStream = new FileStream(reqifPath, FileMode.Open);
var reqIfDeserializer = new ReqIFDeserializer();
var reqIfLoaderService = new ReqIFLoaderService(reqIfDeserializer);
await reqIfLoaderService.Load(fileStream, supportedFileExtensionKind, cts.Token);
await reqIfLoaderService.LoadAsync(fileStream, supportedFileExtensionKind, cts.Token);

this.reqIf = reqIfLoaderService.ReqIFData.Single();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task Verify_that_ReqIF_data_is_loaded_and_set_to_ReqIFData()
var supportedFileExtensionKind = reqifPath.ConvertPathToSupportedFileExtensionKind();

await using var fileStream = new FileStream(reqifPath, FileMode.Open);
await this.reqIfLoaderService.Load(fileStream, supportedFileExtensionKind, cts.Token);
await this.reqIfLoaderService.LoadAsync(fileStream, supportedFileExtensionKind, cts.Token);

Assert.That(this.reqIfLoaderService.ReqIFData, Is.Not.Empty);

Expand All @@ -80,7 +80,7 @@ public async Task Verify_that_ReqIF_data_with_objects_is_loaded_and_set_to_ReqIF
var supportedFileExtensionKind = reqifPath.ConvertPathToSupportedFileExtensionKind();

await using var fileStream = new FileStream(reqifPath, FileMode.Open);
await this.reqIfLoaderService.Load(fileStream, supportedFileExtensionKind, cts.Token);
await this.reqIfLoaderService.LoadAsync(fileStream, supportedFileExtensionKind, cts.Token);

Console.WriteLine($"requirements-and-objects.reqifz desserialized in {sw.ElapsedMilliseconds} [ms]");

Expand All @@ -103,7 +103,7 @@ public async Task Verify_that_ExternalObject_image_can_be_Queried()
var supportedFileExtensionKind = reqifPath.ConvertPathToSupportedFileExtensionKind();

await using var fileStream = new FileStream(reqifPath, FileMode.Open);
await this.reqIfLoaderService.Load(fileStream, supportedFileExtensionKind, cts.Token);
await this.reqIfLoaderService.LoadAsync(fileStream, supportedFileExtensionKind, cts.Token);

Console.WriteLine($"requirements-and-objects.reqifz desserialized in {sw.ElapsedMilliseconds} [ms]");

Expand All @@ -116,7 +116,7 @@ public async Task Verify_that_ExternalObject_image_can_be_Queried()
{
sw.Restart();

var image = await this.reqIfLoaderService.QueryData(externalObject, cts.Token);
var image = await this.reqIfLoaderService.QueryDataAsync(externalObject, cts.Token);

Console.WriteLine($"image extracted in {sw.ElapsedMilliseconds} [ms]");

Expand All @@ -128,7 +128,7 @@ public async Task Verify_that_ExternalObject_image_can_be_Queried()
{
sw.Restart();

var image = await this.reqIfLoaderService.QueryData(externalObject, cts.Token);
var image = await this.reqIfLoaderService.QueryDataAsync(externalObject, cts.Token);

Console.WriteLine($"image extracted in {sw.ElapsedMilliseconds} [ms]");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ public static string QueryDefaultValueAsFormattedString(this AttributeDefinition
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ public static IEnumerable<ExternalObject> QueryExternalObjects(this ReqIFContent
return result;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static IEnumerable<ExternalObject> QueryExternalObjects(this SpecElementW
/// <returns>
/// an <see cref="IEnumerable{String}"/> that contains base64 encoded strings
/// </returns>
public static async Task<IEnumerable<Tuple<ExternalObject, string>>> QueryBase64Payloads(this SpecElementWithAttributes specElementWithAttributes, IReqIFLoaderService reqIfLoaderService)
public static async Task<IEnumerable<Tuple<ExternalObject, string>>> QueryBase64PayloadsAsync(this SpecElementWithAttributes specElementWithAttributes, IReqIFLoaderService reqIfLoaderService)
{
var result = new List<Tuple<ExternalObject, string>>();

Expand All @@ -75,7 +75,7 @@ public static async Task<IEnumerable<Tuple<ExternalObject, string>>> QueryBase64
{
foreach (var externalObject in specObjectValue.ExternalObjects)
{
var payload = await reqIfLoaderService.QueryData(externalObject, cts.Token);
var payload = await reqIfLoaderService.QueryDataAsync(externalObject, cts.Token);
result.Add(new Tuple<ExternalObject, string>(externalObject, payload));
}
}
Expand Down
8 changes: 4 additions & 4 deletions ReqIFSharp.Extensions/Services/IReqIFLoaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface IReqIFLoaderService
/// <summary>
/// Gets a copy of the <see cref="Stream"/> from which the ReqIF is loaded
/// </summary>
Task<Stream> GetSourceStream(CancellationToken token);
Task<Stream> GetSourceStreamAsync(CancellationToken token);

/// <summary>
/// Loads the <see cref="ReqIF"/> objects from the provided <see cref="Stream"/>
Expand All @@ -57,7 +57,7 @@ public interface IReqIFLoaderService
/// <returns>
/// an awaitable <see cref="Task"/>
/// </returns>
Task Load(Stream reqifStream, SupportedFileExtensionKind fileExtensionKind, CancellationToken token);
Task LoadAsync(Stream reqifStream, SupportedFileExtensionKind fileExtensionKind, CancellationToken token);

/// <summary>
/// Query the data object from associated to the <see cref="ExternalObject"/>
Expand All @@ -74,7 +74,7 @@ public interface IReqIFLoaderService
/// <remarks>
/// The <see cref="IReqIFLoaderService"/> caches the data for fast
/// </remarks>
Task<string> QueryData(ExternalObject externalObject, CancellationToken token);
Task<string> QueryDataAsync(ExternalObject externalObject, CancellationToken token);

/// <summary>
/// Resets the <see cref="IReqIFLoaderService"/> by clearing <see cref="ReqIFData"/> and
Expand All @@ -87,4 +87,4 @@ public interface IReqIFLoaderService
/// </summary>
event EventHandler<IEnumerable<ReqIF>> ReqIfChanged;
}
}
}
24 changes: 12 additions & 12 deletions ReqIFSharp.Extensions/Services/ReqIFLoaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ReqIFLoaderService(IReqIFDeSerializer reqIfDeSerializer, ILoggerFactory l
/// <summary>
/// Gets a copy of the <see cref="Stream"/> from which the ReqIF is loaded
/// </summary>
public async Task<Stream> GetSourceStream(CancellationToken token)
public async Task<Stream> GetSourceStreamAsync(CancellationToken token)
{
if (this.sourceStream.Position != 0)
{
Expand All @@ -105,7 +105,7 @@ public async Task<Stream> GetSourceStream(CancellationToken token)
/// Loads the <see cref="ReqIF"/> objects from the provided <see cref="Stream"/>
/// and stores the result in the <see cref="ReqIFData"/> property.
/// </summary>
/// <param name="reqIFStream">
/// <param name="reqIfStream">
/// a <see cref="Stream"/> that contains <see cref="ReqIF"/> content
/// </param>
/// <param name="token">
Expand All @@ -114,7 +114,7 @@ public async Task<Stream> GetSourceStream(CancellationToken token)
/// <returns>
/// an awaitable <see cref="Task"/>
/// </returns>
public async Task Load(Stream reqIFStream, SupportedFileExtensionKind fileExtensionKind, CancellationToken token)
public async Task LoadAsync(Stream reqIfStream, SupportedFileExtensionKind fileExtensionKind, CancellationToken token)
{
this.externalObjectDataCache.Clear();

Expand All @@ -124,17 +124,17 @@ public async Task Load(Stream reqIFStream, SupportedFileExtensionKind fileExtens

this.logger.LogDebug("copying the reqif stream to the deserialization stream for deserialization");

reqIFStream.Seek(0, SeekOrigin.Begin);
await reqIFStream.CopyToAsync(deserializationStream, 81920, token);
reqIfStream.Seek(0, SeekOrigin.Begin);
await reqIfStream.CopyToAsync(deserializationStream, 81920, token);
if (deserializationStream.Position != 0)
{
deserializationStream.Seek(0, SeekOrigin.Begin);
}

this.logger.LogDebug("copying the reqif stream to the source stream for safe keeping");

reqIFStream.Seek(0, SeekOrigin.Begin);
await reqIFStream.CopyToAsync(this.sourceStream, 81920, token);
reqIfStream.Seek(0, SeekOrigin.Begin);
await reqIfStream.CopyToAsync(this.sourceStream, 81920, token);
if (this.sourceStream.Position != 0)
{
this.sourceStream.Seek(0, SeekOrigin.Begin);
Expand All @@ -145,7 +145,7 @@ public async Task Load(Stream reqIFStream, SupportedFileExtensionKind fileExtens
var sw = Stopwatch.StartNew();
this.logger.LogDebug("starting deserialization");
result = await this.reqIfDeSerializer.DeserializeAsync(deserializationStream, fileExtensionKind, token);
this.logger.LogDebug("deserialization finished in {time} [ms]", sw.ElapsedMilliseconds);
this.logger.LogDebug("deserialization finished in {Time} [ms]", sw.ElapsedMilliseconds);

deserializationStream.Dispose();

Expand All @@ -169,7 +169,7 @@ public async Task Load(Stream reqIFStream, SupportedFileExtensionKind fileExtens
/// <remarks>
/// The <see cref="ReqIFLoaderService"/> caches the data for fast
/// </remarks>
public async Task<string> QueryData(ExternalObject externalObject, CancellationToken token)
public async Task<string> QueryDataAsync(ExternalObject externalObject, CancellationToken token)
{
if (externalObject == null)
{
Expand All @@ -178,12 +178,12 @@ public async Task<string> QueryData(ExternalObject externalObject, CancellationT

if (externalObjectDataCache.TryGetValue(externalObject, out var result))
{
this.logger.LogDebug("External Object {uri} retrieved from Cache", externalObject.Uri);
this.logger.LogDebug("External Object {Uri} retrieved from Cache", externalObject.Uri);

return result;
}

var stream = await this.GetSourceStream(token);
var stream = await this.GetSourceStreamAsync(token);

var targetStream = new MemoryStream();

Expand All @@ -193,7 +193,7 @@ public async Task<string> QueryData(ExternalObject externalObject, CancellationT

if (this.externalObjectDataCache.TryAdd(externalObject, result))
{
this.logger.LogDebug("External Object {uri} added to Cache", externalObject.Uri);
this.logger.LogDebug("External Object {Uri} added to Cache", externalObject.Uri);
}

return result;
Expand Down
1 change: 0 additions & 1 deletion ReqIFSharp.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ff23d20c-55d5-4ec1-9db5-57f1c437c183")]

4 changes: 2 additions & 2 deletions ReqIFSharp/AttributeDefinition/AttributeDefinitionBoolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal override void ReadXml(XmlReader reader)

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionBoolean:{reference} could not be found and has been set to null on AttributeDefinitionBoolean:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionBoolean:{Reference} could not be found and has been set to null on AttributeDefinitionBoolean:{Identifier}", reference, Identifier);
}

break;
Expand Down Expand Up @@ -184,7 +184,7 @@ internal override async Task ReadXmlAsync(XmlReader reader, CancellationToken to

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionBoolean:{reference} could not be found and has been set to null on AttributeDefinitionBoolean:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionBoolean:{Reference} could not be found and has been set to null on AttributeDefinitionBoolean:{Identifier}", reference, Identifier);
}

break;
Expand Down
4 changes: 2 additions & 2 deletions ReqIFSharp/AttributeDefinition/AttributeDefinitionDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ internal override void ReadXml(XmlReader reader)

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionDate:{reference} could not be found and has been set to null on AttributeDefinitionDate:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionDate:{Reference} could not be found and has been set to null on AttributeDefinitionDate:{Identifier}", reference, Identifier);
}

break;
Expand Down Expand Up @@ -192,7 +192,7 @@ internal override async Task ReadXmlAsync(XmlReader reader, CancellationToken to

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionDate:{reference} could not be found and has been set to null on AttributeDefinitionDate:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionDate:{Reference} could not be found and has been set to null on AttributeDefinitionDate:{Identifier}", reference, Identifier);
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ internal override void ReadXml(XmlReader reader)

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionEnumeration:{reference} could not be found and has been set to null on AttributeDefinitionEnumeration:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionEnumeration:{Reference} could not be found and has been set to null on AttributeDefinitionEnumeration:{Identifier}", reference, Identifier);
}

break;
Expand Down Expand Up @@ -204,7 +204,7 @@ internal override async Task ReadXmlAsync(XmlReader reader, CancellationToken to

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionEnumeration:{reference} could not be found and has been set to null on AttributeDefinitionEnumeration:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionEnumeration:{Reference} could not be found and has been set to null on AttributeDefinitionEnumeration:{Identifier}", reference, Identifier);
}

break;
Expand Down
4 changes: 2 additions & 2 deletions ReqIFSharp/AttributeDefinition/AttributeDefinitionInteger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal override void ReadXml(XmlReader reader)

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionInteger:{reference} could not be found and has been set to null on AttributeDefinitionInteger:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionInteger:{Reference} could not be found and has been set to null on AttributeDefinitionInteger:{Identifier}", reference, Identifier);
}

break;
Expand Down Expand Up @@ -186,7 +186,7 @@ internal override async Task ReadXmlAsync(XmlReader reader, CancellationToken to

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionInteger:{reference} could not be found and has been set to null on AttributeDefinitionInteger:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionInteger:{Reference} could not be found and has been set to null on AttributeDefinitionInteger:{Identifier}", reference, Identifier);
}

break;
Expand Down
4 changes: 2 additions & 2 deletions ReqIFSharp/AttributeDefinition/AttributeDefinitionReal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal override void ReadXml(XmlReader reader)

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionReal:{reference} could not be found and has been set to null on AttributeDefinitionReal:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionReal:{Reference} could not be found and has been set to null on AttributeDefinitionReal:{Identifier}", reference, Identifier);
}

break;
Expand Down Expand Up @@ -184,7 +184,7 @@ internal override async Task ReadXmlAsync(XmlReader reader, CancellationToken to

if (datatypeDefinition == null)
{
this.logger.LogTrace("The DatatypeDefinitionReal:{reference} could not be found and has been set to null on AttributeDefinitionReal:{Identifier}", reference, Identifier);
this.logger.LogTrace("The DatatypeDefinitionReal:{Reference} could not be found and has been set to null on AttributeDefinitionReal:{Identifier}", reference, Identifier);
}

break;
Expand Down
Loading

0 comments on commit b27644e

Please sign in to comment.