Create() public method

Create an object of the specified type from the specified object
Rally returned an HTML page. This usually occurs when Rally is off-line. Please check the ErrorMessage property for more information. The JSON returned by Rally was not able to be deserialized. Please check the JsonData property for what was returned by Rally.
public Create ( string typePath, DynamicJsonObject obj ) : Rally.RestApi.Response.CreateResult
typePath string the type to be created
obj DynamicJsonObject the object to be created
return Rally.RestApi.Response.CreateResult
        static void Main(string[] args)
        {
            RallyRestApi restApi;
            restApi = new RallyRestApi("*****@*****.**", "secret", "https://rally1.rallydev.com", "v2.0");

            String projectRef = "/project/12352608219";
            Request defectRequest = new Request("Defect");
            defectRequest.Project = projectRef;
            defectRequest.Fetch = new List<string>()
                {
                    "Name",
            "FormattedID",
                    "Tasks"
                };

            defectRequest.Query = new Query("FormattedID", Query.Operator.Equals, "DE8");
            QueryResult defectResults = restApi.Query(defectRequest);
            String defRef = defectResults.Results.First()._ref;
            String defName = defectResults.Results.First().Name;
            Console.WriteLine(defName + " " + defRef);
            DynamicJsonObject defect = restApi.GetByReference(defRef, "Name", "FormattedID", "Tasks");
            String taskCollectionRef = defect["Tasks"]._ref;
            Console.WriteLine(taskCollectionRef);

            ArrayList taskList = new ArrayList();

            foreach (var d in defectResults.Results)
            {
                Request tasksRequest = new Request(d["Tasks"]);
                QueryResult tasksResult = restApi.Query(tasksRequest);
                foreach (var t in tasksResult.Results)
                {
                    var tName = t["Name"];
                    var tFormattedID = t["FormattedID"];
                    Console.WriteLine("Task: " + tName + " " + tFormattedID);
                    DynamicJsonObject task = new DynamicJsonObject();
                    task["_ref"] = t["_ref"];
                    taskList.Add(task);
                }
            }

            Console.WriteLine("Count of elements in the collection before adding a new task: " + taskList.Count);

            DynamicJsonObject newTask = new DynamicJsonObject();
            newTask["Name"] = "another last task";
            newTask["WorkProduct"] = defRef;
            CreateResult createResult = restApi.Create(projectRef, "Task", newTask);
            newTask = restApi.GetByReference(createResult.Reference, "FormattedID", "Name", "WorkProduct");
            Console.WriteLine(newTask["FormattedID"] + " " + newTask["Name"] + " WorkProduct:" + newTask["WorkProduct"]["FormattedID"]);
            taskList.Add(newTask);

            Console.WriteLine("Count of elements in the array after adding a new task: " + taskList.Count);
            defect["Tasks"] = taskList;
            OperationResult updateResult = restApi.Update(defRef, defect);
        }
