【发布时间】:2017-01-15 17:13:08
【问题描述】:
在我从 5 个文档中提取任意两个文档后,DotCMIS 调用停止响应。
我检查了 Alfresco 服务器上的日志,没有任何与失败的调用相关的内容。
我已调试确定超时。
// 定义 CMIS 可用路径,该路径在 alfresco 下已经可用 参数[DotCMIS.SessionParameter.AtomPubUrl] = "https://localhost:8080/alfresco/service/cmis";
// alfresco 门户管理员用户名 参数[DotCMIS.SessionParameter.User] = "admin";
// 露天门户管理员密码 参数[DotCMIS.SessionParameter.Password] = "w4rth0g!";
// 定义会话工厂 SessionFactory 工厂 = SessionFactory.NewInstance();
// 使用会话工厂获取默认存储库,在此存储库上我们将执行操作并在此存储库上创建会话 ISession session = factory.GetRepositories(parameters)[0].CreateSession();
public ContentStream GetContentByDocumentId(string docId) { ISession 会话; IObjectId 标识; IDocument 文档; IContentStream 内容流; 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;
}
我在这里关闭内容流。稍后在下面的方法中,我试图循环遍历该方法
public static void CreateMergedPdf(string targetPdfLocation, IEnumerable docStreams) { 尝试 { 使用 (FileStream 流 = new FileStream(targetPdfLocation, FileMode.Create)) { var pdfDoc = new Document(PageSize.A4); PdfCopy pdf = 新 PdfCopy(pdfDoc, 流); pdfDoc.Open();
foreach (var doc in docStreams)
{
pdf.AddDocument(new PdfReader(doc));
}
pdfDoc.Close();
}
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
}
我已将关闭连接移至我在此处使用的方法。
// 按orderNo字段的顺序合并文档。 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;
这里我将无法访问已关闭的流。有什么方法可以重新打开吗?
在第三次调用 createsession() 时会出现超时错误。
【问题讨论】:
-
只需打开一个会话并重复使用它。不需要为每个文档打开一个会话。
标签: .net asp.net-mvc-4 alfresco dotcms dotcmis