Hi:
I am building a dataminer automation script using C# code.
I noticed we can get element lists from a view:
Element[] elements = engine.FindElementsInView("MyView");
Is there a way that in C# code we can get the element lists from service name? e.g.
Element[] elements = engine.FindElementsInService("MyService");
Thanks
Hi Penf,
I could not find a method in the Engine class to retrieve the list of elements from a service. However, I found a possible way to do this using the DataMiner class library
Please find below an example:
// Create a DMS object
IDms dms = engine.GetDms();// Get the service by name
IDmsService dmsService = dms.GetService("MyService");// Get the settings from the service
ServiceParamSettings[] serviceParamsSettings = dmsService.ParameterSettings.IncludedParameters;// Iterate through the settings available in the service
foreach (ServiceParamSettings serviceParamSetting in serviceParamsSettings)
{
engine.GenerateInformation("Child Element ID=" + serviceParamSetting.ElementID);
engine.GenerateInformation("Child DMA ID=" + serviceParamSetting.DataMinerID);int iElementId = Convert.ToInt32(serviceParamSetting.ElementID);
int iDmaId = Convert.ToInt32(serviceParamSetting.DataMinerID);// Create a DmsElementId object so we can find our element using IDMS class
DmsElementId elementId = new DmsElementId(iDmaId, iElementId);// With the element ID, you can use the IDmsElement interface to interact with the element
IDmsElement dmsElement = dms.GetElement(elementId);engine.GenerateInformation("Element Name=" + dmsElement.Name);
}
References:
Hi Pengf,
Below an equivalent method using only Engine class:
public static IEnumerable<Element> FindElementsInService(this Engine engine, Service service)
{
if (engine == null)
{
throw new ArgumentNullException(nameof(engine));
}if (service == null)
{
throw new ArgumentNullException(nameof(service));
}IEnumerable<Element> FindElementsInServiceIterator()
{
if (service.ServiceInfo?.ServiceParams == null)
{
yield break;
}foreach (var serviceParam in service.ServiceInfo.ServiceParams)
{
if (serviceParam.IsService)
{
continue;
}yield return engine.FindElement(serviceParam.DataMinerID, serviceParam.ElementID);
}
}return FindElementsInServiceIterator();
}