Get object children - Metasys - LIT-12013522 - Software Application - Basic Services client library for .NET (and COM) - Metasys API - 4.2

Metasys REST Client for .NET and COM Developer Guide

Brand
Metasys
Product name
Basic Services client library for .NET (and COM)
Metasys API
Document type
API Reference Guide
Document number
LIT-12013522
Version
4.2
Revision date
2021-04-07
Language
English

To get child devices of an object, or objects of an object, use the GetObjects method. The method takes the GUID of the parent object, and the number of levels to retrieve. The default number of levels is one, or just the immediate children of the object.

Note: If you have a large number of objects on your server, this method can take a long time to complete. To mitigate the time to complete this process, cache the results on your client machine.
Table 1. Get object children .NET signature
Library method name GetObjects
Description Get child devices of an object.
Method signature IEnumerable<MetasysObject> GetObjects(Guid id, int levels = 1);
Method input parameters
  • id: object GUID that the function uses to retrieve the child devices.
  • Optional

    levels: number of levels considered to retrieve the child devices.

Return value A collection of MetasysObject.

The following .NET C# code is an example of a successful Metasys object with object children response:

Guid parentId = client.GetObjectIdentifier("Win2016-VM2:vNAE2343996/Field Bus MSTP1.VAV-08");
// Get direct children (1 level)
List<MetasysObject> directChildren = client.GetObjects(parentId).ToList();
MetasysObject lastChild = directChildren.LastOrDefault();
Console.WriteLine(lastChild);
/*                    
  {
    "ItemReference": "Win2016-VM2:vNAE2343996/Field Bus MSTP1.VAV-08.ZN-T",
    "Id": "d5d96cd3-db4a-52e0-affd-8bc3393c30ec",
    "Name": "ZN-T",
    "Description": null,
    "Type": null,
    "TypeUrl": "https://win2016-vm2/api/v2/enumSets/508/members/601",
    "Category": null,
    "Children": [],
    "ChildrenCount": 0
  }
*/
Guid twoLevelsParentId = client.GetObjectIdentifier("Win2016-VM2:vNAE2343996/WeatherForecast");
// Get descendant for 2 levels (it could take long time, depending on the number of objects)
List<MetasysObject> level2Descendants = client.GetObjects(twoLevelsParentId, 2).ToList();
MetasysObject level1Parent = level2Descendants.SingleOrDefault(s => s.Name == "Time");
Console.WriteLine(level1Parent);
/*                      
  {
    "ItemReference": "Win2016-VM2:vNAE2343996/WeatherForecast.Time",
    "Id": "22bb952e-7557-5de9-b7e5-dce39e21addd",
    "Name": "Time",
    "Description": null,
    "Type": null,
    "TypeUrl": "https://win2016-vm2/api/v2/enumSets/508/members/176",
    "Category": null,
    "Children": [
    {
      "ItemReference": "Win2016-VM2:vNAE2343996/WeatherForecast.Time.Day",
      "Id": "5886a93f-9260-553c-995e-6a65374de85d",
      "Name": "Day",
      "Description": null,
      "Type": null,
      "TypeUrl": "https://win2016-vm2/api/v2/enumSets/508/members/165",
      "Category": null,
      "Children": [],
      "ChildrenCount": 0
    },
    {
      "ItemReference": "Win2016-VM2:vNAE2343996/WeatherForecast.Time.Hour",
      "Id": "6a50d3af-d0a2-537c-a2f7-9c1b5f271cc5",
      "Name": "Hour",
      "Description": null,
      "Type": null,
      "TypeUrl": "https://win2016-vm2/api/v2/enumSets/508/members/165",
      "Category": null,
      "Children": [],
      "ChildrenCount": 0
    },
    {
      "ItemReference": "Win2016-VM2:vNAE2343996/WeatherForecast.Time.Minute",
      "Id": "19a53f38-2fd7-5ac3-a12c-f3b9704ac194",
      "Name": "Minute",
      "Description": null,
      "Type": null,
      "TypeUrl": "https://win2016-vm2/api/v2/enumSets/508/members/165",
      "Category": null,
      "Children": [],
      "ChildrenCount": 0
    },
    {
      "ItemReference": "Win2016-VM2:vNAE2343996/WeatherForecast.Time.Year",
      "Id": "74dfc214-22c1-57a7-ace5-606636d0049c",
      "Name": "Year",
      "Description": null,
      "Type": null,
      "TypeUrl": "https://win2016-vm2/api/v2/enumSets/508/members/165",
      "Category": null,
      "Children": [],
      "ChildrenCount": 0
    }
    ],
    "ChildrenCount": 4
  }
*/