VMware {code} Community
SteveD6486
Contributor
Contributor
Jump to solution

Need c# example on how to get TaskDescription

If I have the descriptionID of a recent task, how can i retrieve the label and summary for said task?

0 Kudos
1 Solution

Accepted Solutions
BenN
Enthusiast
Enthusiast
Jump to solution

Right, I forgot the WSDL doesn't include accessor operations for properties. I use VI Java, whose proxies include accessors.

So programming down on the bare WSDL, you have to get the TaskManager reference and use RetrieveProperties. Something like:

      public void GetTaskDescriptions()
      {
          ObjectSpec oc = new ObjectSpec();
          oc.obj = _sic.taskManager;
          oc.skip = false;
          PropertySpec ps = new PropertySpec();
          ps.type = "TaskManager";
          ps.pathSet = new string[] { "description" };

          PropertyFilterSpec pfs = new PropertyFilterSpec();
          pfs.objectSet = new ObjectSpec[] { oc };
          pfs.propSet = new PropertySpec[] { ps };

          ObjectContent[http://] ocs = _service.RetrieveProperties(_sic.propertyCollector, new PropertyFilterSpec[http://] ocs = _service.RetrieveProperties(_sic.propertyCollector, new PropertyFilterSpec[] { pfs });
          TaskDescription td = (TaskDescription) ocs[0].propSet[0].val;
          ElementDescription[] eds = td.methodInfo;
          for (int i = 0; i < eds.Length; ++i)
          {
              Console.WriteLine("Key: " + eds[i].key);
              Console.WriteLine("Label: " + eds[i].label);
              Console.WriteLine("Summary: " + eds[i].summary);
          }

      }

I plugged this into the SimpleClient.cs sample in the C# part of the SDK, and it seemed to work.

Edited to remove random stuff.

That line ought to be:

ObjectContent[/] ocs = service.RetrieveProperties(sic.propertyCollector, new PropertyFilterSpec[http://] ocs = service.RetrieveProperties(sic.propertyCollector, new PropertyFilterSpec[http://]%20ocs%20=%20_service.retrieveproperties(_sic.propertycollector,%20new%20propertyfilterspec[/] );

Deity save us from smart web pages Smiley Sad

I just cannot win here, how about if I attach the snippet instead?

View solution in original post

0 Kudos
6 Replies
admin
Immortal
Immortal
Jump to solution

Hi,

You would need Managed Object for the Task in order to retrieve its details. The other way is to invoke CreateCollectorForTasks API defined on TaskManager and then filter out each task using the search criteria you wish to.

Hope that helps!

0 Kudos
BenN
Enthusiast
Enthusiast
Jump to solution

You don't need the Task managed object (in fact, he probably already has it if he has the descriptorId). The

descriptorIds are a static set, held by the TaskManager in its description.methodInfo property. You can see

the list via the MOB:

https://<your-vc-url>/mob/?moid=TaskManager&doPath=description

I'm not a c# guy, but here's what it looks like in Java:

  private static void task_description(ServiceInstance si, String descriptorId) throws Exception {
    TaskManager tm = si.getTaskManager();
    TaskDescription td = tm.getDescriptioin();
    for (ElementDescription ed : td.getMethodInfo()) {
      if (descriptorId.equals(ed.getKey())) {
        System.out.println("Label:" + ed.getLabel());
        System.out.println("Summary:" + ed.getSummary());
        break;
      }
    }
  }

0 Kudos
SteveD6486
Contributor
Contributor
Jump to solution

Thanks BenN,

But as far as I can find, there is no getDescription function in the VIM25API from the VIM_SDK.

I can get at all the info regarding the recent task including a descriptionId such as "HostSystem.acquireCimServicesTicket" but I would like to display the friendly label (and/or summary) from the description.methodInfo visible via the mob at

My challenge lies in the enumeration of the ElementDescriptions of the methodInfo. Suggestions from anybody with familiarity of this SDK would be greatly appreciated.

0 Kudos
BenN
Enthusiast
Enthusiast
Jump to solution

Right, I forgot the WSDL doesn't include accessor operations for properties. I use VI Java, whose proxies include accessors.

So programming down on the bare WSDL, you have to get the TaskManager reference and use RetrieveProperties. Something like:

      public void GetTaskDescriptions()
      {
          ObjectSpec oc = new ObjectSpec();
          oc.obj = _sic.taskManager;
          oc.skip = false;
          PropertySpec ps = new PropertySpec();
          ps.type = "TaskManager";
          ps.pathSet = new string[] { "description" };

          PropertyFilterSpec pfs = new PropertyFilterSpec();
          pfs.objectSet = new ObjectSpec[] { oc };
          pfs.propSet = new PropertySpec[] { ps };

          ObjectContent[http://] ocs = _service.RetrieveProperties(_sic.propertyCollector, new PropertyFilterSpec[http://] ocs = _service.RetrieveProperties(_sic.propertyCollector, new PropertyFilterSpec[] { pfs });
          TaskDescription td = (TaskDescription) ocs[0].propSet[0].val;
          ElementDescription[] eds = td.methodInfo;
          for (int i = 0; i < eds.Length; ++i)
          {
              Console.WriteLine("Key: " + eds[i].key);
              Console.WriteLine("Label: " + eds[i].label);
              Console.WriteLine("Summary: " + eds[i].summary);
          }

      }

I plugged this into the SimpleClient.cs sample in the C# part of the SDK, and it seemed to work.

Edited to remove random stuff.

That line ought to be:

ObjectContent[/] ocs = service.RetrieveProperties(sic.propertyCollector, new PropertyFilterSpec[http://] ocs = service.RetrieveProperties(sic.propertyCollector, new PropertyFilterSpec[http://]%20ocs%20=%20_service.retrieveproperties(_sic.propertycollector,%20new%20propertyfilterspec[/] );

Deity save us from smart web pages Smiley Sad

I just cannot win here, how about if I attach the snippet instead?

0 Kudos
SteveD6486
Contributor
Contributor
Jump to solution

Thats it! Works like a charm. Thanks a million BenN.

0 Kudos
BenN
Enthusiast
Enthusiast
Jump to solution

I should also point out that you can ask for a specific ElementDescription instead of the whole set. Sample attached as the Wiki editor seems to hate square brackets (or maybe just me).