Skip to content

Commit 5d887c2

Browse files
author
Mikhail Kalatchev
committed
v0.3.3
1 parent 0add792 commit 5d887c2

3 files changed

Lines changed: 85 additions & 49 deletions

File tree

ErpNetClient/Client.cs

Lines changed: 79 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,113 +24,146 @@ public class Client
2424

2525
public string DeviceId { get; set; } = string.Empty;
2626

27+
28+
2729
/// <summary>
28-
/// Register sale
30+
/// Retreives list of configured printers
2931
/// </summary>
30-
/// <param name="receipt">Receipt</param>
31-
/// <returns>Receipt status</returns>
32-
public async Task<DeviceStatusWithReceiptInfo> PrintFiscalReceiptAsync(Receipt receipt)
32+
/// <returns>List of configured printers</returns>
33+
public async Task<Dictionary<string, DeviceInfo>> GetPrintersAsync()
3334
{
3435
using (var clt = new HttpClient())
3536
{
36-
StringContent cont = new StringContent(JsonSerializer.Serialize<Receipt>(receipt, serializeOptions), Encoding.UTF8, "application/json");
3737
clt.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
38-
HttpResponseMessage res = await clt.PostAsync(new Uri($"{BaseUrl}printers/{this.DeviceId}/receipt"), cont);
38+
HttpResponseMessage res = await clt.GetAsync(new Uri($"{BaseUrl}printers"));
3939
string resStr = await res.Content.ReadAsStringAsync();
40-
return JsonSerializer.Deserialize<DeviceStatusWithReceiptInfo>(resStr, serializeOptions);
40+
return JsonSerializer.Deserialize<Dictionary<string, DeviceInfo>>(resStr, serializeOptions);
4141
}
4242
}
4343

4444
/// <summary>
45-
/// Register refund
45+
/// Retreives printer information - model, uri, etc.
4646
/// </summary>
47-
/// <param name="receipt">Receipt</param>
48-
/// <returns>Receipt status</returns>
49-
public async Task<DeviceStatusWithReceiptInfo> PrintRefundReceiptAsync(ReversalReceipt receipt)
47+
/// <param name="deviceId">Id of the printer</param>
48+
/// <returns>Infomation for the device</returns>
49+
public async Task<DeviceInfo> GetPrinterInfoAsync(string deviceId = null)
5050
{
5151
using (var clt = new HttpClient())
5252
{
53-
StringContent cont = new StringContent(JsonSerializer.Serialize<ReversalReceipt>(receipt, serializeOptions), Encoding.UTF8, "application/json");
5453
clt.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
55-
HttpResponseMessage res = await clt.PostAsync(new Uri($"{BaseUrl}printers/{this.DeviceId}/reversalreceipt"), cont);
54+
HttpResponseMessage res = await clt.GetAsync(new Uri($"{BaseUrl}printers/{(string.IsNullOrWhiteSpace(deviceId) ? this.DeviceId : deviceId)}"));
5655
string resStr = await res.Content.ReadAsStringAsync();
57-
return JsonSerializer.Deserialize<DeviceStatusWithReceiptInfo>(resStr, serializeOptions);
56+
return JsonSerializer.Deserialize<DeviceInfo>(resStr, serializeOptions);
5857
}
5958
}
6059

61-
private async Task<DeviceStatusWithDateTime> PrintReportAsync(bool closeDay)
60+
/// <summary>
61+
/// Retreives printer status
62+
/// </summary>
63+
/// <param name="deviceId">Id of the printer</param>
64+
/// <returns>Device status</returns>
65+
public async Task<DeviceStatusWithDateTime> GetPrinterStatusAsync(string deviceId = null)
6266
{
6367
using (var clt = new HttpClient())
6468
{
65-
StringContent cont = new StringContent(String.Empty, Encoding.UTF8, "application/json");
6669
clt.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
67-
HttpResponseMessage res = await clt.PostAsync(new Uri($"{BaseUrl}printers/{this.DeviceId}/{(closeDay ? "zreport" : "xreport")}"), cont);
70+
HttpResponseMessage res = await clt.GetAsync(new Uri($"{BaseUrl}printers/{(string.IsNullOrWhiteSpace(deviceId) ? this.DeviceId : deviceId)}/status"));
6871
string resStr = await res.Content.ReadAsStringAsync();
6972
return JsonSerializer.Deserialize<DeviceStatusWithDateTime>(resStr, serializeOptions);
7073
}
7174
}
7275

73-
/// <summary>
74-
/// Z Report ends the sales day and can be used for bookkeeping
75-
/// </summary>
76-
/// <returns>Device status</returns>
77-
public async Task<DeviceStatusWithDateTime> PrintZReportAsync()
78-
{
79-
return await PrintReportAsync(true);
80-
}
76+
// Get {id}/cash
77+
// GET taskinfo : TaskInfoResult
8178

8279
/// <summary>
83-
/// X Report prints sales summary (without closing the fiscal day)
80+
/// Sends raw requests to the printer
8481
/// </summary>
85-
/// <returns>Device status</returns>
86-
public async Task<DeviceStatusWithDateTime> PrintXReportAsync()
82+
/// <param name="request"><see cref="RawRequest"/> to be sent.</param>
83+
/// <returns>Device status with raw response</returns>
84+
public async Task<DeviceStatusWithRawResponse> SendRawRequestAsync(RawRequest request)
8785
{
88-
return await PrintReportAsync(false);
86+
using (var clt = new HttpClient())
87+
{
88+
StringContent cont = new StringContent(JsonSerializer.Serialize<RawRequest>(request, serializeOptions), Encoding.UTF8, "application/json");
89+
clt.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
90+
HttpResponseMessage res = await clt.PostAsync(new Uri($"{BaseUrl}printers/{this.DeviceId}/rawrequest"), cont);
91+
string resStr = await res.Content.ReadAsStringAsync();
92+
return JsonSerializer.Deserialize<DeviceStatusWithRawResponse>(resStr, serializeOptions);
93+
}
8994
}
9095

9196
/// <summary>
92-
/// Retreives list of configured printers
97+
/// Register sale
9398
/// </summary>
94-
/// <returns>List of configured printers</returns>
95-
public async Task<Dictionary<string, DeviceInfo>> GetPrintersAsync()
99+
/// <param name="receipt">Receipt</param>
100+
/// <returns>Receipt status</returns>
101+
public async Task<DeviceStatusWithReceiptInfo> PrintFiscalReceiptAsync(Receipt receipt)
96102
{
97103
using (var clt = new HttpClient())
98104
{
105+
StringContent cont = new StringContent(JsonSerializer.Serialize<Receipt>(receipt, serializeOptions), Encoding.UTF8, "application/json");
99106
clt.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
100-
HttpResponseMessage res = await clt.GetAsync(new Uri($"{BaseUrl}printers"));
107+
HttpResponseMessage res = await clt.PostAsync(new Uri($"{BaseUrl}printers/{this.DeviceId}/receipt"), cont);
101108
string resStr = await res.Content.ReadAsStringAsync();
102-
return JsonSerializer.Deserialize<Dictionary<string, DeviceInfo>>(resStr, serializeOptions);
109+
return JsonSerializer.Deserialize<DeviceStatusWithReceiptInfo>(resStr, serializeOptions);
103110
}
104111
}
105112

106113
/// <summary>
107-
/// Retreives printer status
114+
/// Register refund
108115
/// </summary>
109-
/// <param name="deviceId">Id of the printer</param>
110-
/// <returns>The status</returns>
111-
public async Task<DeviceStatusWithDateTime> GetPrinterStatusAsync(string deviceId = null)
116+
/// <param name="receipt">Receipt</param>
117+
/// <returns>Receipt status</returns>
118+
public async Task<DeviceStatusWithReceiptInfo> PrintRefundReceiptAsync(ReversalReceipt receipt)
112119
{
113120
using (var clt = new HttpClient())
114121
{
122+
StringContent cont = new StringContent(JsonSerializer.Serialize<ReversalReceipt>(receipt, serializeOptions), Encoding.UTF8, "application/json");
115123
clt.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
116-
HttpResponseMessage res = await clt.GetAsync(new Uri($"{BaseUrl}printers/{(string.IsNullOrWhiteSpace(deviceId) ? this.DeviceId : deviceId)}/status"));
124+
HttpResponseMessage res = await clt.PostAsync(new Uri($"{BaseUrl}printers/{this.DeviceId}/reversalreceipt"), cont);
117125
string resStr = await res.Content.ReadAsStringAsync();
118-
return JsonSerializer.Deserialize<DeviceStatusWithDateTime>(resStr, serializeOptions);
126+
return JsonSerializer.Deserialize<DeviceStatusWithReceiptInfo>(resStr, serializeOptions);
119127
}
120128
}
121129

