summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Helpers/AssinadorHelper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Decompiler/Gestor.Application.Helpers/AssinadorHelper.cs')
-rw-r--r--Decompiler/Gestor.Application.Helpers/AssinadorHelper.cs183
1 files changed, 183 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Helpers/AssinadorHelper.cs b/Decompiler/Gestor.Application.Helpers/AssinadorHelper.cs
new file mode 100644
index 0000000..ecc002f
--- /dev/null
+++ b/Decompiler/Gestor.Application.Helpers/AssinadorHelper.cs
@@ -0,0 +1,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);
+ }
+}