Rally Rest Api C#ToolKit

时间:2014-06-26 20:55:20

标签: c# api rally

我正在尝试将C#工具包用于RallyRest API。我想显示每个版本的用户素材数量,以及团队的任务数量。分层要求请求不返回所有数据。 此外,如何根据特定版本和用户故事的所有者过滤数据?以下是我的代码。你能告诉我应该看哪儿吗?我看到了API。

RallyRestApi restApi = new RallyRestApi(username, password, "https://rally1.rallydev.com", "1.40");

            bool projectScopingUp = false;
            bool projectScopingDown = true;
            try
            {
                Request storyRequest = new Request("HierarchicalRequirement");
                storyRequest.Workspace = workspaceRef;
                storyRequest.Project = projectRef;

                storyRequest.ProjectScopeUp = projectScopingUp;
                storyRequest.ProjectScopeDown = projectScopingDown;
                storyRequest.Fetch = new List<string>()
                {
                    "Name",
                    "FormattedID",
                    "Project",
                    "Release",
                    "ScheduleState",
                    "State",
                    "Owner",
                    "Tasks"
    };
QueryResult queryStoryResults = restApi.Query(storyRequest);
                int totalUS = 0;
                foreach (var s in queryStoryResults.Results)
                {
                    if (s["Release"] != null)
                    {
                        Release = s["Release"]["Name"];
                        string word = "July 2014";
                        if (Release.Equals(word))
                        {
                           string tempOwner = s["Owner"]["_refObjectName"];
                        if (tempOwner.Contains("development")
                        {


                    Owner = s["Owner"]["_refObjectName"];
                    paragraph.AddFormattedText("ID : " + Id + " Name : " + Name + "  Owner : " + Owner + "Release :" + Release + "Number of Tasks : " + count, TextFormat.NotBold);

                    }

                    }
                }
            }

1 个答案:

答案 0 :(得分:1)

以下是按特定版本和故事所有者过滤故事的示例。它还可以获取每个故事的任务集合,并通过单独的请求进行水合。

static void Main(string[] args)
        {
            int storyCount = 0;
            int taskCount = 0;
            RallyRestApi restApi;
            restApi = new RallyRestApi("apiuser@co.com", "secret", "https://rally1.rallydev.com", "v2.0");

            String workspaceRef = "/workspace/1234";     //replace this OID with an OID of your workspace

            Request sRequest = new Request("HierarchicalRequirement");
            sRequest.Workspace = workspaceRef;
            sRequest.Fetch = new List<string>() { "FormattedID", "Name", "Tasks", "Release", "Project", "Owner" };
            sRequest.Query = new Query("Release.Name", Query.Operator.Equals, "r1").And(new Query("Owner", Query.Operator.Equals, "user@co.com"));
            QueryResult queryResults = restApi.Query(sRequest);

            foreach (var s in queryResults.Results)
            {
                Console.WriteLine("FormattedID: " + s["FormattedID"] + " Name: " + s["Name"] + " Release: " + s["Release"]._refObjectName + " Project: " + s["Project"]._refObjectName + " Owner: " + s["Owner"]._refObjectName);
                storyCount++;
                Request tasksRequest = new Request(s["Tasks"]);
                QueryResult queryTaskResult = restApi.Query(tasksRequest);
                foreach (var t in queryTaskResult.Results)
                {
                    Console.WriteLine("Task: " + t["FormattedID"] + " State: " + t["State"]);
                    taskCount++;
                }
            }
            Console.WriteLine(storyCount + " stories, "+  taskCount + " tasks ");
        }

我注意到您使用的是不再支持的1.40 WS API。如果您有较旧的代码,则必须重新考虑使用v2.0。在v2.0中,无法在同一请求中对集合进行水合。关于此主题的StackOverflow集会标签有很多例子,例如: here下载工具包here的最新dll。