1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Agger.Registro;
using Assinador.Model.Domain;
using Newtonsoft.Json;
using Sign.Modelos;
namespace Gestor.Application.Helpers;
public static class AssinadorHelper
{
private static ParametrosAssinaturaAssinador _parametros;
public const string Authorization = "Authorization";
public const string Server = "Server";
public const string Contrato = "Purchase";
public const string Adquirir = "Purchase/BuyPackage";
public const string Disponiveis = "Sign/Availble";
public const string Contratadas = "Sign/Purchased";
private static string ApiKey { get; set; }
public static Remetente Remetente { get; set; }
public static ParametrosAssinaturaAssinador Parametros
{
get
{
return _parametros;
}
set
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
_parametros = value;
if (value != null)
{
Remetente = new Remetente
{
Id = ApplicationHelper.IdFornecedor,
Documento = value.Documento,
Email = value.Email,
Nome = value.Nome,
Serial = ApplicationHelper.NumeroSerial
};
}
}
}
public static async Task<string> Key()
{
string key = null;
try
{
key = await string.Format("{0}{1}/86", Address.AssinadorApi(), "Authorization").Get<string>(ApplicationHelper.NumeroSerial.BasicKey(), basic: true);
}
catch (Exception)
{
}
return key;
}
public static async Task<int> Licencas(string key)
{
if (key == null)
{
return 0;
}
int licencas = 0;
try
{
licencas = int.Parse(await string.Format("{0}{1}/{2}", Address.AssinadorApi(), "Sign/Availble", ApplicationHelper.IdFornecedor).Get<string>(key));
}
catch (Exception)
{
}
return licencas;
}
public static async Task<bool> Contratado(long id)
{
return await string.Format("{0}{1}/{2}/86", Address.GestorApi(), "Purchase", id).Get<string>(ApplicationHelper.NumeroSerial.BasicKey(), basic: true) == "true";
}
public static string BasicKey(this string serial)
{
return Base64EncodeBasic($"{serial}:{Funcoes.GetNetworkTime().ToUniversalTime().Ticks}");
}
private static string Base64EncodeBasic(string plainText)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(plainText));
}
public static async Task<HttpStatusCode> Get(this string command, string token = null, bool basic = false)
{
string text = (basic ? "Basic" : "Token");
Uri uri = new Uri(Address.GestorApi(), command);
HttpClient val = new HttpClient();
if (!string.IsNullOrWhiteSpace(token))
{
val.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(text, token);
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
HttpResponseMessage val2;
try
{
val2 = await val.GetAsync(uri).ConfigureAwait(continueOnCapturedContext: false);
}
catch (Exception)
{
return HttpStatusCode.InternalServerError;
}
return val2.StatusCode;
}
internal static async Task<T> Get<T>(this string command, string token = null, bool basic = false) where T : class
{
string text = (basic ? "Basic" : "Token");
Uri uri = new Uri(command);
HttpClient val = new HttpClient();
if (!string.IsNullOrWhiteSpace(token))
{
val.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(text, token);
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
HttpResponseMessage val2;
try
{
val2 = await val.GetAsync(uri).ConfigureAwait(continueOnCapturedContext: false);
}
catch (Exception)
{
return null;
}
if (val2.StatusCode != HttpStatusCode.OK)
{
return null;
}
_ = val2.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<T>(val2.Content.ReadAsStringAsync().Result);
}
internal static async Task<T> Put<T>(this string command, T keyValues, string token = null, bool basic = false) where T : class
{
string text = (basic ? "Basic" : "Token");
Uri uri = new Uri(command);
StringContent val = new StringContent(JsonConvert.SerializeObject((object)keyValues, (Formatting)1, new JsonSerializerSettings
{
ReferenceLoopHandling = (ReferenceLoopHandling)1
}), Encoding.UTF8, "application/json");
HttpClient val2 = new HttpClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
if (!string.IsNullOrWhiteSpace(token))
{
val2.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(text, token);
}
HttpResponseMessage val3 = await val2.PutAsync(uri, (HttpContent)(object)val);
if (val3.StatusCode != HttpStatusCode.OK && val3.StatusCode != HttpStatusCode.NoContent)
{
return null;
}
if (val3.StatusCode == HttpStatusCode.NoContent)
{
return null;
}
return JsonConvert.DeserializeObject<T>(val3.Content.ReadAsStringAsync().Result);
}
}
|