DotCMIS calls stop responding after I've fetched any two documents out of 5 document.
I have checked the logs on the Alfresco server and there is nothing at all related to the failed calls.
I have debugged to identify the timeout .
// define CMIS available path which is already available under alfresco parameters[DotCMIS.SessionParameter.AtomPubUrl] = "https://localhost:8080/alfresco/service/cmis";
// alfresco portal admin user name parameters[DotCMIS.SessionParameter.User] = "admin";
// alfresco portal admin password parameters[DotCMIS.SessionParameter.Password] = "w4rth0g!";
// define session factory SessionFactory factory = SessionFactory.NewInstance();
// using session factory get the default repository, on this repository we would be performing actions & create session on this repository ISession session = factory.GetRepositories(parameters)[0].CreateSession();
public ContentStream GetContentByDocumentId(string docId) { ISession session; IObjectId id; IDocument doc; IContentStream contentStream; ContentStream contentStreamModel = new ContentStream();
try
{
session = GetSession();
id = session.CreateObjectId(docId);
doc = session.GetObject(id) as IDocument;
// Content
contentStream = doc.GetContentStream();
contentStreamModel.FileName = contentStream.FileName;
contentStreamModel.Length = contentStream.Length;
contentStreamModel.MimeType = contentStream.MimeType;
contentStreamModel.Stream = contentStream.Stream;
contentStreamModel.Stream.Close();
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
finally
{
session = null;
id = null;
// session.Delete(id, true);
// session.Clear();
doc = null;
contentStream = null;
//contentStream.Stream.Close();
//contentStreamModel.Stream.Close();
}
return contentStreamModel;
}
Here i am closing the contenet stream . Later in the below method i am trying to loop through that
public static void CreateMergedPdf(string targetPdfLocation, IEnumerable docStreams) { try { using (FileStream stream = new FileStream(targetPdfLocation, FileMode.Create)) { var pdfDoc = new Document(PageSize.A4); PdfCopy pdf = new PdfCopy(pdfDoc, stream); pdfDoc.Open();
foreach (var doc in docStreams)
{
pdf.AddDocument(new PdfReader(doc));
}
pdfDoc.Close();
}
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
}
I have moved the closing connection to a the method where i am consuming here.
// Merge documents in order of orderNo field. var docStreams = new List(); //var docStreams2 = new List();
**foreach (string docId in orderedDocIds)
{
// Retreive doc from Alfresco.
var doc = GetContentByDocumentId(docId);
docStreams.Add(doc.Stream);
doc.Stream.Close();
}**
// docStreams.CopyTo(docStreams2.ToArray());
// Created a merged pdf and drops in a temp folder.
FileHelper.CreateMergedPdf(mergedPdfFileLocation, docStreams2);
return mergedPdfFileLocation;
Here i will get cannot access closed stream.Is there any way to reopen?
On third time when the createsession() is getting called it gives timeout errror.