2

我是 Rally 世界的新手,正在努力研究如何使用 RallyRestAPI。有许多示例说明如何查询 Rally 以获取我认为最有帮助的相关信息。我要做的是创建一个 C# 命令行工具来将用户添加到项目中。看来我使用 RallyRestAPI.Create("projectpermission",some dynamic json object) 接口来完成创建。我的问题是理解“一些动态 json 对象”部分。我不确定如何正确设置它。如果有人有一个如何设置它的小例子,我将不胜感激。

4

2 回答 2

1

这是说明如何执行此操作的代码示例。注意:

  • 运行代码以创建权限的用户 ID 必须是工作区或订阅管理员
  • 用户必须已经拥有 Workspace 中的权限(即成为 Workspace 用户)才能成功创建 ProjectPermission

    命名空间 RestExample_AddUsersToProject { 类程序 { 静态无效 Main(string[] args) {

            String userName = "user@company.com";
            String userPassword = "topsecret";
            String serverUrl = "https://rally1.rallydev.com";
            String wsapiVersion = "1.38";
    
            RallyRestApi restApi = new RallyRestApi(
                userName,
                userPassword,
                serverUrl,
                wsapiVersion
            );
    
            restApi.Headers[RallyRestApi.HeaderType.Vendor] = "Rally Software";
            restApi.Headers[RallyRestApi.HeaderType.Name] = "RestExample_AddUsersToProject";
    
            // Query for Project for which we want to add permissions
            Request projectRequest = new Request("project");
            projectRequest.Fetch = new List<string>()
            {
                "Name",
                "Owner",
                "State",
                "Description"
            };
            String projectName = "Avalanche Hazard Mapping";
    
            projectRequest.Query = new Query("Name", Query.Operator.Equals, projectName);
            QueryResult queryProjectResults = restApi.Query(projectRequest);
            var myProject = queryProjectResults.Results.First();
            String myProjectReference = myProject["_ref"];
    
            Console.WriteLine("Project Name: " + myProject["Name"]);
            Console.WriteLine("State: " + myProject["State"]);
    
            // Query for User for whom we wish to add ProjectPermission
            Request userRequest = new Request("user");
            userRequest.Fetch = new List<string>()
                {
                    "UserName",
                    "Subscription",
                    "DisplayName"
                };
    
    
            // User needing the permissions
            userRequest.Query = new Query("UserName", Query.Operator.Equals, "\"boromir@midearth.com\"");
            QueryResult queryUserResults = restApi.Query(userRequest);
    
            var myUser = queryUserResults.Results.First();
            String myUserReference = myUser["_ref"];
    
            Console.WriteLine("Username: " + myUser["UserName"]);
            Console.WriteLine("Display Name: " + myUser["DisplayName"]);
            Console.WriteLine("Subscription: " + myUser["Subscription"]);
    
            // Setup required ProjectPermission data
            DynamicJsonObject newProjectPermission = new DynamicJsonObject();
    
            newProjectPermission["User"] = myUser;
            newProjectPermission["Project"] = myProject;
            newProjectPermission["Role"] = "Editor";
    
            // Create the permission in Rally
            CreateResult addProjectPermissionResult = restApi.Create("ProjectPermission", newProjectPermission);
    
            DynamicJsonObject fetchedProjectPermission = restApi.GetByReference(addProjectPermissionResult.Reference, "Name");
            Console.WriteLine("Created ProjectPermission with Role: " + fetchedProjectPermission["Name"]);            
        }
    }
    

    }

于 2012-11-06T16:49:40.720 回答
0

这里有一些非常基本的 CRUD + 查询示例:http:
//developer.rallydev.com/help/rest-api-net

一般流程总是创建一个新的 DynamicJsonObject,设置适当的字段,然后将该对象传递给 RallyRestApi 的 Create 方法。

于 2012-11-06T05:10:02.150 回答