c# polarion problem

Description
jay0909
Posts: 4
Joined: Thu Jul 26, 2018 6:09 am

c# polarion problem

Postby jay0909 » Thu Jul 26, 2018 6:21 am

Hi,

I downloaded an example from the below link .
https://polarion.plm.automation.siemens.com/hubfs/Docs/Guides_and_Manuals/How-to-call-Polarion-from-DOT-NET.pdf.

The example name SampleWebservice. The Login and Connection works fine but I can't Getworkitems from polarion. If any suggestions please let me know.

rpn
Posts: 23
Joined: Thu Oct 26, 2017 4:08 pm

Re: c# polarion problem

Postby rpn » Mon Jul 30, 2018 10:53 am

There are different Services for different products of Polarion.
The Connection in the Sample-Code holds references to Wrappers for these services.

Code: Select all

SampleWebServiceAPI
{
      [...]
      
        //  WebServices
        public BuilderWebServiceClient          Builder         { get { return Factory.WebServices[WebServiseFactory.Builder]; } }
        public ProjectWebServiceClient          Project         { get { return Factory.WebServices[WebServiseFactory.Project]; } }
        public PlanningWebServiceClient         Planning        { get { return Factory.WebServices[WebServiseFactory.Planning]; } }
        public SecurityWebServiceClient         Security        { get { return Factory.WebServices[WebServiseFactory.Security]; } }
        public SessionWebServiceClient          Session         { get { return Factory.WebServices[WebServiseFactory.Session]; } }
        public TestManagementWebServiceClient   TestManagement  { get { return Factory.WebServices[WebServiseFactory.TestManagement]; } }
        public TrackerWebServiceClient          Tracker         { get { return Factory.WebServices[WebServiseFactory.Tracker]; } }
[...]
}


Try calling the methods of those wrappers (Tracker, Builder, etc.), once you are connected.

Code: Select all

var workItem = myConnection.Tracker.getWorkItemByUri(workItemUri);


EDIT:
You can find documentation on the services here:
https://almdemo.polarion.com/polarion/s ... rvice.html
No native speaker, sorry for my bad English.

jay0909
Posts: 4
Joined: Thu Jul 26, 2018 6:09 am

Re: c# polarion problem

Postby jay0909 » Mon Jul 30, 2018 11:59 am

Hi,

Thanks for the reply. Do you have the working code? If any please share it. I use only trackerservice for getting the data. I still cannot understand why trackerservice is not working.

rpn
Posts: 23
Joined: Thu Oct 26, 2017 4:08 pm

Re: c# polarion problem

Postby rpn » Tue Jul 31, 2018 8:26 am

Sorry, I am not allowed to share the code I am working on.

The code linked in the whitepaper is working for me and there is not much more to it, than retireve ProjectSpaces, Projectes (, Modules) and then query the workitems with the uris from those.
Whitepaper: https://polarion.plm.automation.siemens.com/hubfs/Docs/Guides_and_Manuals/How-to-call-Polarion-from-DOT-NET.pdf

Are you able to see the WorkItems you want to retrieve via the WebService in the Web-Client? Maybe it is a permission issue - if the user you make the connection with does not have the right to read the WorkItems, it just returns null or an empty set, IIRC.
No native speaker, sorry for my bad English.

jay0909
Posts: 4
Joined: Thu Jul 26, 2018 6:09 am

Re: c# polarion problem

Postby jay0909 » Tue Jul 31, 2018 9:44 am

Hi,

Thanks for the reply.I have attached the main program. Can you please check and let me know where i'm making mistake. When i use trackerservice to get the work item its always returning null. I can login and connect successfully.

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TrackerService = net.seabay.polarion.Tracker;
using TestManagementService= net.seabay.polarion.TestManagement;
using Bild=net.seabay.polarion.Builder;
using net.seabay.polarion.Project;
using net.seabay.polarion;

namespace SampleWebServiceAPI
{
    class SampleWebServiceAPI
    {
        private static Connection con { get; set;}

