This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added project strcuture. * Updated sdk to use and the copyright notice. * Added serialization support for MongoDB.
- Loading branch information
Showing
27 changed files
with
816 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31919.166 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".items", ".items", "{75AC41E9-2B8B-4D76-A7DF-A18F4FB9D6D6}" | ||
ProjectSection(SolutionItems) = preProject | ||
.gitignore = .gitignore | ||
azure-pipelines.yml = azure-pipelines.yml | ||
GitVersion.yml = GitVersion.yml | ||
global.json = global.json | ||
icon.png = icon.png | ||
LICENSE = LICENSE | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DF28D730-99B3-4811-AAC7-725A73B3F668}" | ||
ProjectSection(SolutionItems) = preProject | ||
src\Directory.Build.props = src\Directory.Build.props | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F18D2D58-282C-4D93-8D9A-3A76CF98F018}" | ||
ProjectSection(SolutionItems) = preProject | ||
tests\Directory.Build.props = tests\Directory.Build.props | ||
EndProjectSection | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.Temporal", "src\Fluxera.Temporal\Fluxera.Temporal.csproj", "{00724D4C-75EF-4EA2-B5F9-0922B948021B}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fluxera.Temporal.MongoDB", "src\Fluxera.Temporal.MongoDB\Fluxera.Temporal.MongoDB.csproj", "{D1674A18-F0B2-43EF-9C6B-C541B40A7F73}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fluxera.Temporal.MongoDB.UnitTests", "tests\Fluxera.Temporal.MongoDB.UnitTests\Fluxera.Temporal.MongoDB.UnitTests.csproj", "{309830E5-238E-4BF4-A9BA-F942D30EE764}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{00724D4C-75EF-4EA2-B5F9-0922B948021B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{00724D4C-75EF-4EA2-B5F9-0922B948021B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{00724D4C-75EF-4EA2-B5F9-0922B948021B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{00724D4C-75EF-4EA2-B5F9-0922B948021B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D1674A18-F0B2-43EF-9C6B-C541B40A7F73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D1674A18-F0B2-43EF-9C6B-C541B40A7F73}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D1674A18-F0B2-43EF-9C6B-C541B40A7F73}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D1674A18-F0B2-43EF-9C6B-C541B40A7F73}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{309830E5-238E-4BF4-A9BA-F942D30EE764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{309830E5-238E-4BF4-A9BA-F942D30EE764}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{309830E5-238E-4BF4-A9BA-F942D30EE764}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{309830E5-238E-4BF4-A9BA-F942D30EE764}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{00724D4C-75EF-4EA2-B5F9-0922B948021B} = {DF28D730-99B3-4811-AAC7-725A73B3F668} | ||
{D1674A18-F0B2-43EF-9C6B-C541B40A7F73} = {DF28D730-99B3-4811-AAC7-725A73B3F668} | ||
{309830E5-238E-4BF4-A9BA-F942D30EE764} = {F18D2D58-282C-4D93-8D9A-3A76CF98F018} | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {D97BF2AF-6E68-4E88-BF70-773A86E26013} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mode: Mainline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# CI pipeline for a NuGet package solution. | ||
|
||
trigger: | ||
branches: | ||
include: [ '*' ] | ||
exclude: [ 'refs/tags/*' ] | ||
|
||
variables: | ||
BuildConfiguration: Release | ||
DotNetCoreVersion: 6.0.201 | ||
|
||
stages: | ||
- stage: BuildAndTest | ||
jobs: | ||
- job: BuildAndTest | ||
pool: | ||
name: Default | ||
steps: | ||
- checkout: self | ||
persistCredentials: 'true' | ||
clean: true | ||
# Install the desired .NET SDK. | ||
- task: UseDotNet@2 | ||
displayName: 'Acquire .NET SDK' | ||
inputs: | ||
packageType: 'sdk' | ||
version: $(DotNetCoreVersion) | ||
includePreviewVersions: false | ||
# Build all projects. | ||
- task: DotNetCoreCLI@2 | ||
displayName: 'Build Projects' | ||
inputs: | ||
projects: '**/*.csproj' | ||
arguments: '--configuration $(BuildConfiguration)' | ||
# Run all available tests. | ||
- task: DotNetCoreCLI@2 | ||
displayName: 'Execute Tests' | ||
inputs: | ||
command: test | ||
projects: '**/*Tests/*.csproj' | ||
arguments: '--configuration $(BuildConfiguration)' | ||
nobuild: true | ||
# Create the NuGet packages. | ||
- task: DotNetCoreCLI@2 | ||
displayName: 'Pack Packages' | ||
inputs: | ||
command: 'pack' | ||
packagesToPack: 'src/**/*.csproj' | ||
nobuild: true | ||
verbosityPack: Minimal | ||
includesymbols: false | ||
# Copy created NuGet packages to the builds artifacts directory. | ||
- task: PublishBuildArtifacts@1 | ||
displayName: 'Publish Package Artifacts' | ||
inputs: | ||
PathtoPublish: '$(Build.ArtifactStagingDirectory)' | ||
ArtifactName: 'drop' | ||
publishLocation: 'Container' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "6.0.201" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<LangVersion>latest</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Company>Fluxera Software Development GmbH</Company> | ||
<Product>Fluxera Software Foundation</Product> | ||
<Copyright>Copyright © 2014-2022 Fluxera Software Development GmbH. All rights reserved.</Copyright> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Authors>Matthias Gernand</Authors> | ||
<RepositoryUrl>https://github.com/fluxera/Fluxera.Guard</RepositoryUrl> | ||
<PackageProjectUrl>https://github.com/fluxera/Fluxera.Guard</PackageProjectUrl> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<IncludeSymbols>false</IncludeSymbols> | ||
<NeutralLanguage>en</NeutralLanguage> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
</PropertyGroup> | ||
|
||
<Target Name="Update Version" BeforeTargets="Build" Condition="'$(TF_BUILD)' == 'true'"> | ||
<Message Text="Version = $(GITVERSION_FullSemVer)" Importance="High" /> | ||
<Message Text="##vso[build.updatebuildnumber]$(GITVERSION_FullSemVer)" Importance="High" /> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Fluxera.Temporal.MongoDB | ||
{ | ||
using global::MongoDB.Bson.Serialization.Conventions; | ||
using JetBrains.Annotations; | ||
|
||
[PublicAPI] | ||
public static class ConventionPackExtensions | ||
{ | ||
public static ConventionPack UseTemporal(this ConventionPack pack) | ||
{ | ||
pack.Add(new DateTimeConvention()); | ||
pack.Add(new DateTimeOffsetConvention()); | ||
pack.Add(new DateOnlyConvention()); | ||
pack.Add(new TimeOnlyConvention()); | ||
pack.Add(new TimeSpanConvention()); | ||
|
||
return pack; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace Fluxera.Temporal.MongoDB | ||
{ | ||
using System; | ||
using Fluxera.Utilities.Extensions; | ||
using global::MongoDB.Bson.Serialization; | ||
using global::MongoDB.Bson.Serialization.Conventions; | ||
using global::MongoDB.Bson.Serialization.Serializers; | ||
|
||
internal sealed class DateOnlyConvention : ConventionBase, IMemberMapConvention | ||
{ | ||
/// <inheritdoc /> | ||
public void Apply(BsonMemberMap memberMap) | ||
{ | ||
Type originalMemberType = memberMap.MemberType; | ||
Type memberType = originalMemberType.UnwrapNullableType(); | ||
|
||
if(memberType == typeof(DateOnly)) | ||
{ | ||
DateOnlySerializer dateOnlySerializer = new DateOnlySerializer(); | ||
|
||
IBsonSerializer serializer = originalMemberType.IsNullable() | ||
? new NullableSerializer<DateOnly>(dateOnlySerializer) | ||
: dateOnlySerializer; | ||
|
||
memberMap.SetSerializer(serializer); | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Fluxera.Temporal.MongoDB/DateOnlyDateTimeOffsetSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Fluxera.Temporal.MongoDB | ||
{ | ||
using System; | ||
using global::MongoDB.Bson.Serialization; | ||
using global::MongoDB.Bson.Serialization.Serializers; | ||
using JetBrains.Annotations; | ||
|
||
[PublicAPI] | ||
public class DateOnlyDateTimeOffsetSerializer : DateTimeOffsetSerializer | ||
{ | ||
private readonly DateTimeSerializer dateTimeSerializer; | ||
|
||
public DateOnlyDateTimeOffsetSerializer(DateTimeSerializer dateTimeSerializer) | ||
{ | ||
this.dateTimeSerializer = dateTimeSerializer; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, DateTimeOffset value) | ||
{ | ||
this.dateTimeSerializer.Serialize(context, args, value.Date); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override DateTimeOffset Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) | ||
{ | ||
DateTimeOffset dateTimeOffset = this.dateTimeSerializer.Deserialize(context, args); | ||
return dateTimeOffset.Date; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Fluxera.Temporal.MongoDB/DateOnlyDateTimeSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Fluxera.Temporal.MongoDB | ||
{ | ||
using System; | ||
using global::MongoDB.Bson.Serialization; | ||
using global::MongoDB.Bson.Serialization.Serializers; | ||
using JetBrains.Annotations; | ||
|
||
[PublicAPI] | ||
public class DateOnlyDateTimeSerializer : DateTimeSerializer | ||
{ | ||
private readonly DateTimeSerializer dateTimeSerializer; | ||
|
||
public DateOnlyDateTimeSerializer(DateTimeSerializer dateTimeSerializer) | ||
{ | ||
this.dateTimeSerializer = dateTimeSerializer; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, DateTime value) | ||
{ | ||
this.dateTimeSerializer.Serialize(context, args, value.Date); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override DateTime Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) | ||
{ | ||
DateTime dateTime = this.dateTimeSerializer.Deserialize(context, args); | ||
return dateTime.Date; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Fluxera.Temporal.MongoDB | ||
{ | ||
using System; | ||
using global::MongoDB.Bson.Serialization; | ||
using global::MongoDB.Bson.Serialization.Serializers; | ||
using JetBrains.Annotations; | ||
|
||
[PublicAPI] | ||
public class DateOnlySerializer : StructSerializerBase<DateOnly> | ||
{ | ||
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, DateOnly value) | ||
{ | ||
context.Writer.WriteString(value.ToString("yyyy-MM-dd")); | ||
} | ||
|
||
public override DateOnly Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) | ||
{ | ||
return DateOnly.ParseExact(context.Reader.ReadString(), "yyyy-MM-dd", null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace Fluxera.Temporal.MongoDB | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using Fluxera.ComponentModel.Annotations; | ||
using Fluxera.Utilities.Extensions; | ||
using global::MongoDB.Bson; | ||
using global::MongoDB.Bson.Serialization; | ||
using global::MongoDB.Bson.Serialization.Conventions; | ||
using global::MongoDB.Bson.Serialization.Serializers; | ||
|
||
internal sealed class DateTimeConvention : ConventionBase, IMemberMapConvention | ||
{ | ||
/// <inheritdoc /> | ||
public void Apply(BsonMemberMap memberMap) | ||
{ | ||
Type originalMemberType = memberMap.MemberType; | ||
Type memberType = Nullable.GetUnderlyingType(originalMemberType) ?? originalMemberType; | ||
MemberInfo member = memberMap.MemberInfo; | ||
|
||
if(memberType == typeof(DateTime)) | ||
{ | ||
bool dateOnly = member.IsDefined(typeof(DateOnlyAttribute)); | ||
|
||
BsonType representation = dateOnly ? BsonType.String : BsonType.Document; | ||
|
||
DateTimeSerializer dateTimeSerializer = DateTimeSerializer.UtcInstance | ||
.WithRepresentation(representation) | ||
.WithDateOnly(dateOnly); | ||
|
||
if(dateOnly) | ||
{ | ||
dateTimeSerializer = new DateOnlyDateTimeSerializer(dateTimeSerializer); | ||
} | ||
|
||
IBsonSerializer serializer = originalMemberType.IsNullable() | ||
? new NullableSerializer<DateTime>(dateTimeSerializer) | ||
: dateTimeSerializer; | ||
|
||
memberMap.SetSerializer(serializer); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.