In an automation script I have the DVE Element available via engine.FindElement method.
It is also possible to know the parent element that generated the DVE:
elementToConfigure.RawInfo.DveParentDmaId
elementToConfigure.RawInfo.DveParentElementId
But how can I know the Primary Key of the row that generated a DVE element?
I need this value so I can map it to a Function Resource (this contains the parent dma and element Id and the primary key)
I could find the PK of the (regular connector) DVE by creating the below helper.
Usage:
var dmaId = 1000;
var elementId = 1;
Element myRandomElement = engine.FindElement(dmaId, elementId);
var elementMapper = new ElementMapper(engine, myRandomElement);if (elementMapper.IsDve)
{
engine.GenerateInformation("The Name of the Element that created the Connector DVE:" + elementMapper.ParentElement.ElementName);
engine.GenerateInformation("The Name of the Element representing the Connector DVE:" + elementMapper.ChildElement.ElementName);
engine.GenerateInformation("The Primary Key that generated the Connector DVE:" + elementMapper.ExportPrimaryKey);
}
Helper:
using System;
using System.Linq;
using Skyline.DataMiner.Automation;public class ElementMapper
{
public ElementMapper(Engine engine, Element selectedElement)
{
ParentElement = selectedElement;
ChildElement = null;
// check if selected element is DVE?
if (selectedElement.RawInfo.IsDynamicElement)
{
IsDve = true;
ChildElement = selectedElement;
ParentElement = engine.FindElement(selectedElement.RawInfo.DveParentDmaId, selectedElement.RawInfo.DveParentElementId);
ExportPrimaryKey = GetChildReferenceKey(ParentElement, ChildElement);
}
}public bool IsDve { get; private set; }
public string ExportPrimaryKey { get; private set; }
public Element ParentElement { get; private set; }
public Element ChildElement { get; private set; }
private static string GetChildReferenceKey(Element parentElement, Element childElement)
{
int exportTablePid = 0;
int exportElementColumnPid = 0;foreach (var exportedTable in parentElement.Protocol.ExportedTables)
{
if (exportedTable.ExportedProtocolName == childElement.ProtocolName)
{
exportTablePid = exportedTable.ExportedTableID;// Get the column that contains ;element option
exportElementColumnPid = GetElementColumnPid(parentElement, exportTablePid);
break;
}
}foreach (var pk in parentElement.GetTablePrimaryKeys(exportTablePid))
{
var dveElementInfo = Convert.ToString(parentElement.GetParameterByPrimaryKey(exportElementColumnPid, pk));
if (dveElementInfo == string.Format("{0}/{1}", childElement.DmaId, childElement.ElementId))
{
return pk;
}
}return string.Empty;
}private static int GetElementColumnPid(Element parentElement, int exportTablePid)
{
var tableParameter = parentElement.Protocol.Parameters.FirstOrDefault(x => x.ID == exportTablePid);
if (tableParameter != null)
{
foreach (var columnDefs in tableParameter.TableColumnDefinitions)
{
if (columnDefs.Options.Contains("element"))
{
return columnDefs.ParameterID;
}
}
}return 0;
}
}