Table of Contents

Linking rows to DataMiner objects

GQI allows query rows to be linked to certain DataMiner objects. This is achieved via metadata that informs the Dashboards and Low-Code Apps of what a row represents. The metadata can then be used to feed these DataMiner objects from one component to another.

From DataMiner 10.4.0/10.4.1 onwards, you can also add this metadata to the rows of your ad hoc data source, just like the rows from built-in data sources.

To link a GQI row to a DataMiner object, add a reference to the object in the Metadata property of the row.

Example

The following ad hoc data source exposes a table of elements contained within a specific view.

using Skyline.DataMiner.Analytics.GenericInterface;
using Skyline.DataMiner.Net;
using Skyline.DataMiner.Net.Messages;
using System.Collections.Generic;
using System.Linq;

[GQIMetaData(Name = "Get elements in view")]
public sealed class ViewElementsDataSource : IGQIDataSource, IGQIOnInit, IGQIInputArguments
{
    private readonly GQIIntArgument _viewArgument = new GQIIntArgument("View id") { IsRequired = true };
    private readonly GQIStringColumn _nameColumn = new GQIStringColumn("Name");

    private GQIDMS _dms;
    private int _viewID;

    public OnInitOutputArgs OnInit(OnInitInputArgs args)
    {
        _dms = args.DMS;
        return default;
    }

    public GQIArgument[] GetInputArguments() => new[] { _viewArgument };

    public OnArgumentsProcessedOutputArgs OnArgumentsProcessed(OnArgumentsProcessedInputArgs args)
    {
        _viewID = args.GetArgumentValue(_viewArgument);
        return default;
    }

    public GQIColumn[] GetColumns() => new[] { _nameColumn };

    public GQIPage GetNextPage(GetNextPageInputArgs args)
    {
        var rows = GetElements()
            .Select(CreateElementRow)
            .ToArray();
        return new GQIPage(rows);
    }

    private IEnumerable<LiteElementInfoEvent> GetElements()
    {
        var requestMsg = new GetLiteElementInfo { ViewID = _viewID };
        var responseMsg = _dms.SendMessages(requestMsg);
        return responseMsg.OfType<LiteElementInfoEvent>();
    }

    private GQIRow CreateElementRow(LiteElementInfoEvent element)
    {
        // Create a new row with:

        // 1. A unique key
        var elementID = new ElementID(element.DataMinerID, element.ElementID);
        var key = elementID.GetKey();

        // 2. Cells containing element data
        var nameCell = new GQICell { Value = element.Name };
        var cells = new[] { nameCell };

        // 3. Metadata to link the row to the element
        var elementMetadata = new ObjectRefMetadata { Object = elementID };
        var rowMetadata = new GenIfRowMetadata(new[] { elementMetadata });

        return new GQIRow(key, cells) { Metadata = rowMetadata };
    }
}

See also