Untitled
unknown
plain_text
8 months ago
4.7 kB
4
Indexable
var fetchINTLDocuments = new Func<Dictionary<string, string>>(() =>
{
async Task<KeyValuePair<string, string>> FetchProformaInvoiceAsync()
{
int retriesIdx = 0;
string DHLProformaURL = string.Empty;
try
{
var proformaReply = await labelSrv.getProformaAsync(new GetProformaRq()
{
id = shipmnetId,
idSpecified = true,
user_id = shipReques.UserName,
password = shipReques.Passsword,
});
if (!String.IsNullOrWhiteSpace(proformaReply?.@return.proforma))
{
var doc_name = $"CI_{packageLabels.ElementAt(0).TrackingNumber}.pdf";
File.WriteAllBytes(LabelsRoot + doc_name,
convert.frombase64string(proformareply.@return.proforma));
DHLProformaURL = LocalRoot + "pdfs/" + doc_name;
}
return new KeyValuePair<string, string>("DHLProforma", DHLProformaURL);
}
catch
{
do
{
Thread.Sleep(SleepTime);
await FetchProformaInvoiceAsync();
retriesIdx++;
}
while (retriesIdx < 3);
return new KeyValuePair<string, string>("DHLProforma", ""); ;
}
}
async Task<KeyValuePair<string, string>> FetchDHLInvoiceAsync()
{
string DHLInvoiceURL = string.Empty;
var dhlInvoiceReply = await labelSrv.getDHLInvoiceAsync(new GetDHLInvoiceRq()
{
id = shipmnetId,
idSpecified = true,
user_id = shipReques.UserName,
password = shipReques.Passsword,
});
if (!String.IsNullOrWhiteSpace(dhlInvoiceReply?.@return.dhl_invoice))
{
var doc_name = $"DHLInvoice_{packageLabels.ElementAt(0).TrackingNumber}.pdf";
File.WriteAllBytes(LabelsRoot + doc_name,
convert.frombase64string(dhlinvoicereply.@return.dhl_invoice));
DHLInvoiceURL = LocalRoot + "pdfs/" + doc_name;
}
return new KeyValuePair<string, string>("DHLInvoice", DHLInvoiceURL);
}
async Task<KeyValuePair<string, string>> FetchInvoiceAsync()
{
string InvoiceURL = "";
var invoiceReply = await labelSrv.getInvoiceAsync(new GetInvoiceRq()
{
id = shipmnetId,
idSpecified = true,
user_id = shipReques.UserName,
password = shipReques.Passsword,
});
if (!string.isnullorwhitespace(invoicereply.@return.invoice))
{
var doc_name = $"Invoice_{packageLabels.ElementAt(0).TrackingNumber}.pdf";
File.WriteAllBytes(LabelsRoot + doc_name,
convert.frombase64string(invoicereply.@return.invoice));
InvoiceURL = LocalRoot + "pdfs/" + doc_name;
}
return new KeyValuePair<string, string>("Invoice", InvoiceURL);
}
//var documentUrls = await Task.WhenAll(
var documentUrls = Task.WhenAll(
FetchProformaInvoiceAsync(),
FetchDHLInvoiceAsync(),
FetchInvoiceAsync()).Result;
return documentUrls.ToDictionary(pair => pair.Key, pair => pair.Value);
});
intlDocuments = fetchINTLDocuments();Editor is loading...
Leave a Comment