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;
}
}
Hi Mieke,
This will depend from connector to connector, depending on how the relations were built.
In general the linking should be done in the following way: in your FunctionResource object you will have the table 'LinkerTableEntries' that will map the FunctionResource 'PK' with the primary key of the table that was selected as entry point for that Function.
From that point on, you have a key in your connector, if the DVE is exported from the same table as the FunctionResource entry point then that's you key, otherwise you will have to rely on the connector relations to find the DVE (assuming that there's a relation between the two tables).
E.g.:
From the example above, for Source 1, the function resource was exported from table 1000 with the key 75edf.. From that table 1000 now you will have to continue to follow the relations until you get to the table that exported the DVE.
Both DVE Name and the Resource ID are stored in the [Generic DVE table]; therefore you should be able to access resource Id from DVE name using data available in that table.
Alternative is to use the ResourceManagerHelper and an appropriate filter:
FilterElement<Resource> filter = ResourceExposers.DmaID.Equal(fctDve.DmaId).AND(ResourceExposers.ElementID.Equal(fctDve.ElementId));
var fctResource = RMHelper.GetResources(filter).OfType<FunctionResource>().First();