Rally SOAP API - How do I add an attachment to a Hierarchical Requirement?

隐身守侯 提交于 2019-12-13 06:32:51

问题


I have followed this code to add attachment to a HierarchicalRequirement.

I get the following error:

validation error: Attachment.attachments[0] should not be null

How do I add an attachment to a Hierarchical Requirement?


回答1:


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;
        }
    }
}


来源:https://stackoverflow.com/questions/10989084/rally-soap-api-how-do-i-add-an-attachment-to-a-hierarchical-requirement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!