Skip to content

Commit 2a9767c

Browse files
committed
SP-17454 update c# client and avoid extra serialization
1 parent 3a14972 commit 2a9767c

9 files changed

Lines changed: 53 additions & 43 deletions

File tree

src/Regula.DocumentReader.NetCoreExample/Regula.DocumentReader.NetCoreExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<OutputType>Exe</OutputType>
44
<Product>DocumentReader WebClient Example</Product>
55
<PackageId>Regula.DocumentReader.NetCoreExampple</PackageId>
6-
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
6+
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
77
</PropertyGroup>
88
<ItemGroup>
99
<ProjectReference Include="..\Regula.DocumentReader.WebClient\Regula.DocumentReader.WebClient.csproj" />

src/Regula.DocumentReader.WebClient/Api/DocumentReaderApi.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ public RecognitionResponse Process(ProcessRequest processRequest, Dictionary<Str
5151
else
5252
processRequest.SystemInfo.License = License;
5353

54-
return new RecognitionResponse(this._processApi.ApiProcess(processRequest, headers, xRequestID));
54+
return new RecognitionResponse(this._processApi.ApiProcessWithHttpInfo(processRequest, headers, xRequestID));
5555
}
5656

57-
5857
public async Task<RecognitionResponse> ProcessAsync(ProcessRequest processRequest)
5958
{
6059
return await ProcessAsync(processRequest, new Dictionary<String, String>(), default(string));
@@ -77,7 +76,7 @@ public async Task<RecognitionResponse> ProcessAsync(ProcessRequest processReques
7776
else
7877
processRequest.SystemInfo.License = License;
7978

80-
var response = await this._processApi.ApiProcessAsync(processRequest, headers, xRequestID, cancellationToken);
79+
var response = await this._processApi.ApiProcessWithHttpInfoAsync(processRequest, headers, xRequestID, cancellationToken);
8180

8281
return new RecognitionResponse(response);
8382
}

src/Regula.DocumentReader.WebClient/Api/ProcessApi.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,11 @@ public void AddDefaultHeader(string key, string value)
258258
if (exception != null) throw exception;
259259
}
260260

261+
var rawResponse = localVarResponse.Content;
262+
261263
return new ApiResponse<ProcessResponse>(localVarStatusCode,
262264
localVarResponse.Headers.ToDictionarySafe(x => x.Name, x => string.Join(",", x.Value)),
263-
(ProcessResponse) this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(ProcessResponse)));
265+
(ProcessResponse) this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(ProcessResponse)), rawResponse);
264266
}
265267

266268
/// <summary>

src/Regula.DocumentReader.WebClient/Client/ApiResponse.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,30 @@ public class ApiResponse<T>
3535
/// </summary>
3636
/// <value>The data.</value>
3737
public T Data { get; private set; }
38+
39+
40+
/// <summary>
41+
/// Gets or sets the RawResponse
42+
/// </summary>
43+
/// <value>The data.</value>
44+
public string RawResponse { get; private set; }
3845

3946
/// <summary>
4047
/// Initializes a new instance of the <see cref="ApiResponse&lt;T&gt;" /> class.
4148
/// </summary>
4249
/// <param name="statusCode">HTTP status code.</param>
4350
/// <param name="headers">HTTP headers.</param>
4451
/// <param name="data">Data (parsed HTTP body)</param>
45-
public ApiResponse(int statusCode, IDictionary<string, string> headers, T data)
52+
/// <param name="rawResponse"></param>
53+
public ApiResponse(int statusCode,
54+
IDictionary<string, string> headers,
55+
T data,
56+
string rawResponse = null)
4657
{
4758
this.StatusCode= statusCode;
4859
this.Headers = headers;
4960
this.Data = data;
61+
this.RawResponse = rawResponse;
5062
}
5163

5264
}

src/Regula.DocumentReader.WebClient/Model/ContainerList.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
* Regula Document Reader Web API
33
*
4-
* Regula Document Reader Web API
4+
* Documents recognition as easy as reading two bytes. # Clients: * [JavaScript](https://github.com/regulaforensics/DocumentReader-web-js-client) client for the browser and node.js based on axios * [Java](https://github.com/regulaforensics/DocumentReader-web-java-client) client compatible with jvm and android * [Python](https://github.com/regulaforensics/DocumentReader-web-python-client) 3.5+ client * [C#](https://github.com/regulaforensics/DocumentReader-web-csharp-client) client for .NET & .NET Core
55
*
6-
* The version of the OpenAPI document: 5.2.0
6+
* The version of the OpenAPI document: 7.2.0
77
*
88
* Generated by: https://github.com/openapitools/openapi-generator.git
99
*/
@@ -25,7 +25,7 @@
2525
namespace Regula.DocumentReader.WebClient.Model
2626
{
2727
/// <summary>
28-
/// list with result objects
28+
/// List with various objects, containing processing results
2929
/// </summary>
3030
[DataContract]
3131
public partial class ContainerList : IEquatable<ContainerList>, IValidatableObject
@@ -38,8 +38,9 @@ protected ContainerList() { }
3838
/// <summary>
3939
/// Initializes a new instance of the <see cref="ContainerList" /> class.
4040
/// </summary>
41+
/// <param name="count">Length of list (Count for items).</param>
4142
/// <param name="list">list (required).</param>
42-
public ContainerList(List<ResultItem> list = default(List<ResultItem>))
43+
public ContainerList(int count = default(int), List<ResultItem> list = default(List<ResultItem>))
4344
{
4445
// to ensure "list" is required (not null)
4546
if (list == null)
@@ -51,8 +52,16 @@ protected ContainerList() { }
5152
this.List = list;
5253
}
5354

55+
this.Count = count;
5456
}
5557

58+
/// <summary>
59+
/// Length of list (Count for items)
60+
/// </summary>
61+
/// <value>Length of list (Count for items)</value>
62+
[DataMember(Name="Count", EmitDefaultValue=false)]
63+
public int Count { get; set; }
64+
5665
/// <summary>
5766
/// Gets or Sets List
5867
/// </summary>
@@ -67,6 +76,7 @@ public override string ToString()
6776
{
6877
var sb = new StringBuilder();
6978
sb.Append("class ContainerList {\n");
79+
sb.Append(" Count: ").Append(Count).Append("\n");
7080
sb.Append(" List: ").Append(List).Append("\n");
7181
sb.Append("}\n");
7282
return sb.ToString();
@@ -78,7 +88,7 @@ public override string ToString()
7888
/// <returns>JSON string presentation of the object</returns>
7989
public virtual string ToJson()
8090
{
81-
return JsonConvert.SerializeObject(this, Formatting.Indented);
91+
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
8292
}
8393

8494
/// <summary>
@@ -102,6 +112,11 @@ public bool Equals(ContainerList input)
102112
return false;
103113

104114
return
115+
(
116+
this.Count == input.Count ||
117+
(this.Count != null &&
118+
this.Count.Equals(input.Count))
119+
) &&
105120
(
106121
this.List == input.List ||
107122
this.List != null &&
@@ -119,6 +134,8 @@ public override int GetHashCode()
119134
unchecked // Overflow is fine, just wrap
120135
{
121136
int hashCode = 41;
137+
if (this.Count != null)
138+
hashCode = hashCode * 59 + this.Count.GetHashCode();
122139
if (this.List != null)
123140
hashCode = hashCode * 59 + this.List.GetHashCode();
124141
return hashCode;

src/Regula.DocumentReader.WebClient/Model/Ext/RecognitionResponse.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
using System.IO;
44
using System.Text;
55
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
6+
using Regula.DocumentReader.WebClient.Client;
67

78
namespace Regula.DocumentReader.WebClient.Model.Ext
89
{
910
public class RecognitionResponse
1011
{
11-
public RecognitionResponse(ProcessResponse originalResponse)
12+
private readonly ApiResponse<ProcessResponse> _apiResponse;
13+
14+
public RecognitionResponse(ApiResponse<ProcessResponse> apiResponse)
1215
{
13-
OriginalResponse = originalResponse;
16+
_apiResponse = apiResponse;
1417
}
15-
16-
public ProcessResponse OriginalResponse { get; }
1718

18-
public string Json => Newtonsoft.Json.JsonConvert.SerializeObject(this.OriginalResponse);
19+
public ProcessResponse OriginalResponse => this._apiResponse.Data;
20+
21+
public string Json => this._apiResponse.RawResponse;
1922

2023
public Status Status()
2124
{

src/Regula.DocumentReader.WebClient/Model/IdentResult.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ protected IdentResult() { }
4343
/// <param name="area">area.</param>
4444
/// <param name="image">image.</param>
4545
/// <param name="etalonImage">etalonImage.</param>
46-
/// <param name="percentValue">Probability percent for IMAGE_PATTERN check or element&#39;s visibility for IR_VISIBILITY.</param>
4746
/// <param name="areaList">areaList.</param>
48-
public IdentResult(int elementType = default(int), int lightIndex = default(int), RectangleCoordinates area = default(RectangleCoordinates), ImageData image = default(ImageData), ImageData etalonImage = default(ImageData), int percentValue = default(int), AreaContainer areaList = default(AreaContainer), int type = 0, int elementResult = default(int), int elementDiagnose = default(int)) : base(type, elementResult, elementDiagnose)
47+
public IdentResult(int elementType = default(int), int lightIndex = default(int), RectangleCoordinates area = default(RectangleCoordinates), ImageData image = default(ImageData), ImageData etalonImage = default(ImageData), AreaContainer areaList = default(AreaContainer), int type = 0, int elementResult = default(int), int elementDiagnose = default(int), int percentValue = default(int)) : base(type, elementResult, elementDiagnose, percentValue)
4948
{
5049
this.ElementType = elementType;
5150
this.LightIndex = lightIndex;
5251
this.Area = area;
5352
this.Image = image;
5453
this.EtalonImage = etalonImage;
55-
this.PercentValue = percentValue;
5654
this.AreaList = areaList;
5755
}
5856

@@ -86,13 +84,6 @@ protected IdentResult() { }
8684
[DataMember(Name="EtalonImage", EmitDefaultValue=false)]
8785
public ImageData EtalonImage { get; set; }
8886

89-
/// <summary>
90-
/// Probability percent for IMAGE_PATTERN check or element&#39;s visibility for IR_VISIBILITY
91-
/// </summary>
92-
/// <value>Probability percent for IMAGE_PATTERN check or element&#39;s visibility for IR_VISIBILITY</value>
93-
[DataMember(Name="PercentValue", EmitDefaultValue=false)]
94-
public int PercentValue { get; set; }
95-
9687
/// <summary>
9788
/// Gets or Sets AreaList
9889
/// </summary>
@@ -113,7 +104,6 @@ public override string ToString()
113104
sb.Append(" Area: ").Append(Area).Append("\n");
114105
sb.Append(" Image: ").Append(Image).Append("\n");
115106
sb.Append(" EtalonImage: ").Append(EtalonImage).Append("\n");
116-
sb.Append(" PercentValue: ").Append(PercentValue).Append("\n");
117107
sb.Append(" AreaList: ").Append(AreaList).Append("\n");
118108
sb.Append("}\n");
119109
return sb.ToString();
@@ -174,11 +164,6 @@ public bool Equals(IdentResult input)
174164
(this.EtalonImage != null &&
175165
this.EtalonImage.Equals(input.EtalonImage))
176166
) && base.Equals(input) &&
177-
(
178-
this.PercentValue == input.PercentValue ||
179-
(this.PercentValue != null &&
180-
this.PercentValue.Equals(input.PercentValue))
181-
) && base.Equals(input) &&
182167
(
183168
this.AreaList == input.AreaList ||
184169
(this.AreaList != null &&
@@ -205,8 +190,6 @@ public override int GetHashCode()
205190
hashCode = hashCode * 59 + this.Image.GetHashCode();
206191
if (this.EtalonImage != null)
207192
hashCode = hashCode * 59 + this.EtalonImage.GetHashCode();
208-
if (this.PercentValue != null)
209-
hashCode = hashCode * 59 + this.PercentValue.GetHashCode();
210193
if (this.AreaList != null)
211194
hashCode = hashCode * 59 + this.AreaList.GetHashCode();
212195
return hashCode;

src/Regula.DocumentReader.WebClient/Model/ResultItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
* Regula Document Reader Web API
33
*
4-
* Regula Document Reader Web API
4+
* Documents recognition as easy as reading two bytes. # Clients: * [JavaScript](https://github.com/regulaforensics/DocumentReader-web-js-client) client for the browser and node.js based on axios * [Java](https://github.com/regulaforensics/DocumentReader-web-java-client) client compatible with jvm and android * [Python](https://github.com/regulaforensics/DocumentReader-web-python-client) 3.5+ client * [C#](https://github.com/regulaforensics/DocumentReader-web-csharp-client) client for .NET & .NET Core
55
*
6-
* The version of the OpenAPI document: 5.2.0
6+
* The version of the OpenAPI document: 7.2.0
77
*
88
* Generated by: https://github.com/openapitools/openapi-generator.git
99
*/
@@ -131,7 +131,7 @@ public override string ToString()
131131
/// <returns>JSON string presentation of the object</returns>
132132
public virtual string ToJson()
133133
{
134-
return JsonConvert.SerializeObject(this, Formatting.Indented);
134+
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
135135
}
136136

137137
/// <summary>

src/Regula.DocumentReader.WebClient/Model/StatusResult.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99
*/
1010

1111
using System;
12-
using System.Linq;
1312
using System.IO;
1413
using System.Text;
15-
using System.Text.RegularExpressions;
16-
using System.Collections;
1714
using System.Collections.Generic;
18-
using System.Collections.ObjectModel;
1915
using System.Runtime.Serialization;
2016
using Newtonsoft.Json;
21-
using Newtonsoft.Json.Converters;
2217
using System.ComponentModel.DataAnnotations;
23-
using OpenAPIDateConverter = Regula.DocumentReader.WebClient.Client.OpenAPIDateConverter;
2418

2519
namespace Regula.DocumentReader.WebClient.Model
2620
{

0 commit comments

Comments
 (0)