1
我正在嘗試使用.Net API查詢附加到Rally任務中的用戶。 我成功地能夠查詢用戶故事以及相應的任務。在Rally .Net API中查詢特定任務的所有者?
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();
}
}
}
//我們需要
當我嘗試你所提到的,我不斷收到一個runTimeBinderException。我能夠處理,但仍然沒有運氣。 1)我還是查詢車主在 –
userStoryRequest.Fetch =新名單(){ 「FormattedID」, 「姓名」, 「任務」, 「估計」, 「國家」, 「所有者」, 「UserName」 }; –
即使我在taskResult期間查詢? –