Skip to content

Contains a DIS Macro to generate a ScriptContext class that retrieves all the ScriptParameter tags and parses them into properties.

License

Notifications You must be signed in to change notification settings

SkylineCommunications/SLC-DISMACRO-Script-Context

Repository files navigation

SLC-DISMACRO-Script-Context

Quality Gate Status

Contains a DIS Macro to generate a ScriptContext class that retrieves all the ScriptParameter tags and parses them into properties. The macro includes a check for a JSON array, because low code apps will fill in those parameters as a json array.

Note

This generated class can be used as a start. For example all the properties are generated as "string" because the ScriptParameter attribute "type" only supports string. You can then edit this generated class and change your properties to be for example an integer, or an enum, by updating the constructor.

Installation

You can do a manual install by downloading the .xml file from the releases.

  1. Go to releases
  2. Download the .xml file from the latest version
  3. Go to Visual Studio -> Extension -> DIS -> Tool Windows -> DIS Macros
  4. In the DIS Macros windows right click "My Macros"
  5. Click on "Import macros...", this will open a windows explorer dialog
  6. Go to the file you just downloaded.

How to use

  1. Open an Automation Script in visual studio.
  2. Open the Automation Script's .xml file.
  3. Open the DIS Macros tool window.
  4. Select the "Create Script Context" macro
  5. Press run at the top of the DIS Macros window.
  6. The ScriptContext class will be copied to your Clipboard.
  7. Create a new file in your Automation Script Solution, for example: "ScriptContext.cs".
  8. Paste the generated code.

Example

namespace Skyline.DataMiner.Automation
{
	using System;
	using System.Linq;

	using Newtonsoft.Json;

	using Skyline.DataMiner.Automation;
	using Skyline.DataMiner.Utils.InteractiveAutomationScript;

	public class ScriptContext
	{
		public ScriptContext(IEngine engine)
		{
			Engine = engine;

			AgentId = GetScriptParam("Agent Id").Single();
			ElementId = GetScriptParam("Element Id").Single();
			RepoName = GetScriptParam("Repo Name").Single();
			RepoOwner = GetScriptParam("Repo Owner").Single();
		}

		public IEngine Engine { get; }

		public string AgentId { get; }

		public string ElementId { get; }

		public string RepoName { get; }

		public string RepoOwner { get; }

		private static string[] GetScriptParam(string name)
		{
			var rawValue = Engine.GetScriptParam(name)?.Value;
			if (String.IsNullOrEmpty(rawValue))
			{
				throw new ArgumentException($"Script Param '{name}' cannot be left empty.");
			}

			if (IsJsonArray(rawValue))
			{
				return JsonConvert.DeserializeObject<string[]>(rawValue);
			}
			else
			{
				return new[] { rawValue };
			}
		}

		private static bool IsJsonArray(string json)
		{
			try
			{
				JArray.Parse(json);
				return true;
			}
			catch
			{
				return false;
			}
		}
	}
}

About DataMiner

DataMiner is a transformational platform that provides vendor-independent control and monitoring of devices and services. Out of the box and by design, it addresses key challenges such as security, complexity, multi-cloud, and much more. It has a pronounced open architecture and powerful capabilities enabling users to evolve easily and continuously.

The foundation of DataMiner is its powerful and versatile data acquisition and control layer. With DataMiner, there are no restrictions to what data users can access. Data sources may reside on premises, in the cloud, or in a hybrid setup.

A unique catalog of 7000+ connectors already exist. In addition, you can leverage DataMiner Development Packages to build you own connectors (also known as "protocols" or "drivers").

Note See also: About DataMiner.

About Skyline Communications

At Skyline Communications, we deal in world-class solutions that are deployed by leading companies around the globe. Check out our proven track record and see how we make our customers' lives easier by empowering them to take their operations to the next level.

About

Contains a DIS Macro to generate a ScriptContext class that retrieves all the ScriptParameter tags and parses them into properties.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages