简体   繁体   中英

Getting Project List via Rally C# API

I need a way to retrieve a list of projects using C#.

Tried doing something like this:

    DynamicJsonObject sub = restApi.GetSubscription("Projects");
        //query the project collection
        Request wRequest = new Request(sub["Projects"]);
        QueryResult queryResult = restApi.Query(wRequest);

        return queryResult.Results.Select(result => new Project()
        {
            Id = result["ObjectID"],
            Name = result["Name"]
        }).ToList();

unfortunately with no success. Can anyone help please?

The code below should print workspaces and projects to which the user whose account is used to authenticate the code has access to.

            DynamicJsonObject sub = restApi.GetSubscription("Workspaces");

            Request wRequest = new Request(sub["Workspaces"]);
            wRequest.Limit = 1000;
            QueryResult queryResult = restApi.Query(wRequest);
            int allProjects = 0;
            foreach (var result in queryResult.Results)
            {
                var workspaceReference = result["_ref"];
                var workspaceName = result["Name"];
                Console.WriteLine("Workspace: " + workspaceName);
                Request projectsRequest = new Request(result["Projects"]);
                projectsRequest.Fetch = new List<string>()
                {
                    "Name"
                };
                projectsRequest.Limit = 10000; //project requests are made per workspace
                QueryResult queryProjectResult = restApi.Query(projectsRequest);
                int projectsPerWorkspace = 0;
                foreach (var p in queryProjectResult.Results)
                {
                    allProjects++;
                    projectsPerWorkspace++;
                    Console.WriteLine(projectsPerWorkspace + " Project: " + p["Name"] + " State: " + p["State"]);
                } 
            }
            Console.WriteLine("Returned " + allProjects + " projects in the subscription");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM