Skip to content

Commit

Permalink
Merge pull request #35 from fiskaltrust/user/tsc/journalfix
Browse files Browse the repository at this point in the history
Don't return \0 in last journal chunk
  • Loading branch information
TSchmiedlechner authored Nov 26, 2020
2 parents 9a90eb8 + 9c19a4c commit f00141e
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace fiskaltrust.Middleware.Interface.Client.Extensions
{
public static class StreamExtensions
{
public static async IAsyncEnumerable<JournalResponse> ToAsyncEnumerable(this Stream stream)
public static async IAsyncEnumerable<JournalResponse> ToAsyncEnumerable(this Stream stream, int chunkSize)
{
var chunkSize = 4096;
var buffer = new byte[chunkSize];
while ((_ = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
int readAmount;
while ((readAmount = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
yield return new JournalResponse
{
Chunk = buffer.ToList()
Chunk = buffer.Take(readAmount).ToList()
};
buffer = new byte[chunkSize];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.3.4",
"version": "1.3.11",
"releaseBranches": [
"^refs/heads/master$",
"^refs/tags/v\\d+(?:\\.\\d+)*(?:-.*)?$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public AsyncJournalPOSHelper(IPOS innerPOS)
public IAsyncEnumerable<JournalResponse> JournalAsync(JournalRequest request)
{
var stream = _innerPOS.Journal(request.ftJournalType, request.From, request.To);
return stream.ToAsyncEnumerable();
return stream.ToAsyncEnumerable(request.MaxChunkSize);
}

public Task<EchoResponse> EchoAsync(EchoRequest message) => _innerPOS.EchoAsync(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;

namespace fiskaltrust.Middleware.Interface.Client.Http
{
public class HttpPosClientOptions : ClientOptions
{
public HttpCommunicationType CommunicationType { get; set; }
using System;

namespace fiskaltrust.Middleware.Interface.Client.Http
{
public class HttpPosClientOptions : ClientOptions
{
public HttpCommunicationType CommunicationType { get; set; }
public bool UseUnversionedLegacyUrls { get; set; } = false;
public Guid? CashboxId { get; set; }
public string AccessToken { get; set; }
}

public enum HttpCommunicationType
{
Json,
Xml
}

public Guid? CashboxId { get; set; }
public string AccessToken { get; set; }
}

public enum HttpCommunicationType
{
Json,
Xml
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.3.4",
"version": "1.3.11",
"releaseBranches": [
"^refs/heads/master$",
"^refs/tags/v\\d+(?:\\.\\d+)*(?:-.*)?$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AsyncPOSHelper(ifPOS.v1.IPOS innerPOS)
public IAsyncEnumerable<ifPOS.v1.JournalResponse> JournalAsync(ifPOS.v1.JournalRequest request)
{
var stream = _innerPOS.Journal(request.ftJournalType, request.From, request.To);
return stream.ToAsyncEnumerable();
return stream.ToAsyncEnumerable(request.MaxChunkSize);
}

public Task<ifPOS.v1.EchoResponse> EchoAsync(ifPOS.v1.EchoRequest message) => Task.Run(() => _innerPOS.EchoAsync(message));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace fiskaltrust.Middleware.Interface.Client.Soap
{
public class SoapClientOptions : ClientOptions
{
public long MaxReceivedMessageSize { get; set; } = 16 * 1024 * 1024;
public TimeSpan ReceiveTimeout { get; set; } = TimeSpan.FromDays(14);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ namespace fiskaltrust.Middleware.Interface.Client.Soap
public static class SoapDESSCDFactory
{
public static async Task<IDESSCD> CreateSSCDAsync(ClientOptions options)
{
var soapClientOptions = new SoapClientOptions
{
RetryPolicyOptions = options.RetryPolicyOptions,
Url = options.Url
};
return await CreateSSCDAsync(soapClientOptions);
}

public static async Task<IDESSCD> CreateSSCDAsync(SoapClientOptions options)
{
var connectionhandler = new SoapProxyConnectionHandler<IDESSCD>(options);

Expand Down
10 changes: 10 additions & 0 deletions src/fiskaltrust.Middleware.Interface.Client.Soap/SoapPosFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ namespace fiskaltrust.Middleware.Interface.Client.Soap
public static class SoapPosFactory
{
public static async Task<IPOS> CreatePosAsync(ClientOptions options)
{
var soapClientOptions = new SoapClientOptions
{
RetryPolicyOptions = options.RetryPolicyOptions,
Url = options.Url
};
return await CreatePosAsync(soapClientOptions);
}

public static async Task<IPOS> CreatePosAsync(SoapClientOptions options)
{
var connectionhandler = new SoapProxyConnectionHandler<IPOS>(options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ namespace fiskaltrust.Middleware.Interface.Client.Soap
{
internal class SoapProxyConnectionHandler<T> : IProxyConnectionHandler<T> where T : class
{
private const long MAX_RECEIVED_MESSAGE_SIZE = 16 * 1024 * 1024;
private const int RECEIVE_TIMEOUT_DAYS = 14;

private T _proxy;
private readonly ClientOptions _options;
private readonly SoapClientOptions _options;

public SoapProxyConnectionHandler(ClientOptions options)
public SoapProxyConnectionHandler(SoapClientOptions options)
{
_options = options;
}
Expand Down Expand Up @@ -77,14 +74,13 @@ private Binding ConfigureBinding()
{
// Use timeout * 2 to make sure the call doesn't end before the outer timeout
var sendTimeout = _options.RetryPolicyOptions?.ClientTimeout.Double() ?? RetryPolicyOptions.Default.ClientTimeout.Double();
var receiveTimeout = TimeSpan.FromDays(RECEIVE_TIMEOUT_DAYS);

return _options.Url.Scheme switch
{
"http" => new BasicHttpBinding(BasicHttpSecurityMode.None) { MaxReceivedMessageSize = MAX_RECEIVED_MESSAGE_SIZE, SendTimeout = sendTimeout, ReceiveTimeout = receiveTimeout },
"https" => new BasicHttpBinding(BasicHttpSecurityMode.Transport) { MaxReceivedMessageSize = MAX_RECEIVED_MESSAGE_SIZE, SendTimeout = sendTimeout, ReceiveTimeout = receiveTimeout },
"net.pipe" => new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { MaxReceivedMessageSize = MAX_RECEIVED_MESSAGE_SIZE, SendTimeout = sendTimeout, ReceiveTimeout = receiveTimeout },
"net.tcp" => new NetTcpBinding(SecurityMode.None) { MaxReceivedMessageSize = MAX_RECEIVED_MESSAGE_SIZE, SendTimeout = sendTimeout, ReceiveTimeout = receiveTimeout },
"http" => new BasicHttpBinding(BasicHttpSecurityMode.None) { MaxReceivedMessageSize = _options.MaxReceivedMessageSize, SendTimeout = sendTimeout, ReceiveTimeout = _options.ReceiveTimeout },
"https" => new BasicHttpBinding(BasicHttpSecurityMode.Transport) { MaxReceivedMessageSize = _options.MaxReceivedMessageSize, SendTimeout = sendTimeout, ReceiveTimeout = _options.ReceiveTimeout },
"net.pipe" => new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { MaxReceivedMessageSize = _options.MaxReceivedMessageSize, SendTimeout = sendTimeout, ReceiveTimeout = _options.ReceiveTimeout },
"net.tcp" => new NetTcpBinding(SecurityMode.None) { MaxReceivedMessageSize = _options.MaxReceivedMessageSize, SendTimeout = sendTimeout, ReceiveTimeout = _options.ReceiveTimeout },
_ => throw new ArgumentException($"The url {_options.Url} is not supported.", nameof(_options.Url))
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.3.4",
"version": "1.3.11",
"releaseBranches": [
"^refs/heads/master$",
"^refs/tags/v\\d+(?:\\.\\d+)*(?:-.*)?$"
Expand Down

0 comments on commit f00141e

Please sign in to comment.