Hello,
I need a bit of advice on how I can refactor my code. Right now I created it using FileStream and it works quite fine, the next step is to make it work with MemorySteam which I don't really get on.
if (packingSlipCounter > 1)
{
for(int i = 1; i <=conLen(pslip); i )
{
custPackingSlipJour = CustPackingSlipJour::findFromCustPackingSlipTrans(conPeek(refid, i), conPeek(pslip, i), conPeek(datephys, i));
select docuRef
where docuRef.RefCompanyId == custPackingSlipJour.DataAreaId &&
docuRef.RefTableId == custPackingSlipJour.TableId &&
docuRef.RefRecId == custPackingSlipJour.RecId &&
docuRef.TypeId == Parameters.DocuTypeId;
if (docuRef && Parameters.Cloud == NoYes::Yes)
{
System.IO.MemoryStream attachmentStream = new System.IO.MemoryStream();
using (System.IO.Stream docuRefStream = DocumentManagement::getAttachmentStream(docuRef))
{
docuRefStream.CopyTo(attachmentStream);
}
System.Byte[] binData2;
binData2 = attachmentStream.ToArray();
gotcmr = true;
cmrFileCounter ;
}
else if (docuRef)
{
System.IO.Stream stream = DocumentManagement::getAttachmentStream(docuRef);
cmrFile = filePath docuRef.originalFileName();
System.IO.FileStream fileStream = new System.IO.FileStream(cmrFile, System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
stream.CopyTo(fileStream);
fileStream.Close();
cmrfilename = conIns(cmrfilename, cmrFileCounter 1, docuRef.originalFileName());
gotcmr = true;
cmrFileCounter ;
}
}
private void MergePDF()
{
PdfSharp.Pdf.PdfDocument outPutPDFDocument = new PdfSharp.Pdf.PdfDocument();
PdfSharp.Pdf.PdfDocument inputPDFDocument = new PdfSharp.Pdf.PdfDocument();
PdfSharp.Pdf.PdfPages pdfPages;
int i, j, pageCount;
FileName pdfFile;
InteropPermission permission;
str errorMessage;
try
{
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
for (i = 1; i <= conLen(cmrfilename); i )
{
pdfFile = filePath conPeek(cmrfilename,i);
inputPDFDocument = PdfSharp.Pdf.IO.PdfReader::Open(pdfFile, PdfSharp.Pdf.IO.PdfDocumentOpenMode::Import);
outputPDFDocument.set_Version(inputPDFDocument.get_Version());
pageCount = inputPDFDocument.get_PageCount();
pdfPages = inputPDFDocument.get_Pages();
if (pageCount > 0)
{
for (j = 0 ; j < pageCount; j )
{
outputPDFDocument.AddPage(pdfPages.get_Item(j));
}
}
}
outputPDFDocument.Save(filePath "MergedCMR.pdf");
CodeAccessPermission::revertAssert();
cmrFile = filePath "MergedCMR.pdf";
}
catch(Exception::CLRError)
{
errorMessage = AifUtil::getClrErrorMessage();
CodeAccessPermission::revertAssert();
throw error(errorMessage);
}
}