2012-06-12 54 views

回答

1

你能發表一個代碼摘錄來說明問題嗎?如果您按照Rally SOAP API - How do I add an attachment to a TestCaseResult中的方法行事,那麼您正處於正確的軌道上。以下是在向故事添加附件時適用於我的快速代碼示例:

 // 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; 
     } 
    } 
} 
+0

謝謝。有用。我所做的不同之處在於創建附件內容,然後創建附件並分配給HierarchicalRequirement對象並創建HierarchicalRequirement。現在我已經將其更改爲創建HierarchicalRequirement,然後創建附件,並且它完美地工作。再次感謝。 – user1450091

+0

如果您同意以上回答您的問題,請將答案標記爲已接受 - 這有助於在標籤論壇中找出已回答的問題。 – 2012-06-17 06:03:07

相關問題