Skip to content

Instantly share code, notes, and snippets.

@TomW-Skyline
Last active January 16, 2025 12:28
Show Gist options
  • Select an option

  • Save TomW-Skyline/8a40132e6e31af6bbb720da013d2eae1 to your computer and use it in GitHub Desktop.

Select an option

Save TomW-Skyline/8a40132e6e31af6bbb720da013d2eae1 to your computer and use it in GitHub Desktop.
GQI GetPartialTableMessage
using System;
using System.Collections.Generic;
using System.Globalization;
using Skyline.DataMiner.Analytics.GenericInterface;
using Skyline.DataMiner.Net.Messages;
public static class GqiGetPartialTable
{
public static IDictionary<string, object[]> GetTable(GQIDMS gqiDms, int dmaId, int elementId, int tableId, int keyColumnIndex = 0)
{
var message = new GetPartialTableMessage(dmaId, elementId, tableId, new[] { "forceFullTable=true" });
var response = (ParameterChangeEventMessage)gqiDms.SendMessage(message);
if (response == null)
{
throw new InvalidOperationException("Failed to retrieve table data. Response is null.");
}
var result = BuildDictionary(response, keyColumnIndex);
return result;
}
private static IDictionary<string, object[]> BuildDictionary(ParameterChangeEventMessage response, int keyColumnIndex)
{
if (response == null)
{
throw new ArgumentNullException(nameof(response));
}
var result = new Dictionary<string, object[]>();
if (response.NewValue == null || response.NewValue.ArrayValue == null)
{
return result;
}
ParameterValue[] columns = response.NewValue.ArrayValue;
if (keyColumnIndex >= columns.Length)
{
throw new ArgumentException("Invalid key column index.", nameof(keyColumnIndex));
}
// Dictionary used as a mapping from index to key.
string[] keyMap = new string[columns[keyColumnIndex].ArrayValue.Length];
int rowNumber = 0;
foreach (ParameterValue keyCell in columns[keyColumnIndex].ArrayValue)
{
string primaryKey = Convert.ToString(keyCell.CellValue.InteropValue, CultureInfo.CurrentCulture);
result[primaryKey] = new object[columns.Length];
keyMap[rowNumber] = primaryKey;
rowNumber++;
}
int columnNumber = 0;
foreach (ParameterValue column in columns)
{
rowNumber = 0;
foreach (ParameterValue cell in column.ArrayValue)
{
result[keyMap[rowNumber]][columnNumber] = cell.CellValue.ValueType == ParameterValueType.Empty ? null : cell.CellValue.InteropValue;
rowNumber++;
}
columnNumber++;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment