Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skylinecommunications/slc-dismacro-create-class-from-table
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.
https://github.com/skylinecommunications/slc-dismacro-create-class-from-table
dataminer dataminer-dis-macro
Last synced: about 5 hours ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/skylinecommunications/slc-dismacro-create-class-from-table
- Owner: SkylineCommunications
- License: mit
- Created: 2024-06-07T13:58:06.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-07T14:39:54.000Z (5 months ago)
- Last Synced: 2024-06-07T16:04:30.394Z (5 months ago)
- Topics: dataminer, dataminer-dis-macro
- Language: C#
- Homepage:
- Size: 651 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SLC-DISMACRO-Script-Context
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=SkylineCommunications_SLC-DISMACRO-Create-Class-From-Table&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=SkylineCommunications_SLC-DISMACRO-Create-Class-From-Table)
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](https://github.com/SkylineCommunications/SLC-DISMACRO-Create-Class-From-Table/releases)
1. Download the .xml file from the latest version
1. Go to Visual Studio -> Extension -> DIS -> Tool Windows -> DIS Macros
1. In the DIS Macros windows right click "My Macros"
1. Click on "Import macros...", this will open a windows explorer dialog
1. Go to the file you just downloaded.## How to use
1. Open a Connector in visual studio.
1. Open the Connector's .xml file.
1. Open the DIS Macros tool window.
1. Select the table and all of it's columns.
1. Select the "Create Class from Table" macro.
1. Press run at the top of the DIS Macros window.
1. The generated code will be copied to your Clipboard.
1. Create a new file in your pre compiled QAction, for example: "MyTable.cs".
1. Paste the generated code.## Example
```csharp
// This is auto-generated code by a DIS Macro. Do not modify.
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 Rows { get; set; } = new List();
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](https://aka.dataminer.services/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](https://aka.dataminer.services/about-skyline) and see how we make our customers' lives easier by empowering them to take their operations to the next level.