Skip to content

Commit

Permalink
Agrege impresión de Póliza Mercosur
Browse files Browse the repository at this point in the history
  • Loading branch information
FacuMasino committed Aug 26, 2024
1 parent 6de4ef8 commit b8dcea9
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 53 deletions.
5 changes: 4 additions & 1 deletion ImprimirPolizas/PolicyDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class PolicyDocs
public string PolicyId { get; set; }
public string CardId { get; set; }
public string PaymentCupon { get; set; }
public string MercosurPolicy { get; set; }

public string GetIdByOption(ScTools.DownloadOpt opt)
{
Expand All @@ -25,8 +26,10 @@ public string GetIdByOption(ScTools.DownloadOpt opt)
return PaymentCupon;
case ScTools.DownloadOpt.policyCard:
return CardId;
case ScTools.DownloadOpt.mercosur:
return MercosurPolicy;
default:
return "";
return "0";
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ImprimirPolizas/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3")]
[assembly: AssemblyFileVersion("1.3")]
[assembly: AssemblyVersion("1.4")]
[assembly: AssemblyFileVersion("1.4")]
73 changes: 39 additions & 34 deletions ImprimirPolizas/ScTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public enum DownloadOpt
paymentReceipt = 5,
coupons = 6,
invoice = 7,
mercosur = 8,
}

// Verifica que el servidor este disponible
Expand Down Expand Up @@ -168,11 +169,15 @@ CancellationToken cancellationToken
};

client.DownloadFileAsync(
new Uri($"{_baseUrl}getBinaryV2?docId={docId}&opt={(int)opt}"),
new Uri(
$"{_baseUrl}getBinaryV2?docId={docId}&opt={(int)opt}&pcN={pcNumber}"
),
Path.Combine(folderPath, fileName)
);

Debug.Print($"{_baseUrl}getBinaryV2?docId={docId}&opt={(int)opt}");
Debug.Print(
$"{_baseUrl}getBinaryV2?docId={docId}&opt={(int)opt}&pcN={pcNumber}"
);

await tcs.Task;
}
Expand Down Expand Up @@ -231,6 +236,9 @@ public static string GetFileName(string pcNumber, DownloadOpt opt)
case DownloadOpt.invoice:
fileName += "Factura.pdf";
break;
case DownloadOpt.mercosur:
fileName += "Mercosur.pdf";
break;
default:
fileName += ".pdf";
break;
Expand Down Expand Up @@ -300,6 +308,8 @@ public static string GetOptionName(DownloadOpt opt)
return "Cupones de pago";
case ScTools.DownloadOpt.invoice:
return "Factura";
case ScTools.DownloadOpt.mercosur:
return "Mercosur";
default:
return "Desconocido";
}
Expand All @@ -311,53 +321,48 @@ CancellationToken ctsToken
)
{
PolicyDocs pcDocs = new PolicyDocs();

string baseUrl = $"{_baseUrl}getDocsId?policyNumber={policyNumber}";

try
{
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage res = await client.GetAsync(baseUrl, ctsToken))
{
using (HttpContent content = res.Content)
{
if (res.StatusCode != HttpStatusCode.OK)
{
throw new Exception(
"Error al obtener los documentos de la póliza."
);
}
var resData = await content.ReadAsStringAsync();
// Realiza la solicitud HTTP asíncrona
HttpResponseMessage response = await client.GetAsync(baseUrl, ctsToken);

JObject jsonData = JObject.Parse(resData);
pcDocs.PolicyId = jsonData["Policy"].ToString();
pcDocs.PaymentCupon = jsonData["PaymentCoupon"]?.ToString();
pcDocs.SummaryId = jsonData["PolicySummary"].ToString();
pcDocs.CardId = jsonData["InsuranceCardMandatory"].ToString();
return pcDocs;
}
}
// Maneja la cancelación aquí, si la solicitud se cancela
ctsToken.ThrowIfCancellationRequested();

// Asegúrate de manejar la respuesta correctamente
response.EnsureSuccessStatusCode();

string responseData = await response.Content.ReadAsStringAsync();

JObject jsonData = JObject.Parse(responseData);
pcDocs.PolicyId = jsonData["Policy"]?.ToString();
pcDocs.PaymentCupon = jsonData["PaymentCoupon"]?.ToString();
pcDocs.SummaryId = jsonData["PolicySummary"]?.ToString();
pcDocs.CardId = jsonData["InsuranceCardMandatory"]?.ToString();
pcDocs.MercosurPolicy = jsonData["MercosurPolicy"]?.ToString();
}
}
catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled)
catch (OperationCanceledException)
{
throw new OperationCanceledException();
// Re-lanzar la excepción OperationCanceledException para indicar que la tarea fue cancelada
throw;
}
catch (AggregateException ex)
when (ex.InnerException is WebException exWeb
&& exWeb.Status == WebExceptionStatus.RequestCanceled
)
{
throw new OperationCanceledException();
}
catch (TaskCanceledException)
catch (HttpRequestException ex) when (ex.InnerException is OperationCanceledException)
{
throw new OperationCanceledException();
// Si hay una excepción de tipo HttpRequestException con un InnerException de tipo OperationCanceledException
throw new OperationCanceledException("La solicitud fue cancelada.", ex);
}
catch (Exception ex)
{
throw ex;
// Re-lanzar cualquier otra excepción que no sea específica de cancelación
throw new Exception("Error al obtener los documentos de la póliza.", ex);
}

return pcDocs;
}

public static bool IsCarPolicy(string policyNumber)
Expand Down
52 changes: 41 additions & 11 deletions ImprimirPolizas/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b8dcea9

Please sign in to comment.