Skip to content

Commit

Permalink
updated libraries, changed Base to Core
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Lanning authored and Mark Lanning committed Dec 12, 2024
1 parent f02865d commit b23eeab
Show file tree
Hide file tree
Showing 24 changed files with 180 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish_nugets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
id-token: write

env:
SOLUTION_PATH: './ThingsLibrary.Frameworks.Deploy.sln'
SOLUTION_PATH: './ThingsLibrary.Frameworks.sln'

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
timeout-minutes: 15

env:
SOLUTION_PATH: './ThingsLibrary.Frameworks.Deploy.sln'
SOLUTION_PATH: './ThingsLibrary.Frameworks.sln'

steps:
- name: Checkout
Expand Down
19 changes: 12 additions & 7 deletions Base/src/ThingsLibrary.Base/Attributes/ValidationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override ValidationResult IsValid(object? instance, ValidationContext
}
else
{
return new ValidationResult($"The {validationContext.MemberName} field is required.", new List<string> { validationContext.MemberName });
return new ValidationResult($"The {validationContext.MemberName} field is required.", [validationContext.MemberName]);
}
}
else
Expand Down Expand Up @@ -66,7 +66,7 @@ protected override ValidationResult IsValid(object? instance, ValidationContext

if (instance == null)
{
var propertyInfo = validationContext.ObjectType.GetProperty(validationContext.MemberName);
var propertyInfo = validationContext.ObjectType.GetProperty(validationContext.MemberName ?? string.Empty);
if (propertyInfo != null)
{
var isNullable = propertyInfo.CustomAttributes.Any(x => x.AttributeType.Name == "NullableAttribute");
Expand All @@ -76,7 +76,7 @@ protected override ValidationResult IsValid(object? instance, ValidationContext
}
else
{
return new ValidationResult($"The {validationContext.MemberName} field is required.", new List<string> { validationContext.MemberName });
return new ValidationResult($"The {validationContext.MemberName} field is required.", [validationContext.MemberName ?? "(NULL)"]);
}
}
else
Expand All @@ -90,14 +90,17 @@ protected override ValidationResult IsValid(object? instance, ValidationContext
{
foreach (var keyPair in dictionary)
{
// nothing to validate?
if(keyPair.Value is null) { continue; }

var subResults = new List<ValidationResult>();
var context = new ValidationContext(keyPair.Value, null, null);

Validator.TryValidateObject(keyPair.Value, context, subResults, true);

if (subResults.Any())
{
var compositeResult = new CompositeValidationResult($"Validation for {validationContext.DisplayName}[{keyPair.Key}] failed!", new List<string> { $"{validationContext.MemberName}[{keyPair.Key}]" });
var compositeResult = new CompositeValidationResult($"Validation for {validationContext.DisplayName}[{keyPair.Key}] failed!", [$"{validationContext.MemberName}[{keyPair.Key}]"]);
subResults.ForEach(compositeResult.AddResult);

results.Add(compositeResult);
Expand All @@ -109,14 +112,16 @@ protected override ValidationResult IsValid(object? instance, ValidationContext
int i = 0;
foreach (var item in list)
{
if(item is null) { continue; }

var subResults = new List<ValidationResult>();
var context = new ValidationContext(item, null, null);

Validator.TryValidateObject(item, context, subResults, true);

if (subResults.Any())
{
var compositeResult = new CompositeValidationResult($"Validation for {validationContext.DisplayName}[{i}] failed!", new List<string> { $"{validationContext.MemberName}[{i}]" });
var compositeResult = new CompositeValidationResult($"Validation for {validationContext.DisplayName}[{i}] failed!", [$"{validationContext.MemberName}[{i}]"]);
subResults.ForEach(compositeResult.AddResult);

results.Add(compositeResult);
Expand All @@ -137,7 +142,7 @@ protected override ValidationResult IsValid(object? instance, ValidationContext

if (subResults.Any())
{
var compositeResult = new CompositeValidationResult($"Validation for {validationContext.DisplayName} failed!", new List<string> { validationContext.MemberName });
var compositeResult = new CompositeValidationResult($"Validation for {validationContext.DisplayName} failed!", [$"{validationContext.MemberName}"]);
subResults.ForEach(compositeResult.AddResult);

results.Add(compositeResult);
Expand All @@ -146,7 +151,7 @@ protected override ValidationResult IsValid(object? instance, ValidationContext

if (results.Any())
{
var compositeResults = new CompositeValidationResult($"Validation for {validationContext.DisplayName} failed!", new List<string> { validationContext.MemberName });
var compositeResults = new CompositeValidationResult($"Validation for {validationContext.DisplayName} failed!", [$"{validationContext.MemberName}"]);
results.ForEach(compositeResults.AddResult);

return compositeResults;
Expand Down
2 changes: 1 addition & 1 deletion Base/src/ThingsLibrary.Base/DataType/Events/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// </copyright>
// ================================================================================

using ThingsLibrary.Schema.Library.Extensions;
using ThingsLibrary.DataType.Extensions;

namespace ThingsLibrary.DataType.Events
{
Expand Down
88 changes: 88 additions & 0 deletions Base/src/ThingsLibrary.Base/DataType/Extensions/Checksum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// ================================================================================
// <copyright file="Checksum.cs" company="Starlight Software Co">
// Copyright (c) Starlight Software Co. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
// </copyright>
// ================================================================================

namespace ThingsLibrary.DataType.Extensions
{
public static class ChecksumExtensions
{
/// <summary>
/// Append the checksum
/// </summary>
/// <param name="sentence"></param>
/// <remarks>Checksum based on the NMEA0183 checksum which is just a simple byte-by-byte XOR of all the bytes between $ and * signs exclusively.</remarks>
public static void AppendChecksum(this StringBuilder sentence)
{
// not the beginning of a sentence
if (sentence.Length == 0) { return; }
if (sentence[0] != '$') { return; }

//Start with first Item
int checksum = Convert.ToByte(sentence[1]);

// Loop through all chars to get a checksum
int i;
for (i = 2; i < sentence.Length; i++)
{
if (sentence[i] == '*') { break; }

// No. XOR the checksum with this character's value
checksum ^= Convert.ToByte(sentence[i]);
}

// no astrisk to mark the CRC check
if (i == sentence.Length)
{
sentence.Append("*");
}

// Return the checksum formatted as a two-character hexadecimal
sentence.Append(checksum.ToString("X2"));
}

/// <summary>
/// Calculate a checksum value based on the NMEA0183 style calculation
/// </summary>
/// <param name="sentence">Sentence</param>
/// <remarks>Checksum based on the NMEA0183 checksum which is just a simple byte-by-byte XOR of all the bytes between $ and * signs exclusively.</remarks>
/// <returns>Two character hexadecimal checksum value</returns>
public static string ToChecksum(this string sentence)
{
if (string.IsNullOrEmpty(sentence)) { return string.Empty; }

// not the beginning of a sentence
if (sentence[0] != '$') { return string.Empty; }

//Start with first Item
int checksum = Convert.ToByte(sentence[1]);

// Loop through all chars to get a checksum
for (int i = 2; i < sentence.Length; i++)
{
if (sentence[i] == '*') { break; }

// No. XOR the checksum with this character's value
checksum ^= Convert.ToByte(sentence[i]);
}

// Return the checksum formatted as a two-character hexadecimal
return checksum.ToString("X2");
}

/// <summary>
/// Validate that the checksum on the sentence is correct
/// </summary>
/// <param name="sentence"></param>
/// <returns></returns>
public static bool ValidateChecksum(this string sentence)
{
var checksum = sentence.ToChecksum();
if (string.IsNullOrEmpty(checksum)) { return false; }

return sentence.EndsWith(checksum);
}
}
}
3 changes: 1 addition & 2 deletions Base/src/ThingsLibrary.Base/DataType/Guard/Guard.Null.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public static ref readonly ArgumentInfo<TType> Null<TType>(in this ArgumentInfo<
/// <param name="exceptionMessage">The exception message.</param>
/// <typeparam name="TType">The type.</typeparam>
/// <returns>An instance of the <see cref="ArgumentInfo{TType}" /> struct.</returns>
/// <exception cref="ArgumentException">Thrown when the condition is not met.</exception>
[MemberNotNull(nameof(argument.Value))]
/// <exception cref="ArgumentException">Thrown when the condition is not met.</exception>
public static ref readonly ArgumentInfo<TType> NotNull<TType>(in this ArgumentInfo<TType> argument, string? exceptionMessage = null) where TType : class
{
if (argument.HasValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Write(Utf8JsonWriter writer, Dictionary<string, object> val
JsonSerializer.Serialize(writer, (IDictionary<string, object>)value, options);
}

private object ExtractValue(ref Utf8JsonReader reader, JsonSerializerOptions options)
private object? ExtractValue(ref Utf8JsonReader reader, JsonSerializerOptions options)
{
switch (reader.TokenType)
{
Expand Down Expand Up @@ -83,7 +83,10 @@ private object ExtractValue(ref Utf8JsonReader reader, JsonSerializerOptions opt
var list = new List<object>();
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
list.Add(ExtractValue(ref reader, options));
var value = ExtractValue(ref reader, options);
if(value == null) { continue; }

list.Add(value);
}
return list;
}
Expand Down
2 changes: 1 addition & 1 deletion Base/src/ThingsLibrary.Base/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class Reflection
public static T GetDefault<T>()
{
var defaultValue = GetDefault(typeof(T));
if(defaultValue == null) { return default(T); }
if(defaultValue == null) { return default; }

Check warning on line 26 in Base/src/ThingsLibrary.Base/Reflection.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 26 in Base/src/ThingsLibrary.Base/Reflection.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

return (T)defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
</PropertyGroup>

<PropertyGroup>
<PackageId>ThingsLibrary.Base</PackageId>
<PackageDescription>Things Library base framework libraries and wrappers.</PackageDescription>
<PackageId>ThingsLibrary.Core</PackageId>
<PackageDescription>Things Library core framework libraries and wrappers.</PackageDescription>

<ProductName>ThingsLibrary.Base</ProductName>
<Title>Things Library Base Framework Library</Title>
<Title>Things Library Core Framework Library</Title>
<Description>This is the common base foundational library.</Description>

<Authors>Mark Lanning</Authors>
<Company>Starlight Software Co.</Company>
<RepositoryUrl></RepositoryUrl>
<Company>Starlight Software Co.</Company>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ThingsLibrary.Schema.Library" Version="0.2.8" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Base/src/ThingsLibrary.Testing/ThingsLibrary.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageDescription>Things Library testing framework libraries and wrappers.</PackageDescription>

<ProductName>ThingsLibrary.Testing</ProductName>
<Title>Testing Library</Title>
<Title>Things Library Testing Framework Library</Title>
<Description>This is the testing library that adds test container capabilities</Description>

<Authors>Mark Lanning</Authors>
Expand All @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ThingsLibrary.Base\ThingsLibrary.Base.csproj" />
<ProjectReference Include="..\ThingsLibrary.Base\ThingsLibrary.csproj" />
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions Base/src/ThingsLibrary.Testing/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
// </copyright>
// ================================================================================

global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
global using System.Threading.Tasks;
global using System.Text.RegularExpressions;
global using System.Reflection;
global using Microsoft.Extensions.Configuration;

global using System.Diagnostics.CodeAnalysis;
global using Microsoft.VisualStudio.TestTools.UnitTesting;

// ================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\ThingsLibrary.Base\ThingsLibrary.Base.csproj" />
<ProjectReference Include="..\..\src\ThingsLibrary.Base\ThingsLibrary.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Base\src\ThingsLibrary.Base\ThingsLibrary.Base.csproj" />
<ProjectReference Include="..\..\..\Base\src\ThingsLibrary.Base\ThingsLibrary.csproj" />
<ProjectReference Include="..\..\..\Services\src\ThingsLibrary.Services\ThingsLibrary.Services.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Base\src\ThingsLibrary.Testing\ThingsLibrary.Testing.csproj" />
<ProjectReference Include="..\..\src\ThingsLibrary.Database\ThingsLibrary.Database.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Base\src\ThingsLibrary.Testing\ThingsLibrary.Testing.csproj" />
<ProjectReference Include="..\..\src\ThingsLibrary.Database\ThingsLibrary.Database.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.2.1" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.2.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Base\src\ThingsLibrary.Base\ThingsLibrary.Base.csproj" />
<ProjectReference Include="..\..\..\Base\src\ThingsLibrary.Base\ThingsLibrary.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit b23eeab

Please sign in to comment.