130+
// POST {id}/withdraw
131+
// POST {id}/deposit
132+
// POST {id}/datetime
133+
122134
/// <summary>
123-
/// Sends raw requests to the printer
135+
/// Z Report ends the sales day and can be used for bookkeeping
124136
/// </summary>
125-
/// <param name="request"><see cref="RawRequest"/> to be sent.</param>
126-
/// <returns>Device status status</returns>
127-
public async Task<DeviceStatusWithDateTime> SendRawRequestAsync(RawRequest request)
137+
/// <returns>Device status</returns>
138+
public async Task<DeviceStatusWithDateTime> PrintZReportAsync()
139+
{
140+
return await PrintReportAsync(true);
141+
}
142+
143+
/// <summary>
144+
/// X Report prints sales summary (without closing the fiscal day)
145+
/// </summary>
146+
/// <returns>Device status</returns>
147+
public async Task<DeviceStatusWithDateTime> PrintXReportAsync()
148+
{
149+
return await PrintReportAsync(false);
150+
}
151+
152+
// POST {id}/duplicate
153+
// POST {id}/reset
154+
155+
/// <summary>
156+
/// Base function (to wrap it)
157+
/// </summary>
158+
/// <param name="closeDay"></param>
159+
/// <returns></returns>
160+
private async Task<DeviceStatusWithDateTime> PrintReportAsync(bool closeDay)
128161
{
129162
using (var clt = new HttpClient())
130163
{
131-
StringContent cont = new StringContent(JsonSerializer.Serialize<RawRequest>(request, serializeOptions), Encoding.UTF8, "application/json");
164+
StringContent cont = new StringContent(String.Empty, Encoding.UTF8, "application/json");
132165
clt.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
133-
HttpResponseMessage res = await clt.PostAsync(new Uri($"{BaseUrl}printers/{this.DeviceId}/rawrequest"), cont);
166+
HttpResponseMessage res = await clt.PostAsync(new Uri($"{BaseUrl}printers/{this.DeviceId}/{(closeDay ? "zreport" : "xreport")}"), cont);
134167
string resStr = await res.Content.ReadAsStringAsync();
135168
return JsonSerializer.Deserialize<DeviceStatusWithDateTime>(resStr, serializeOptions);
136169
}

ErpNetClient/ErpNetClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageTags>Fiscal server;Datecs;Tremol;Daisy;Eltrade;Incotex;ISL;SKYWARE Group;ErpNet.FS</PackageTags>
1616
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1717
<RepositoryUrl>https://github.com/SKYWARE-Group/ErpNetClient</RepositoryUrl>
18-
<Version>0.3.2</Version>
18+
<Version>0.3.3</Version>
1919
</PropertyGroup>
2020

2121
<ItemGroup>

TestApp/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ static async Task Main(string[] args)
6363

6464
var c = new Client() { DeviceId = "dt937256" };
6565
var res = await c.SendRawRequestAsync(new RawRequest() { Request = "P800\t200\t" });
66-
res = await c.SendRawRequestAsync(new RawRequest() { Request = "P1200\t200\t" });
67-
res = await c.SendRawRequestAsync(new RawRequest() { Request = "P1800\t200\t" });
6866
Console.WriteLine($"OK: {res.Ok}");
67+
68+
var res2 = await c.GetPrinterInfoAsync();
69+
Console.WriteLine($"URI: {res2.Uri}");
70+
71+
6972
}
7073

7174
}

0 commit comments

Comments
 (0)