Skip to content

Contains a DIS Macro to generate a class for a selected table in a Connector. It will generate a class representing a row, and one representing the table.

License

Notifications You must be signed in to change notification settings

SkylineCommunications/SLC-DISMACRO-Create-Class-From-Table

Repository files navigation

SLC-DISMACRO-Script-Context

Quality Gate Status

Contains a DIS Macro to generate a class for a selected table in a Connector. It will generate a class representing a row, and one representing the table.

Note

This generated class can be used as a start. For example if your column is a discreet you might want to have a property of type enum instead of a double. You can just edit this generated class and change the properties. Don't forget to update the constructor and the ToProtocolRow method too.

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 a Connector in visual studio.
  2. Open the Connector's .xml file.
  3. Open the DIS Macros tool window.
  4. Select the table and all of it's columns.
  5. Select the "Create Class from Table" macro.
  6. Press run at the top of the DIS Macros window.
  7. The generated code will be copied to your Clipboard.
  8. Create a new file in your pre compiled QAction, for example: "MyTable.cs".
  9. Paste the generated code.

Example

// <auto-generated>This is auto-generated code by a DIS Macro. Do not modify.</auto-generated>
namespace Skyline.Protocol.Tables
{
	using System;
	using System.Collections.Generic;
	using System.Linq;

	using Skyline.DataMiner.Net.Helper;
	using Skyline.DataMiner.Scripting;

	using SLNetMessages = Skyline.DataMiner.Net.Messages;

	public class RepositoryTagsRecord
	{
		private static readonly double DateTimeNotAvailable = -2;


		public RepositoryTagsRecord() { }

		public RepositoryTagsRecord(params object[] row)
		{
			ID = Convert.ToString(row[0]);
			Name = Convert.ToString(row[1]);
			RepositoryID = Convert.ToString(row[2]);
			CommitSHA = Convert.ToString(row[3]);
		}

		public string ID { get; set; } 

		public string Name { get; set; } 

		public string RepositoryID { get; set; } 

		public string CommitSHA { get; set; } 

		public static RepositoryTagsRecord FromPK(SLProtocol protocol, string pk)
		{
			var row = (object[])protocol.GetRow(Parameter.Repositorytags.tablePid, pk);
			if(row[0] == null)
			{
				return default;
			}

			return new RepositoryTagsRecord(row);
		}

		public object[] ToProtocolRow()
		{
			return new RepositorytagsQActionRow
			{
				Repositorytagsid_1201 = ID,
				Repositorytagsname_1202 = Name,
				Repositorytagsrepositoryid_1203 = RepositoryID,
				Repositorytagscommitsha_1204 = CommitSHA,
			};
		}

		public void SaveToProtocol(SLProtocol protocol)
		{
			if(!protocol.Exists(Parameter.Repositorytags.tablePid, ID))
			{
				protocol.AddRow(Parameter.Repositorytags.tablePid, ToProtocolRow());
			}
			else
			{
				protocol.SetRow(Parameter.Repositorytags.tablePid, ID, ToProtocolRow());
			}
		}
	}

	public class RepositoryTagsRecords
	{
		public RepositoryTagsRecords() { }

		public RepositoryTagsRecords(SLProtocol protocol)
		{
			uint[] repositoryTagsIdx = new uint[]
			{
				Parameter.Repositorytags.Idx.repositorytagsid_1201,
				Parameter.Repositorytags.Idx.repositorytagsname_1202,
				Parameter.Repositorytags.Idx.repositorytagsrepositoryid_1203,
				Parameter.Repositorytags.Idx.repositorytagscommitsha_1204,
			};
			object[] repositorytags = (object[])protocol.NotifyProtocol((int)SLNetMessages.NotifyType.NT_GET_TABLE_COLUMNS, Parameter.Repositorytags.tablePid, repositoryTagsIdx);
			object[] iD = (object[])repositorytags[0];
			object[] name = (object[])repositorytags[1];
			object[] repositoryID = (object[])repositorytags[2];
			object[] commitSHA = (object[])repositorytags[3];

			for (int i = 0; i < iD.Length; i++)
			{
				Rows.Add( new RepositoryTagsRecord(
				iD[i],
				name[i],
				repositoryID[i],
				commitSHA[i]));
			}
		}

		public List<RepositoryTagsRecord> Rows { get; set; } = new List<RepositoryTagsRecord>();

		public void SaveToProtocol(SLProtocol protocol, bool partial = false)
		{
			// Calculate the batch size, recommended 25000 cells max per fill array, divided by the number of columns.
			var batchSize = 25000 / 4;

			// If full then the first batch needs to be a SaveOption.Full.
			var first = !partial;
			if (!Rows.Any() && !partial)
			{
				protocol.ClearAllKeys(Parameter.Repositorytags.tablePid);
				return;
			}

			foreach (var batch in Rows.Select(x => x.ToProtocolRow()).Batch(batchSize))
			{
				if (first)
				{
					protocol.FillArray(Parameter.Repositorytags.tablePid, batch.ToList(), NotifyProtocol.SaveOption.Full);
				}
				else
				{
					protocol.FillArray(Parameter.Repositorytags.tablePid, batch.ToList(), NotifyProtocol.SaveOption.Partial);
				}
			}
		}
	}
}

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 class for a selected table in a Connector. It will generate a class representing a row, and one representing the table.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages