Rally SOAP API - 如何将附件添加到分层需求? [英] Rally SOAP API - How do I add an attachment to a Hierarchical Requirement?
本文介绍了Rally SOAP API - 如何将附件添加到分层需求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遵循了这段代码 将附件添加到 HierarchicalRequirement
.
I have followed this code to add attachment to a HierarchicalRequirement
.
我收到以下错误:
validation error: Attachment.attachments[0] should not be null
如何向层次结构需求添加附件?
How do I add an attachment to a Hierarchical Requirement?
推荐答案
您能否发布一段代码摘录来说明问题?如果您遵循了 Rally SOAP 中的方法API - 如何将附件添加到 TestCaseResult 你是在正确的轨道上.以下是在向故事添加附件时对我有用的快速代码示例:
Can you post a code excerpt that illustrates the problem? If you followed the approach in Rally SOAP API - How do I add an attachment to a TestCaseResult you're on the right track. Following is a quick code sample that works for me when adding an attachment to a story:
// issue query for target story
QueryResult queryResult = service.query(workspace, objectType, queryString, orderString, fetchFullObjects, start, pageSize);
// look at the object returned from query()
Console.WriteLine("Query returned " + queryResult.TotalResultCount + " objects");
// Grab the resulting story
DomainObject rallyObject = queryResult.Results.First();
HierarchicalRequirement queryStory = (HierarchicalRequirement)rallyObject;
// Read In Image Content
String imageFilePath = "C:\\Users\\username\\";
String imageFileName = "image1.png";
String fullImageFile = imageFilePath + imageFileName;
var imageFileLength = new FileInfo(fullImageFile).Length;
Image myImage = Image.FromFile(fullImageFile);
Console.WriteLine("Image File Length: " + imageFileLength);
// Convert Image to Byte Array format
byte[] imageByteArray = ImageToByteArray(myImage, System.Drawing.Imaging.ImageFormat.Png);
var imageNumberBytes = imageByteArray.Length;
// Create the Attachment Content
AttachmentContent attachmentContent = new AttachmentContent();
attachmentContent.Content = imageByteArray;
attachmentContent.Workspace = workspace;
CreateResult result = service.create(attachmentContent);
attachmentContent = (AttachmentContent)result.Object;
// Create the Attachment Container, wire it up to the AttachmentContent
Attachment myAttachment = new Attachment();
myAttachment.ContentType = "image/png";
myAttachment.Content = attachmentContent;
myAttachment.Name = "image1.png";
myAttachment.Size = imageNumberBytes ;
myAttachment.SizeSpecified = true;
myAttachment.User = user;
myAttachment.Artifact = queryStory;
myAttachment.Workspace = workspace;
// Create the attachment in Rally
result = service.create(myAttachment);
Console.WriteLine(result.Object);
}
public static byte[] ImageToByteArray (Image image, System.Drawing.Imaging.ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
return imageBytes;
}
}
}
这篇关于Rally SOAP API - 如何将附件添加到分层需求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文