当我尝试上传附件时,我随机收到此错误。
“无法从传输连接读取数据:连接已关闭。”
我有一个使用 C# RallyRestAPI 的导入函数,它从测试轨道中提取数据并将其插入到 Rally 中,并将附件复制到 Rally。我的测试数据有 3 个大小不同的附件,分别为 350k、63k 和 43k。当我运行我的导入器时,它会在不同时间的不同上传错误。没有一致性。有时三个都会失败,有时第二个会,第三个会成功。创建和更新故事似乎很好,所以它看起来像超时,但我不确定如何更改 RallyRestAPI 中的超时。
有没有其他人使用 C# 和 Rally RestAPI 遇到过这个问题?
这是我的上传代码。对 Connect() 的调用返回一个 RallyRestAPI 对象并登录到该对象。我每次调用 Rally 时都会重新登录(不确定我是否需要这样做)。
private string AddAttachment(string reference, string name, string content, long contentSize, string type) {
var restAPI = Connect();
try {
var attachmentContent = new DynamicJsonObject();
attachmentContent["Content"] = content;
attachmentContent["Workspace"] = _workspace["_ref"];
attachmentContent["Project"] = _target["_ref"];
var result = restAPI.Create("AttachmentContent", attachmentContent);
if (result.Success) {
_logger.Info("Attached the relevant AttachmentContent.");
}
else {
throw new LoggedException("Could not attach attachment to '" + reference + "' due to the following errors\n" + GetErrorList(result.Errors));
}
var attachmentContentRef = result.Reference;
// DynamicJSONObject for Attachment Container
var myAttachment = new DynamicJsonObject();
myAttachment["Workspace"] = _workspace["_ref"];
myAttachment["Project"] = _target["_ref"];
myAttachment["Artifact"] = reference;
myAttachment["Content"] = attachmentContentRef;
myAttachment["Name"] = Path.GetFileName(name);
var contentType = "image/jpg";
if (!string.IsNullOrEmpty(type)) {
switch (type.Trim().ToLower()) {
case "doc":
contentType = "document/text";
break;
default:
contentType = type;
break;
}
}
myAttachment["ContentType"] = contentType;
myAttachment["Size"] = contentSize;
result = restAPI.Create("Attachment", myAttachment);
if (result.Success) {
_logger.Info("Attached the relevant attachment.");
}
else {
throw new LoggedException("Could not attach attachment to '" + reference + "' due to the following errors\n" + GetErrorList(result.Errors));
}
return attachmentContentRef;
}
catch (Exception ex) {
throw new LoggedException("Unhandled exception occurred: ",ex);
}
}