如何使用Rally.NET工具包访问用户故事的任务集合

本文关键字:故事 任务 任务集 集合 用户 访问 何使用 Rally NET 工具包 | 更新日期: 2023-09-27 18:21:29

我得到:

未处理的异常:System.Collections.Generic.KeyNotFoundException:给定字典里没有关键字。

当迭代用户故事查询结果并尝试访问故事["任务"]时

foreach (var story in queryStoryResults.Results)
       {
           Console.WriteLine("FormattedID: " + story["FormattedID"]);
           Console.WriteLine("Name: " + story["Name"]);
           Console.Write("Tasks: " + story["Tasks"]);

}

如何使用Rally.NET工具包访问用户故事的任务集合

首先,确保正在提取Tasks,以及要提取的任务特定字段,例如State。接下来,在循环中需要一个嵌套循环来迭代用户故事结果。这是代码示例。它查询当前迭代中的用户故事,并打印出与查询结果相关联的任务的FormattedID和State:

namespace RESTexample_storiesFromIteration
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize the REST API
            RallyRestApi restApi;
            restApi = new RallyRestApi("user@domain.com", "1984", "https://rally1.rallydev.com", "1.43");
            //Set our Workspace and Project scopings
            String workspaceRef = "/workspace/1111";
            String projectRef = "/project/2222";
            bool projectScopingUp = false;
            bool projectScopingDown = true;
            DateTime now = DateTime.Today;
            String nowString = now.ToString("yyyy-MM-dd");
            Request iterationRequest = new Request("Iteration");
            iterationRequest.Workspace = workspaceRef;
            iterationRequest.Project = projectRef;
            iterationRequest.Fetch = new List<string>()
                {
                    "Name",
                    "StartDate",
                    "EndDate",
                    "Project",
                    "State"
                };
            String iterationQueryString = "((StartDate <= '"" + nowString + "'") AND (EndDate >= '"" + nowString + "'"))";
            iterationRequest.Query = new Query(iterationQueryString);
            QueryResult queryIterationResults = restApi.Query(iterationRequest);
            var myIteration = queryIterationResults.Results.First();
            var myIterationName = myIteration["Name"];
            var myIterationProject = myIteration["Project"];
            var myIterationProjectName = myIterationProject["Name"];
            Console.WriteLine("Name: " + myIterationName);
            Console.WriteLine("Project Ref: " + myIterationProjectName);
            Console.WriteLine("State: " + myIteration["State"]);
            // Query for Stories
            Request storyRequest = new Request("hierarchicalrequirement");
            storyRequest.Workspace = workspaceRef;
            storyRequest.Project = projectRef;
            storyRequest.ProjectScopeUp = projectScopingUp;
            storyRequest.ProjectScopeDown = projectScopingDown;
            storyRequest.Fetch = new List<string>()
                {
                    "Name",
                    "ObjectID",
                    "ScheduleState",
                    "State",
                    "FormattedID",
                    "PlanEstimate",
                    "Iteration",
                    "Tasks"
                };
            storyRequest.Query = new Query("Iteration.Name", Query.Operator.Equals, myIterationName);
            QueryResult queryStoryResults = restApi.Query(storyRequest);
            foreach (var s in queryStoryResults.Results)
            {
                Console.WriteLine("----------");
                Console.WriteLine("FormattedID: " + s["FormattedID"]);
                Console.WriteLine("Name: " + s["Name"]);
                Console.WriteLine("PlanEstimate: " + s["PlanEstimate"]);
                var tasks = s["Tasks"];
                foreach (var t in tasks)
                 {
                     Console.WriteLine("Task: " + t["FormattedID"] + " " + t["State"]);
                 }
            }
        }
    }
}