Skip to content

Commit

Permalink
Merge pull request #5 from fiskaltrust/user/tsc/factories
Browse files Browse the repository at this point in the history
Add helper packages to simplify IPOS creation via different communication channels
  • Loading branch information
TSchmiedlechner committed May 6, 2020
2 parents 4c53d4f + f231bce commit adf8f7d
Show file tree
Hide file tree
Showing 38 changed files with 1,401 additions and 92 deletions.
6 changes: 0 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.0.50</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
39 changes: 16 additions & 23 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ resources:

trigger:
batch: true
branches:
include:
- master
- refs/tags/*

pr:
- master
Expand All @@ -14,7 +18,7 @@ variables:
- name: BuildPlatform
value: any cpu
- name: Solution
value: 'fiskaltrust.if.sln'
value: 'fiskaltrust.Middleware.Interface.sln'

jobs:
- job: Build
Expand All @@ -24,38 +28,27 @@ jobs:
- task: VisualStudioTestPlatformInstaller@1
displayName: VsTest Platform Installer

- powershell: |
dotnet tool install -g nbgv
workingDirectory: '/'
displayName: Install nbgv CLI
- powershell: |
if (-not $Env:BUILD_SOURCEBRANCH.StartsWith("refs/tags/v") -and
-not $Env:BUILD_SOURCEBRANCH.StartsWith("refs/heads/master") -and
-not $Env:BUILD_SOURCEBRANCH.StartsWith("refs/heads/release")) {
git config --global user.email "fiskaltrust@fiskaltrust.cloud"
git config --global user.name "fiskaltrust"
$date = "$(Get-Date -UFormat "%y")$("{0:D3}" -f (Get-Date).DayofYear)"
$versionPostfix = "-$date-$(Build.BuildId)"
$versionContent = Get-Content 'version.json' -Raw | ConvertFrom-Json
$versionContent.version = "$($versionContent.version)$versionPostfix"
$versionContent | ConvertTo-Json -Depth 32 | Set-Content 'version.json'
git add .
git commit -m "Version bump" -q
}
nbgv cloud
displayName: Set NBGV version
- task: yavt@1
inputs:
mode: 'Multi'
semverVersion: 'v1'

- powershell: |
$nugetFeed = if ($Env:BUILD_SOURCEBRANCH.StartsWith("refs/heads/release/") -or $Env:BUILD_SOURCEBRANCH.StartsWith("refs/tags/v")) { "release" } else { "dev" }
Write-Host "##vso[task.setvariable variable=NuGetFeed;]$nugetFeed"
displayName: Set NuGet feed
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
projects: '**/*.csproj'
vstsFeed: $(NuGetFeed)

- task: DotNetCoreCLI@2
displayName: Build
inputs:
projects: '**/*.csproj'
projects: '$(Solution)'
arguments: '--configuration $(BuildConfiguration)'

