在 Rally .Net API 中查询特定任务的所有者?

问题描述 投票:0回答:1

我正在尝试使用 .Net API 查询附加到 Rally 中的任务的用户。 我成功地查询了用户故事以及相应的任务。

using System;
using System.Collections.Generic;

namespace RallyIntegration
{
    using Microsoft.CSharp.RuntimeBinder;
    using Rally.RestApi;
    using Rally.RestApi.Response;
    class UserStoryTask
    {
        static void Main(string[] args)
        {
            ///<summary>
            ///Will reuturn the user stories, tasks and the estimates per each task
            /// </summary>

            //instantiate Rally Object
            RallyRestApi api = new RallyRestApi();

            //user-credentials
            const string username = "[email protected]"; //use get methods
            const string password = "secret"; //use get methods;
            const string serverUrl = "https://rally1.rallydev.com";

            //authenitcate
            api.Authenticate(username, password, serverUrl, null, false);

           
            string workspaceReferenceID = "/workspace/secret";
            string projectReferenceID = "/project/secret";
            bool projectScopingUp = false; //will not include all the projects above the default project
            bool projectScopingdown = true; //will include child projects

            //setup the userStoryRequest
            Request userStoryRequest = new Request("HierarchicalRequirement");
            userStoryRequest.Workspace = workspaceReferenceID;
            userStoryRequest.Project = projectReferenceID;
            userStoryRequest.ProjectScopeUp = projectScopingUp;
            userStoryRequest.ProjectScopeDown = projectScopingdown;

            //fetch data from the story request
            userStoryRequest.Fetch = new List<string>()
            {
                "FormattedID", "Name", "Tasks", "Estimate", "State", "Owner", "UserName"
            };

            //Userstory Query
            userStoryRequest.Query = (new Query("LastUpdateDate", Query.Operator.GreaterThan, "2016-01-01"));
            QueryResult userStoryResult = api.Query(userStoryRequest);

            //iterate through the query results
            foreach (var userStory in userStoryResult.Results)
            {
                Console.WriteLine(userStory["FormattedID"] + ":" + userStory["Name"]);

                //Task Request
                Request taskRequest = new Request(userStory["Tasks"]);
                QueryResult taskResult = api.Query(taskRequest);
                if (taskResult.TotalResultCount > 0)
                {
                    foreach (var task in taskResult.Results)
                    {
                        var taskName = task["Name"];
                        var taskEstimate = task["Estimate"];
                        var taskState = task["State"];
                        Console.WriteLine("Task Name: " + taskName + Environment.NewLine + "Estimate: " + taskEstimate + Environment.NewLine + "State: "+taskState);

                        try
                        { 
                            //how can I say only return if the task has an owner attached to it
                            //http://stackoverflow.com/questions/32621290/what-is-the-proper-way-to-fetch-the-owner-name-of-a-rally-task
                            Request ownerRequest = new Request(userStory["Owner"]);
                            QueryResult ownerResult = api.Query(ownerRequest);
                            foreach (var owner in ownerResult.Results)
                            {
                                var ownerName = owner["Owner"];
                                Console.WriteLine("Owner: " + ownerName);
                            }
                        }
                        catch(NullReferenceException)
                        {
                            Console.WriteLine("Null Reference Hit");
                        }
                        catch(RuntimeBinderException)
                        {
                            Console.WriteLine("Binder Exception");
                        }
                        finally
                        {
                            //api.close();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Tasks Not Found...");
                }
            }
            Console.ReadLine();
        }
    }
}

//我们需要提取特定任务的用户或所有者

c# .net rally
1个回答
0
投票

只要你在查询任务集合时获取Owner:

taskRequest.setFetch("Owner");

您应该能够看到每个任务的检查所有者:

foreach (var task in taskResult.Results)
{
    var owner = task["Owner"];

    if (owner != null) 
    {
        var ownerName = owner["_refObjectName"];                    
        //todo: do something here
    }


}
© www.soinside.com 2019 - 2024. All rights reserved.