        static void Main(string[] args)
        {
            con = new Connection("https://", "almdemo.polarion.com");

            con.login("seabay", "seabay");

            if (con.IsLoggedIn == true)
            {
                //  get the parameter from the call
                if (args.Length < 2)
                {
                    Console.WriteLine("\r\nPlease provide one of the parameter: [ -r query | -c workitemid | -t testrunid ]\r\n");
                    return;
                }

                if (args[0] == "-r")
                {
                    GetWorkItems(args[1]);
                }

                if (args[0] == "-c")
                {
                    ChangeWorkItems(args[1]);
                }

                if (args[0] == "-t")
                {
                    GetTestResults(args[1]);
                }
            }
        }
        static void GetWorkItems(string query)
        {
            //  get the workitems of the query and order them by id
            //  The call queryWorkItems requires to specifiy which fields to be retrieved
            //  Custom fields are prefixed with "customFields."

            //TrackerService.WorkItem[] wiList = con.Tracker.queryWorkItems(query, "id", new string[] { "id", "title", "customFields.targetVersion" });
            TrackerService.WorkItem WILIT = con.Tracker.getWorkItemByUri("subterra:data-service:objects:/default/DP-471${WorkItem}Task");

            int index = 0;
           /* foreach (TrackerService.WorkItem wi in wiList)
            {
                StringBuilder cfValues = new StringBuilder();
                if (wi.customFields != null)
                {
                    foreach (TrackerService.EnumOptionId enumId in (TrackerService.EnumOptionId[])wi.customFields[0].value)
                    {
                        if (cfValues.Length != 0)
                        {
                            cfValues.Append(", ");
                        }

                        cfValues.Append(enumId.id);
                    }
                }

                Console.WriteLine("({0}) = {1} - {2} - {3}", index++, wi.id, wi.title, cfValues.ToString());
            }*/
   
            Console.ReadKey();
        }
        static void ChangeWorkItems(string workItemType)
        {
            //  create a new WorkItem instance
            TrackerService.WorkItem newWorkItem = new TrackerService.WorkItem();

            //  set project
            newWorkItem.project = new TrackerService.Project();
            newWorkItem.project.uri = con.Project.getProject("drivepilot").uri;

            //  set the workitem type
            TrackerService.EnumOptionId enumId = new TrackerService.EnumOptionId();
            enumId.id = workItemType;
            newWorkItem.type = enumId;

            //  set the title
            newWorkItem.title = "Created By a WebService API-Call";

            //  create the workitem
            string newWorkItemUri= con.Tracker.createWorkItem(newWorkItem);

            //  set the custom field targetVersion
            TrackerService.CustomField cf = new TrackerService.CustomField();
            cf.key = "targetVersion";
            cf.parentItemURI = newWorkItemUri;

            //  set the value, it is of type EnumOptionId[]
            enumId = new TrackerService.EnumOptionId();
            enumId.id= "Version_1_0";
            cf.value= new TrackerService.EnumOptionId[] {enumId};
            con.Tracker.setCustomField(cf);

            //  change the workitem status
            foreach (TrackerService.WorkflowAction workflowAction in con.Tracker.getAvailableActions(newWorkItemUri))
            {
                if (workflowAction.nativeActionId == "reviewed")
                {
                    con.Tracker.performWorkflowAction(newWorkItemUri, workflowAction.actionId);
                    break;
                }
            }

        }
        static void GetTestResults(string testRunId)
        {
            //  get the test results of a given Testrun

            TestManagementService.TestRun testRun= con.TestManagement.getTestRunById("drivepilot", testRunId);

            foreach (TestManagementService.TestRecord testRecord in testRun.records)
            {
                if (testRecord.result.id == "failed")
                {
                    TrackerService.WorkItem testcase = con.Tracker.getWorkItemByUri(testRecord.testCaseURI);
                    TrackerService.WorkItem defect = con.Tracker.getWorkItemByUri(testRecord.defectURI);
                    Console.WriteLine("failed Testcase: {0} - {1}, defect: {2} - {3}",
                                        testcase.id, testcase.title, defect.id, defect.title);
                }
            }

            Console.ReadKey();
        }
    }
}

rpn
Posts: 23
Joined: Thu Oct 26, 2017 4:08 pm

Re: c# polarion problem

Postby rpn » Wed Aug 01, 2018 1:23 pm

I don't have the time to debug your code, but on the first look the

Code: Select all

static void GetWorkItems(string query)

Method you posted is not doing anything. It queries for a single WorkItem with a Hardcoded URI, than declares and initializes an integer called index and waits for a keypress. After that, it returns to Main and Main exits.

Where do you get the uri "subterra:data-service:objects:/default/DP-471${WorkItem}Task" from, and (Iam guessing, that you just want to see Data of Variable WILIT in the debugger) are you sure, a item with that uri resides on the server you are connected to?
If you are connecting to the almdemo-server, maybe it is better to revert your changes and supply the MainFunction with the Query "id:DP\-471" - thats giving you exactly that item - than you can check its uri - I guess the hardcoded URI in your code is errenous.

EDIT:
You can get those queries by entering Table-View in Polarion and construct the query with the supplied tooling, than you can convert that query to text and use it in your program.
No native speaker, sorry for my bad English.


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 10 guests