- task: codesigning@2
Expand Down
84 changes: 84 additions & 0 deletions fiskaltrust.Middleware.Interface.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29521.150
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{396D771A-5085-49F4-B020-389C901C75D3}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
README.md = README.md
version.json = version.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{18766606-E68D-44CC-B89A-5807F901D943}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{4A4977D1-0B9A-44F9-B4A3-3D08FBB58D14}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.interface", "src\fiskaltrust.ifPOS\fiskaltrust.interface.csproj", "{ED0862F3-D1A0-4246-A22D-937F471647CE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Interface.Tests", "test\fiskaltrust.ifPOS.Tests\fiskaltrust.Middleware.Interface.Tests.csproj", "{B4ECE1C6-E1F3-4F54-98B8-B588D9DB52D9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{7CCEF987-3E5A-48D0-9D69-708C62526829}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Interface.Client.Grpc", "src\fiskaltrust.Middleware.Interface.Client.Grpc\fiskaltrust.Middleware.Interface.Client.Grpc.csproj", "{5274E790-A7AD-4360-8613-72E9CCDF43CE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Interface.Client.Http", "src\fiskaltrust.Middleware.Interface.Client.Http\fiskaltrust.Middleware.Interface.Client.Http.csproj", "{71C15B88-ACE8-4926-AA1D-85ECA2199AE3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Interface.Client.Soap", "src\fiskaltrust.Middleware.Interface.Client.Soap\fiskaltrust.Middleware.Interface.Client.Soap.csproj", "{FB69506F-4B31-4F9E-90EC-078D035A17EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fiskaltrust.Middleware.Interface.Client.Shared", "src\fiskaltrust.Middleware.Interface.Client.Shared\fiskaltrust.Middleware.Interface.Client.Shared.csproj", "{4CF9D784-E218-414D-8A14-56D514C0FBA9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fiskaltrust.Middleware.Interface.Client.Tests", "test\fiskaltrust.Middleware.Interface.Client.Tests\fiskaltrust.Middleware.Interface.Client.Tests.csproj", "{8D5E806B-39EF-4FCD-AD59-5AB710F5D8BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED0862F3-D1A0-4246-A22D-937F471647CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED0862F3-D1A0-4246-A22D-937F471647CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED0862F3-D1A0-4246-A22D-937F471647CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED0862F3-D1A0-4246-A22D-937F471647CE}.Release|Any CPU.Build.0 = Release|Any CPU
{B4ECE1C6-E1F3-4F54-98B8-B588D9DB52D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4ECE1C6-E1F3-4F54-98B8-B588D9DB52D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4ECE1C6-E1F3-4F54-98B8-B588D9DB52D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4ECE1C6-E1F3-4F54-98B8-B588D9DB52D9}.Release|Any CPU.Build.0 = Release|Any CPU
{5274E790-A7AD-4360-8613-72E9CCDF43CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5274E790-A7AD-4360-8613-72E9CCDF43CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5274E790-A7AD-4360-8613-72E9CCDF43CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5274E790-A7AD-4360-8613-72E9CCDF43CE}.Release|Any CPU.Build.0 = Release|Any CPU
{71C15B88-ACE8-4926-AA1D-85ECA2199AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71C15B88-ACE8-4926-AA1D-85ECA2199AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71C15B88-ACE8-4926-AA1D-85ECA2199AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71C15B88-ACE8-4926-AA1D-85ECA2199AE3}.Release|Any CPU.Build.0 = Release|Any CPU
{FB69506F-4B31-4F9E-90EC-078D035A17EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB69506F-4B31-4F9E-90EC-078D035A17EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB69506F-4B31-4F9E-90EC-078D035A17EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB69506F-4B31-4F9E-90EC-078D035A17EB}.Release|Any CPU.Build.0 = Release|Any CPU
{4CF9D784-E218-414D-8A14-56D514C0FBA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CF9D784-E218-414D-8A14-56D514C0FBA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CF9D784-E218-414D-8A14-56D514C0FBA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CF9D784-E218-414D-8A14-56D514C0FBA9}.Release|Any CPU.Build.0 = Release|Any CPU
{8D5E806B-39EF-4FCD-AD59-5AB710F5D8BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D5E806B-39EF-4FCD-AD59-5AB710F5D8BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D5E806B-39EF-4FCD-AD59-5AB710F5D8BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D5E806B-39EF-4FCD-AD59-5AB710F5D8BB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{ED0862F3-D1A0-4246-A22D-937F471647CE} = {18766606-E68D-44CC-B89A-5807F901D943}
{B4ECE1C6-E1F3-4F54-98B8-B588D9DB52D9} = {4A4977D1-0B9A-44F9-B4A3-3D08FBB58D14}
{7CCEF987-3E5A-48D0-9D69-708C62526829} = {18766606-E68D-44CC-B89A-5807F901D943}
{5274E790-A7AD-4360-8613-72E9CCDF43CE} = {7CCEF987-3E5A-48D0-9D69-708C62526829}
{71C15B88-ACE8-4926-AA1D-85ECA2199AE3} = {7CCEF987-3E5A-48D0-9D69-708C62526829}
{FB69506F-4B31-4F9E-90EC-078D035A17EB} = {7CCEF987-3E5A-48D0-9D69-708C62526829}
{4CF9D784-E218-414D-8A14-56D514C0FBA9} = {7CCEF987-3E5A-48D0-9D69-708C62526829}
{8D5E806B-39EF-4FCD-AD59-5AB710F5D8BB} = {4A4977D1-0B9A-44F9-B4A3-3D08FBB58D14}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3CAE7E81-C6A5-44FA-8E98-F9207561129F}
EndGlobalSection
EndGlobal
46 changes: 0 additions & 46 deletions fiskaltrust.if.sln

This file was deleted.

24 changes: 24 additions & 0 deletions src/fiskaltrust.Middleware.Interface.Client.Grpc/GrpcPosFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using fiskaltrust.ifPOS.v1;
using fiskaltrust.Middleware.Interface.Client.Shared;
using System.Threading.Tasks;

namespace fiskaltrust.Middleware.Interface.Client.Grpc
{
public static class GrpcPosFactory
{
public static async Task<IPOS> CreatePosAsync(GrpcPosOptions options)
{
var connectionhandler = new GrpcProxyConnectionHandler<IPOS>(options);

if (options.RetryPolicyOptions != null)
{
var retryPolicyHelper = new RetryPolicyHandler<IPOS>(options.RetryPolicyOptions, connectionhandler);
return new PosRetryProxyClient(retryPolicyHelper);
}
else
{
return await connectionhandler.GetProxyAsync();
}
}
}
}
10 changes: 10 additions & 0 deletions src/fiskaltrust.Middleware.Interface.Client.Grpc/GrpcPosOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using fiskaltrust.Middleware.Interface.Client.Shared;
using Grpc.Core;

namespace fiskaltrust.Middleware.Interface.Client.Grpc
{
public class GrpcPosOptions : PosOptions
{
public ChannelCredentials ChannelCredentials { get; set; } = ChannelCredentials.Insecure;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using fiskaltrust.Middleware.Interface.Client.Shared.RetryLogic.Interfaces;
using Grpc.Core;
using ProtoBuf.Grpc.Client;
using System;
using System.Threading.Tasks;

namespace fiskaltrust.Middleware.Interface.Client.Grpc
{
internal class GrpcProxyConnectionHandler<T> : IProxyConnectionHandler<T> where T : class
{
private T _proxy;
private Channel _channel;
private readonly GrpcPosOptions _options;

public GrpcProxyConnectionHandler(GrpcPosOptions options)
{
_options = options;
}

public Task ReconnectAsync()
{
if (_proxy != null && _channel.State == ChannelState.Ready)
{
return Task.CompletedTask;
}
_channel = new Channel(_options.Url.Host, _options.Url.Port, _options.ChannelCredentials);
_proxy = _channel.CreateGrpcService<T>();

return Task.CompletedTask;
}

public async Task ForceReconnectAsync()
{
try
{
await _channel.ShutdownAsync();
}
catch
{
// We can ignore the case when shutdown failed
}
_channel = new Channel(_options.Url.Host, _options.Url.Port, ChannelCredentials.Insecure);
_proxy = _channel.CreateGrpcService<T>();
}

public async Task<T> GetProxyAsync()
{
if (_proxy == null || _channel.State != ChannelState.Ready)
{
await ReconnectAsync();
}

return _proxy;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="fiskaltrust.interface" Version="1.3.0-rc1" />
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
<PackageReference Include="Grpc.Core" Version="2.28.1" />
<PackageReference Include="protobuf-net.Grpc.Native" Version="1.0.37" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\fiskaltrust.Middleware.Interface.Client.Shared\fiskaltrust.Middleware.Interface.Client.Shared.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<_PackageFiles Include="$(OutputPath)\net461\fiskaltrust.Middleware.Interface.Client.Shared.dll">
<BuildAction>None</BuildAction>
<PackagePath>lib\net461\</PackagePath>
</_PackageFiles>
<_PackageFiles Include="$(OutputPath)\netstandard2.0\fiskaltrust.Middleware.Interface.Client.Shared.dll">
<BuildAction>None</BuildAction>
<PackagePath>lib\netstandard2.0\</PackagePath>
</_PackageFiles>
</ItemGroup>

<PropertyGroup>
<PackageId>fiskaltrust.Middleware.Interface.Client.Grpc</PackageId>
<Authors>fiskaltrust</Authors>
<Company>fiskaltrust</Company>
<PackageLicenseUrl>https://github.com/fiskaltrust/middleware-interface-dotnet/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/fiskaltrust/middleware-interface-dotnet</PackageProjectUrl>
<PackageIconUrl>https://portal.fiskaltrust.at/Content/favicons/favicon-64x64.png</PackageIconUrl>
<Description>An optional helper implementation to simplify the usage of the fiskaltrust Middleware interface via gRPC.</Description>
<Copyright>Copyright 2020</Copyright>
<PackageTags>fiskaltrust interface</PackageTags>
<AssemblyCompany>fiskaltrust</AssemblyCompany>
<AssemblyProduct>fiskaltrust.Middleware.Interface.Grpc</AssemblyProduct>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.IO;
using System.Xml.Serialization;

namespace fiskaltrust.Middleware.Interface.Client.Http.Helpers
{
internal static class XmlSerializationHelpers
{
public static string Serialize(object inputObject)
{
using (var writer = new StringWriter())
{
new XmlSerializer(inputObject.GetType()).Serialize(writer, inputObject);
return writer.ToString();
}
}
}
}
Loading

0 comments on commit adf8f7d

Please sign in to comment.