Esempio n. 2
0
        int DoSign(IEnumerable<Artifact> artifacts, SynchronizationContext sc)
        {
            var restApi = new RallyRestApi(Settings.Default.RallyUser, Settings.Default.RallyPassword
                //, proxy: new WebProxy("localhost:8888", false)
                );

            foreach (var tagArt in artifacts)
            {
                var toCreate = new DynamicJsonObject();
                toCreate["Text"] = "%FIX_CODE_REVIEW_PASSED%";
                toCreate["Artifact"] = tagArt.Reference;
                var createResult = restApi.Create("ConversationPost", toCreate);

                // update status
                sc.Post(_ => {
                    var lvi = listViewArtifacts.Items.Cast<ListViewItem>().FirstOrDefault(l => l.Tag == tagArt);
                    if (!createResult.Success)
                    {
                        lvi.BackColor = Color.Tomato;

                        if (createResult.Errors.Count > 0)
                            lvi.SubItems[1].Text = createResult.Errors[0];
                        else
                            lvi.SubItems[1].Text = "Unexpected error";
                    }
                    else
                    {
                        lvi.BackColor = Color.LightGreen;
                        lvi.SubItems[3].Text = "✔";
                    }
                }, null);
            }

            return 0;
        }
    static void Main(string[] args)
    {
        RallyRestApi restApi = new RallyRestApi("*****@*****.**", "secret", "https://sandbox.rallydev.com", "v2.0");
        DynamicJsonObject user = restApi.GetCurrentUser();
        String userRef = user["_ref"];
        String workspaceRef = "/workspace/12352608129"; //use valid workspace OID in your Rally
        String projectRef = "/project/14018981229";         //use valid project OID in your Rally

        System.Diagnostics.TextWriterTraceListener myListener = new System.Diagnostics.TextWriterTraceListener("log.log", "myListener");

        try
        {
            //create story
            DynamicJsonObject myStory = new DynamicJsonObject();
            myStory["Name"] = "my story " + DateTime.Now;
            myStory["Project"] = projectRef;
            myStory["Owner"] = userRef;
            CreateResult createStory = restApi.Create(workspaceRef, "HierarchicalRequirement", myStory);
            myStory = restApi.GetByReference(createStory.Reference, "FormattedID", "Owner", "Project");
            myListener.WriteLine(DateTime.Now + "___________\r\n" +  myStory["FormattedID"] + " Owner: " + myStory["Owner"]._refObjectName + " Project: " + myStory["Project"]._refObjectName);

            //update story
            myStory["Description"] = "updated " + DateTime.Now;

            //create tasks
            for (int i = 1; i <= 3; i++)
            {
                DynamicJsonObject myTask = new DynamicJsonObject();
                myTask["Name"] = "task " + i + DateTime.Now;
                myTask["Owner"] = userRef;
                myTask["State"] = "In-Progress";
                myTask["WorkProduct"] = myStory["_ref"];
                CreateResult createTask = restApi.Create(workspaceRef, "Task", myTask);
                myTask = restApi.GetByReference(createTask.Reference, "FormattedID", "Owner", "State");
                myListener.WriteLine(myTask["FormattedID"] + " State: " + myTask["StateX"]);
            }
        }
        catch(Exception e)
        {
            myListener.WriteLine(e);
        }

        myListener.Flush();
    }
        static void Main(string[] args)
        {
            RallyRestApi restApi = new RallyRestApi(webServiceVersion: "v2.0");
                String apiKey = "_abc123";
                restApi.Authenticate(apiKey, "https://rally1.rallydev.com", allowSSO: false);
                String projectRef = "/project/32904827032";
                try
                {
                    //create story
                    DynamicJsonObject myStory = new DynamicJsonObject();
                    myStory["Name"] = "another story " + DateTime.Now;
                    myStory["Project"] = projectRef;

                    CreateResult createStory = restApi.Create(workspaceRef, "HierarchicalRequirement", myStory);
                    myStory = restApi.GetByReference(createStory.Reference, "FormattedID", "Project");

                    //update story
                    myStory["Description"] = "updated " + DateTime.Now;
                    myStory["c_CustomString"] = "abc123";
                    Console.WriteLine("--------------------");
                    Console.WriteLine(myStory["FormattedID"]);
                    OperationResult updateResult = restApi.Update(myStory["_ref"], myStory);

                    //create tasks
                    for (int i = 1; i <= 3; i++)
                    {
                        DynamicJsonObject myTask = new DynamicJsonObject();
                        myTask["Name"] = "task " + i + DateTime.Now;
                        myTask["State"] = "In-Progress";
                        myTask["WorkProduct"] = myStory["_ref"];
                        CreateResult createTask = restApi.Create(workspaceRef, "Task", myTask);
                        myTask = restApi.GetByReference(createTask.Reference, "FormattedID", "Owner", "State");
                        Console.WriteLine(myTask["FormattedID"]);

                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
        }
        static void Main(string[] args)
        {
            RallyRestApi restApi = new RallyRestApi(webServiceVersion: "v2.0");
            String apiKey = "_abc123";
            restApi.Authenticate(apiKey, "https://rally1.rallydev.com", allowSSO: false);
            String workspaceRef = "/workspace/123";
            String projectRef = "/project/456";

            Request request = new Request("PortfolioItem/Feature");
            request.Fetch = new List<string>() { "Name", "FormattedID" };
            request.Query = new Query("FormattedID", Query.Operator.Equals, "F2356");
            QueryResult result = restApi.Query(request);

            String featureRef = result.Results.First()._ref;
            Console.WriteLine("found" + featureRef);

            //create stories
            try
            {
                for (int i = 1; i <= 25; i++)
                {
                    DynamicJsonObject story = new DynamicJsonObject();
                    story["Name"] = "story " + i;
                    story["PlanEstimate"] = new Random().Next(2,10);
                    story["PortfolioItem"] = featureRef;
                    story["Project"] = projectRef;
                    CreateResult createResult = restApi.Create(workspaceRef, "HierarchicalRequirement", story);
                    story = restApi.GetByReference(createResult.Reference, "FormattedID");
                    Console.WriteLine("creating..." + story["FormattedID"]);
                }
            //read stories
                DynamicJsonObject feature = restApi.GetByReference(featureRef, "UserStories");
                Request storiesRequest = new Request(feature["UserStories"]);
                storiesRequest.Fetch = new List<string>()
                {
                    "FormattedID",
                    "PlanEstimate"
                };
                storiesRequest.Limit = 1000;
                QueryResult storiesResult = restApi.Query(storiesRequest);
                int storyCount = 0;
                foreach (var userStory in storiesResult.Results)
                {
                    Console.WriteLine(userStory["FormattedID"] + " " + userStory["PlanEstimate"]);
                    storyCount++;
                }
                Console.WriteLine(storyCount);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        static void Main(string[] args)
        {
            RallyRestApi restApi = new RallyRestApi(webServiceVersion: "v2.0");
            String apiKey = "_abc777";
            restApi.Authenticate(apiKey, "https://rally1.rallydev.com", allowSSO: false);
            String workspaceRef = "/workspace/123";
            String projectRef = "/project/134";

            DynamicJsonObject badDefect = new DynamicJsonObject();
            badDefect["Name"] = "bad defect " + DateTime.Now;
            badDefect["Project"] = projectRef;

            CreateResult createRequest = restApi.Create(workspaceRef, "Defect", badDefect);
            badDefect = restApi.GetByReference(createRequest.Reference, "FormattedID", "Project");
            Console.WriteLine(badDefect["FormattedID"] + " " + badDefect["Project"]._refObjectName);
        }
    static void Main(string[] args)
    {
        RallyRestApi restApi = new RallyRestApi("*****@*****.**", "secret", "https://rally1.rallydev.com", "v2.0");
        DynamicJsonObject user = restApi.GetCurrentUser();
        String userRef = user["_ref"];
        String workspaceRef = "/workspace/11111"; //use valid workspace OID in your Rally
        String projectRef = "/project/12345";         //use valid project OID in your Rally

        DynamicJsonObject myStory = new DynamicJsonObject();
        myStory["Name"] = "my story";
        myStory["Project"] = projectRef;
        myStory["Owner"] = userRef;
        CreateResult createResult = restApi.Create(workspaceRef, "HierarchicalRequirement", myStory);
        myStory = restApi.GetByReference(createResult.Reference, "FormattedID", "Owner", "Project");
        Console.WriteLine(myStory["FormattedID"] + " " + myStory["Owner"]._refObjectName + " " + myStory["Project"]._refObjectName);
    }
        static void Main(string[] args)
        {
            RallyRestApi restApi = new RallyRestApi(webServiceVersion: "v2.0");
            String apiKey = "_abc123";
            restApi.Authenticate(apiKey, "https://rally1.rallydev.com", allowSSO: false);
            String workspaceRef = "/workspace/1011574887"; //non-default workspace of the user
            String projectRef = "/project/1791269111"; //a non-default project of the user (inside the workspace above)
            try
            {
                //create testset
                DynamicJsonObject myTestSet = new DynamicJsonObject();
                myTestSet["Name"] = "important set " + DateTime.Now;
                myTestSet["Project"] = projectRef;

                CreateResult createTestSet = restApi.Create(workspaceRef, "TestSet", myTestSet);
                myTestSet = restApi.GetByReference(createTestSet.Reference, "FormattedID", "Project");
                Console.WriteLine(myTestSet["FormattedID"] + " " + myTestSet["Project"]._refObjectName);

                //find current iteration

                Request iterationRequest = new Request("Iteration");
                iterationRequest.Project = projectRef;
                iterationRequest.ProjectScopeDown = false;
                iterationRequest.ProjectScopeUp = false;
                iterationRequest.Fetch = new List<string>() { "ObjectID", "Name" };
                iterationRequest.Query = new Query("(StartDate <= Today)").And(new Query("(EndDate >= Today)"));
                QueryResult queryResults = restApi.Query(iterationRequest);
                if (queryResults.TotalResultCount > 0)
                {
                    Console.WriteLine(queryResults.Results.First()["Name"] + " " + queryResults.Results.First()["ObjectID"]);
                    myTestSet["Iteration"] = queryResults.Results.First()._ref;
                    OperationResult updateResult = restApi.Update(myTestSet["_ref"], myTestSet);
                }
                else
                {
                    Console.WriteLine("No current iterations");
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        static void Main(string[] args)
        {
            RallyRestApi restApi = new RallyRestApi("*****@*****.**", "secret", "https://rally1.rallydev.com", "v2.0");
            String workspaceRef = "/workspace/11111"; //use valid workspace OID in your Rally
            String projectRef = "/project/12345";         //use valid project OID in your Rally
            String userRef = "/user/777";
            DynamicJsonObject d = new DynamicJsonObject();
            d["Name"] = "some bug";
            d["Project"] = projectRef;
            d["Owner"] = userRef;

            CreateResult createResult = restApi.Create(workspaceRef, "Defect", d);
            DynamicJsonObject defect = restApi.GetByReference(createResult.Reference, "FormattedID");
            Console.WriteLine(defect["FormattedID"]);

            //update defect
            defect["Description"] = "bad bug";
            OperationResult updateResult = restApi.Update(defect["_ref"], defect);
        }
        static void Main(string[] args)
        {
            RallyRestApi restApi;
            restApi = new RallyRestApi("*****@*****.**", "secret", "https://rally1.rallydev.com", "v2.0");

            String projectRef = "/project/123456";     //use valid OID of your project

            Request userRequest = new Request("User");

            userRequest.Query = new Query("UserName", Query.Operator.Equals, "*****@*****.**");

            QueryResult userResults = restApi.Query(userRequest);

            String userRef = userResults.Results.First()._ref;
            Console.WriteLine(userRef);

            DynamicJsonObject myStory = new DynamicJsonObject();
            myStory["Name"] = "a new story";
            myStory["Project"] = projectRef;
            myStory["Owner"] = userRef;
            CreateResult createResult = restApi.Create("HierarchicalRequirement", myStory);
            myStory = restApi.GetByReference(createResult.Reference, "FormattedID", "Owner", "Project");
            Console.WriteLine(myStory["FormattedID"] + " " + myStory["Owner"]._refObjectName + " " + myStory["Project"]._refObjectName);
        }
        static void Main(string[] args)
        {
            RallyRestApi restApi = new RallyRestApi(webServiceVersion: "v2.0");
            String apiKey = "_abc123";
            restApi.Authenticate(apiKey, "https://rally1.rallydev.com", allowSSO: false);
            String workspaceRef = "/workspace/1011574887";
            String projectRef = "/project/1791269111";
            String userName = "******";

            try
            {

                Request storyRequest = new Request("hierarchicalrequirement");
                storyRequest.Workspace = workspaceRef;
                storyRequest.Project = projectRef;

                storyRequest.Fetch = new List<string>()
                {
                    "FormattedID"
                };

                storyRequest.Query = new Query("FormattedID", Query.Operator.Equals, "US2917");
                QueryResult queryResult = restApi.Query(storyRequest);
                var storyObject = queryResult.Results.First();
                String storyReference = storyObject["_ref"];

                Request userRequest = new Request("user");
                userRequest.Fetch = new List<string>()
                {
                    "UserName"
                };

                userRequest.Query = new Query("UserName", Query.Operator.Equals, userName);
                QueryResult queryUserResults = restApi.Query(userRequest);
                DynamicJsonObject user = new DynamicJsonObject();
                user = queryUserResults.Results.First();
                String userRef = user["_ref"];

                String imageFilePath = "C:\\images\\";
                String imageFileName = "rally.png";
                String fullImageFile = imageFilePath + imageFileName;
                Image myImage = Image.FromFile(fullImageFile);

                string imageBase64String = ImageToBase64(myImage, System.Drawing.Imaging.ImageFormat.Png);
                var imageNumberBytes = Convert.FromBase64String(imageBase64String).Length;
                Console.WriteLine("Image size: " + imageNumberBytes);

                DynamicJsonObject myAttachmentContent = new DynamicJsonObject();
                myAttachmentContent["Content"] = imageBase64String;
                CreateResult myAttachmentContentCreateResult = restApi.Create(workspaceRef,"AttachmentContent", myAttachmentContent);
                String myAttachmentContentRef = myAttachmentContentCreateResult.Reference;
                Console.WriteLine(myAttachmentContentRef);

                DynamicJsonObject myAttachment = new DynamicJsonObject();
                myAttachment["Artifact"] = storyReference;
                myAttachment["Content"] = myAttachmentContentRef;
                myAttachment["Name"] = "rally.png";
                myAttachment["Description"] = "Attachment Desc";
                myAttachment["ContentType"] = "image/png";
                myAttachment["Size"] = imageNumberBytes;
                myAttachment["User"] = userRef;

                CreateResult myAttachmentCreateResult = restApi.Create(workspaceRef, "Attachment", myAttachment);

                List<string> createErrors = myAttachmentContentCreateResult.Errors;
                for (int i = 0; i < createErrors.Count; i++)
                {
                    Console.WriteLine(createErrors[i]);
                }

                String myAttachmentRef = myAttachmentCreateResult.Reference;
                Console.WriteLine(myAttachmentRef);

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 12
0
        //Creates the test case
        public static void CreateTestCaseWork(string testcase)
        {
            Console.WriteLine("CreateTestCaseWork method");
            string rallyUser = System.Configuration.ConfigurationManager.AppSettings["rallyUser"];
            string rallyPassword = System.Configuration.ConfigurationManager.AppSettings["rallyPassword"];
            string workspaceRef = "https://rally1.rallydev.com/slm/webservice/1.40/workspace/144782102.js";
            //Log into rally
            RallyRestApi restApi = new RallyRestApi(rallyUser, rallyPassword, "https://rally1.rallydev.com", "1.40");

            try
            {
                //Search to see if this test case already exists, if it does, we don't want to create another one so do nothing

                Request request = new Request("testcase");
                request.Fetch = new List<string>
                {
                    "Name",
                    "ObjectID",
                };

                request.Query = new Query("Name", Query.Operator.Equals, testcase);
                QueryResult queryResult = restApi.Query(request);

                var result = queryResult.Results.First();
                var objectID = result["ObjectID"];
                Console.WriteLine("Found the test case: " + result["Name"] + " " + result["ObjectID"]);
            }

            catch (InvalidOperationException e)
            {
                //If the test case doesn't exist, then we need to create it
                DynamicJsonObject toCreate = new DynamicJsonObject();
                toCreate["Name"] = testcase;
                toCreate["Method"] = "Automated";
                CreateResult createResult = restApi.Create(workspaceRef, "testcase", toCreate);

                Console.WriteLine("Created testcase: " + testcase);

            }
        }
Esempio n. 13
0
        public static void CreateTestCaseResultWork(string testcase, string result, string notes)
        {
            string rallyUser = System.Configuration.ConfigurationManager.AppSettings["rallyUser"];
            string rallyPassword = System.Configuration.ConfigurationManager.AppSettings["rallyPassword"];
            string build = System.Configuration.ConfigurationManager.AppSettings["build"];
            string workspaceRef = "https://rally1.rallydev.com/slm/webservice/1.40/workspace/144782102.js";
            //Log into rally
            RallyRestApi restApi = new RallyRestApi(rallyUser, rallyPassword, "https://rally1.rallydev.com", "1.40");

            try
            {
                //Search to see if this test case exists

                Request request = new Request("testcase");
                request.Fetch = new List<string>
                {
                    "Name",
                    "ObjectID",
                };

                request.Query = new Query("Name", Query.Operator.Equals, testcase);
                QueryResult queryResult = restApi.Query(request);

                var result2 = queryResult.Results.First();
                var objectID = result2["ObjectID"];
                Console.WriteLine("Found the test case: " + result2["Name"] + " " + result2["ObjectID"]);

                //Create the test case result object
                DynamicJsonObject newTCResult = new DynamicJsonObject();
                newTCResult["Date"] = DateTime.UtcNow.ToString("o");
                newTCResult["TestCase"] = objectID;
                newTCResult["Notes"] = notes;
                newTCResult["Build"] = build;
                newTCResult["Verdict"] = result;

                CreateResult cr = restApi.Create(workspaceRef, "TestCaseResult", newTCResult);
                Console.WriteLine("Created test case result");
            }

            catch (InvalidOperationException e)
            {
                //If the test case doesn't exist, then we need to create it
                Console.WriteLine("Cannot find the test case: " + testcase);

            }
        }
        void buttonPostFDP_Click(object sender, EventArgs e)
        {
            UsageMetrics.IncrementUsage(UsageMetrics.UsageKind.CommitToolPostFDP);

            var t = CancellableWait.Wait("Resolve URL...", _resolveRallyUrlsTask);
            if(t.IsFaulted)
            {
                MessageBoxEx.ShowError("Resolve URL failed");
                return;
            }

            if (t.IsCanceled)
                return;

            try
            {
                buttonPostFDP.Enabled = false;

                UseWaitCursor = true;

                var restApi = new RallyRestApi(Settings.Default.RallyUser, Settings.Default.RallyPassword
                    //, proxy: new WebProxy("localhost:8888", false)
                );

                var textLines = File.ReadAllText(_fdpFilePath)
                    .Split('\n')
                    .Select(l => l.Replace("\r", ""))
                ;

                var text = string.Join("<br/>", textLines.Select(HttpUtility.HtmlEncode).Select(l => l.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")));

                var art = _issues[0].RallyArtifact;

                var toCreate = new DynamicJsonObject();
                toCreate["Text"] = text;
                toCreate["Artifact"] = art.Reference;
                var createResult = restApi.Create("ConversationPost", toCreate);

                if (!createResult.Success)
                {
                    MessageBoxEx.ShowError(string.Join("\n", createResult.Errors.DefaultIfEmpty("Unexpected")));
                    return;
                }

                if (MessageBox.Show("Discussion post added.\nOpen discussion in browser?", "Success", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    Process.Start(_issues[0].RallyUrl + "/discussion");
            }
            finally
            {
                buttonPostFDP.Enabled = true;
                UseWaitCursor = false;
            }
        }