Calls to Adobe Services API never return.
Using the following code, the call to createPdfOperation.Execute(executionContext); never returns.
private async Task ConvertToPDF()
{
try
{
if (checkedNodes.Count() == 0) return;
localService.isLoading = true;
// Initial setup, create credentials instance.
Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()
.WithClientId(clientId)
.WithClientSecret(clientSecret)
.Build();
//Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.Create(credentials);
foreach (FileNode bn in checkedNodes)
{
if (bn.ContentType == "SharePointFolder" || bn.ContentType == "Root" || bn.ContentType == "BlobPrefix") continue;
IFile spDoc = await localService.DownloadSharePointDocument($"{SharePointPath}/{bn.Path}");
if (spDoc == null) continue;
string mediaType = "UNSUPPORTED";
string fileExt = Path.GetExtension(bn.FileName).ToLower();
switch (fileExt)
{
case ".docx": mediaType = CreatePDFOperation.SupportedSourceFormat.DOCX.GetMediaType(); break;
case ".doc": mediaType = CreatePDFOperation.SupportedSourceFormat.DOC.GetMediaType(); break;
case ".xlsx": mediaType = CreatePDFOperation.SupportedSourceFormat.XLSX.GetMediaType(); break;
case ".xls": mediaType = CreatePDFOperation.SupportedSourceFormat.XLS.GetMediaType(); break;
default: mediaType = "UNSUPPORTED"; break;
}
if (mediaType == "UNSUPPORTED")
{
notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Error", Detail = $"{fileExt} files not supported.", Duration = -1 });
localService.isLoading = false;
return;
}
Stream ms = await spDoc.GetContentAsync();
ms.Seek(0, 0);
FileRef source = FileRef.CreateFromStream(ms, mediaType);
CreatePDFOperation createPdfOperation = CreatePDFOperation.CreateNew();
createPdfOperation.SetInput(source);
// Execute the operation.
FileRef result = createPdfOperation.Execute(executionContext);
// Save the result to the specified location.
Stream outStream = new MemoryStream();
result.SaveAs(outStream);
outStream.Seek(0, 0);
string newFileName = Path.GetFileNameWithoutExtension(bn.FileName) + ".pdf";
string upResult = await localService.UploadSharePointDocument(currentSharePointFolder, newFileName, outStream, false);
if (upResult != "SUCCESS")
{
notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Error", Detail = upResult, Duration = -1 });
localService.isLoading = false;
return;
}
}
string parentKeyValue = ParentObject.GetType().GetProperty(ParentKeyProperty).GetValue(ParentObject, null).ToString();
await Load(parentKeyValue);
}
catch (ServiceUsageException ex)
{ notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Service Usage", Detail = ex.Message, Duration = -1 }); }
catch (ServiceApiException ex)
{ notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Service Api", Detail = ex.Message, Duration = -1 }); }
catch (SDKException ex)
{ notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "SDK", Detail = ex.Message, Duration = -1 }); }
catch (IOException ex)
{ notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "IO", Detail = ex.Message, Duration = -1 }); }
catch (Exception ex)
{ notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Error", Detail = ex.Message, Duration = -1 }); }
finally
{
localService.isLoading = false;
checkedNodes = new List<object>();
}
}