Hi,
I'm looking at automation script solution to move elements from one view to another, run periodically. I am looking to do this via C# code. Is there any reference I could use to implement this?
Hi Sean,
Following code should help you
using Skyline.DataMiner.Library.Automation;
using Skyline.DataMiner.Library.Common;private void MoveElements(Engine engine)
{
var dms = engine.GetDms();
var currentView = dms.GetView("Current View");
var newView = dms.GetView("New View");foreach (var element in currentView.Elements)
{
element.Views.Clear();
element.Views.Add(newView);element.Update();
}
}
Update 1
private void MoveElements(Engine engine)
{
var dms = engine.GetDms();var protocol = dms.GetProtocol("protocol name", "protocol version");
var elements = dms.GetElements().Where(x => x.Protocol == protocol);var newView = dms.GetView("New View");
foreach (var element in elements)
{
element.Views.Clear();
element.Views.Add(newView);element.Update();
}
}
I actually need to only move elements from a specific protocol. So I was doing engine.FindElementsByProtocol() function to get a list of elements. Is there a method to set/remove views from Element class?
If I follow the code below, is there a way to filter elements by protocol?
Lastly, I get an error when I add using Skyline.DataMiner.Library.Common. I am using Skyline.DataMiner.Automation (DM version 10.1).
Unfortunately the Engine class doesn’t have methods to change the view of an element and the Class Library doesn’t have a method to get the elements by protocol.
I’ve added an additional code sample in my original post in which I’m requesting all the elements of the system and filter on the protocol afterwards.
Would it be possible to mention which error you have so that I can look this up for you?
First error message:
Engine does not contain a definition for ‘GetDms’ and no accessible extension method ‘GetDms’ accepting a first argument of type ‘Engine’ could be found (are you missing a using directive or an assembly reference?)
This is likely related to the fact that I can’t use Skyline.DataMiner.Library.Automation, I can only use Skyline.DataMiner.Automation
Second error message:
foreach statement cannot operate on variables of type ‘?’ because ‘?’ does not contain a public instance definition for ‘GetEnumerator’
This seems related to the first message, doesn’t make much sense on its own.
Code:
using System;
using System.IO;
using Skyline.DataMiner.Automation;
using System.Collections.Generic;
using System.Text;
using System.Linq;
public class Script
{
private void MoveElement(Engine engine)
{
var dms = engine.GetDms();
var protocol = dms.GetProtocol(“Newtec Dialog Time Series Database – Network”, “Production”);
var elements = dms.GetElements().Where(x => x.Protocol == protocol);
var newView = dms.GetView(“Newtec-PROD-NWT”);
foreach (var element in elements)
{
element.Views.Clear();
element.Views.Add(newView);
element.Update();
}
}
}
Hi Sean
Class Library is code that is supplied via DIS. Are you developing this script in Visual Studio with DIS? Otherwise the usage of Class Library is not possible.
If you are developing this with DIS, make sure to have the Class Library feature enabled in the DIS Settings (https://docs.dataminer.services/develop/TOOLS/DIS/Reference/DIS_settings.html#class-library).
I generated the script via DIS but once exported to DMA, I am seeing the same validation error messages and when I run it:
The following was returned from the script:
(after retries) (Code: 0x80040251) Skyline.DataMiner.Net.Exceptions.DataMinerException: No Assembly found for cookie 2
(6,25): error CS0234: The type or namespace name ‘Library’ does not exist in the namespace ‘Skyline.DataMiner’ (are you missing an assembly reference?)
(7,25): error CS0234: The type or namespace name ‘Library’ does not exist in the namespace ‘Skyline.DataMiner’ (are you missing an assembly reference?)
(13,26): error CS1061: ‘Engine’ does not contain a definition for ‘GetDms’ and no accessible extension method ‘GetDms’ accepting a first argument of type ‘Engine’ could be found (are you missing a using directive or an assembly reference?)
(20,33): error CS1579: foreach statement cannot operate on variables of type ‘?’ because ‘?’ does not contain a public instance definition for ‘GetEnumerator’
at CManagedAutomation.RunWrapped(CManagedAutomation* , Int32 iCookie, IUnknown* pIAutomation, tagVARIANT* varParameters, tagVARIANT* pvarReturn, String scriptName)
at CManagedAutomation.Run(CManagedAutomation* , Int32 iCookie, Char* bstrScriptName, IUnknown* pIAutomation, tagVARIANT* varParameters, tagVARIANT* varEntryPoint, tagVARIANT* pvarReturn)
As this question has been inactive for a long time, we will now close it. If you want further assistance, feel free to post a new question or contact techsupport@skyline.be.