CougarConfigSupport 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package CougarConfigSupport --version 1.0.1
NuGet\Install-Package CougarConfigSupport -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CougarConfigSupport" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CougarConfigSupport --version 1.0.1
#r "nuget: CougarConfigSupport, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CougarConfigSupport as a Cake Addin
#addin nuget:?package=CougarConfigSupport&version=1.0.1

// Install CougarConfigSupport as a Cake Tool
#tool nuget:?package=CougarConfigSupport&version=1.0.1

Cougar Config Support:

This CougarConfigSupport is a simple library for importing data from Excel files (.xlsx) and JSON files (.json) into a .NET application. It provides a list of classes and method to process data into desired part.

Installation

To use the Config Support in your .NET project, follow these steps:

Ensure you have all this library installed in your project. You can install it via NuGet using the following command:

  • Install-Package EPPlus
  • Install-Package Newtonsoft.Json
  • Install-Package CougarConfigSupport Install latest package

Usage

using CougarConfigSupport;

class Program
{
    private static OPCUAConversion yourClassInstance = new OPCUAConversion();
    private static PLCConversion yourClassInstance = new PLCConversion();

    static void Main(string[] args)
    {
        var responseTypeAccordingToMethodResponse = yourClassInstance.SomeMethod();
        //your code
    }
}

OPCUAConversion Class:

The OPCUAConversion class provides a two methods

  • FileToJSON -- Convert Excel to JSON structure string
  • JSONToFile -- Convert JSON to Excel / JSON data with respect to the JSON

FileToJSON Method

The FileToJSON method import Excel data and converting it to JSON. Here's how you can use it:

Parameters:
  • filePath: Specify the path of your Excel file location with name.
  • subProcess: An array of string with all sub-Process.
  • dataType: An array of string with all Data Types.
  • descriptionPattern: Regex patter to check the description pattern.
Request:

CSharp:

class Program
{
    static void Main(string[] args)
    {
        OPCUAConversion yourClassInstance = new OPCUAConversion();
        string filePath = "example.xlsx"; // Specify the Excel file path
        string[] subProcess = new string[] { "SubProcess1", "SubProcess2", "SubProcess3" };
        string[] dataType = new string[] { "DataType1", "DataType2", "DataType3" };
        string descriptionPattern = "YourRegexPattern";

        string response = yourClassInstance.ConvertExcelToJson(string filePath, string[] subProcess, string[] dataType, string descriptionPattern);
        // Use the response as needed in your application
    }
}
Response:

The return as a JSON formatted string.

Example Response:

Type1: With Xml string
{
  "name": "string",
  "version": "string",
  "comment": "string",
  "instanceNamespaceUri": "string",
  "opcGatewayOptions": {
    "additionalProp1": "string",
    "additionalProp2": "string",
    "additionalProp3": "string"
  },
  "opcNodeConfig": [
    {
      "description": "string",
      "version": "string",
      "nameSpaceUri": "string",
      "opcNodes": [
        {
          "name": "string",
          "type": "string",
          "description": "string",
          "template": "string",
          "childTypes": [
            "string"
          ]
        }
      ],
      "xmlConfig": "string"
    }
  ]
}

Type:2 Without Xml string
{
  "name": "string",
  "version": "string",
  "comment": "string",
  "instanceNamespaceUri": "string",
  "opcGatewayOptions": {
    "additionalProp1": "string",
    "additionalProp2": "string",
    "additionalProp3": "string"
  },
  "opcNodeConfig": [
    {
      "description": "string",
      "version": "string",
      "nameSpaceUri": "string",
      "opcNodes": [
        {
          "name": "string",
          "type": "string",
          "description": "string",
          "template": "string",
          "childTypes": [
            "string"
          ]
        }
      ]
    }
  ]
}

ConvertJsonToExcel Method:

The ConvertJsonToExcel method import JSON data and converting it to Excel / JSON files with respect to the JSON request. Here's how you can use it:

Parameters:
  • opcNode: OPCNodeConfig Type data.
  • filePath: folder path to save the extracted files.
  • columnData: It refers to Excel column header information.
  • attributes: It refers to the list of attributes used in the files.
Example:
class Program
{
    public class OPCNodeConfig
    {
        public string description { get; set; }
        public string version { get; set; }
        public string nameSpaceUri { get; set; }
        public string xmlConfig { get; set; }
        public List<OPCNode> opcNodes { get; set; }
    }
    public class OPCNode
    {
        public string name { get; set; }
        public string type { get; set; }
        public string template { get; set; }
        public string description { get; set; }
        public List<OPCNode> childTypes { get; set; }
        public List<string> ObjectLevels { get; set; } = new List<string>();
    }
    static void Main(string[] args)
    {
        // Create an instance of your class
        OPCUAConversion yourClassInstance = new OPCUAConversion();

        // Prepare sample data
        OPCNodeConfig opcNode = new OPCNodeConfig();
        // Add sample data to opcNode

        string filePath = yourFilePath.json;
        List<string> columnData = new List<string> { "ColumnData1", "ColumnData2", "ColumnData3" };
        string[] attributes = new string[] { "Attributes1", "Attributes2", "Attributes3" };

        // Call the ExcelToJSONConvertMethod
        yourClassInstance.ConvertJsonToExcel(OPCNodeConfig opcNode, string filePath, List<string> columnData, string[] attributes)
    }
}
Return Value:

No return, it will save the file as Excel or Json in the give file path location

Example Response:

Type:1 JSON contains XML type configuration
File saved as
- HeaderJson.json
- xmlFile1.json
- xmlFile2.json ...

Type:2 JSON does not contains XML in the configuration
File saved as
- HeaderJson.json
- excelFile1.xlsx
- excelFile2.xlsx ...

PLCConversion Class:

The PLCConversion class provides a two methods

  • ConvertExcelToDictionary -- Convert Excel data to Dictionary type data
  • ConvertExcelIntoJSON -- Convert Dictionary type data to Excel file
  • ConvertJSONIntoExcel -- Convert JSON to Excel file with respect to the JSON

ConvertExcelToDictionary Method

The ConvertExcelToDictionary method import Excel data and converting it Dictionary<string, List<string[]>> data. Here's how you can use it:

Parameters:
  • filePath: Specify the path of your Excel file location with name
Request:

CSharp:

class Program
{
    static void Main(string[] args)
    {
        PLCConversion yourClassInstance = new PLCConversion();
        string filePath = "example.xlsx"; // Specify the Excel file path

        Dictionary<string, List<string[]>> response = yourClassInstance.ConvertExcelToDictionary(string filePath);
        // Use the response as needed in your application
    }
}
Response:

The return as a Dictionary<string, List<string[]>> type.

Example Response:

{
    { 
        "Key1",
        new List<string[]>
        {
            new string[] { "Value1_1", "Value1_2", "Value1_3" },
            new string[] { "Value2_1", "Value2_2", "Value2_3" }
        }
    },
    { 
        "Key2",
        new List<string[]>
        {
            new string[] { "Value3_1", "Value3_2" },
            new string[] { "Value4_1", "Value4_2", "Value4_3", "Value4_4" }
        }
    },
    { 
        "Key3",
        new List<string[]>
        {
            new string[] { "Value5_1" },
            new string[] { "Value6_1", "Value6_2" }
        }
    }
}

ConvertExcelIntoJSON Method

The ConvertExcelIntoJSON method convert Dictionary<string, List<string[]>> data to indented JSON string. Here's how you can use it:

Parameters:
  • sheetDataDictionary: A dictionary where the key is a string and the value is a list of string arrays
  • sheetName: The Excel Main Sheet Name
Request:

CSharp:

class Program
{
    static void Main(string[] args)
    {
        PLCConversion yourClassInstance = new PLCConversion();

        Dictionary<string, List<string[]>> data = new Dictionary<string, List<string[]>>()
        {
            { 
                "Key1", 
                new List<string[]>
                {
                    new string[] { "Value1_1", "Value1_2", "Value1_3" },
                    new string[] { "Value2_1", "Value2_2", "Value2_3" }
                }
            },
            { 
                "Key2", 
                new List<string[]>
                {
                    new string[] { "Value3_1", "Value3_2" },
                    new string[] { "Value4_1", "Value4_2", "Value4_3", "Value4_4" }
                }
            },
            { 
                "Key3", 
                new List<string[]>
                {
                    new string[] { "Value5_1" },
                    new string[] { "Value6_1", "Value6_2" }
                }
            }
        };
        string sheetName = "PLC_Configuration_Creator"; // Specify the Excel main sheet name

        string response = yourClassInstance.ConvertExcelIntoJSON(Dictionary<string, List<string[]>> data, string sheetName);
        // Use the response as needed in your application
    }
}
Response:

The return as a JSON String type.

Example Response:

{
  "name": "string",
  "version": "string",
  "comment": "string",
  "opcToPLCMappings": [
    {
      "plcType": "AllenBradley_Legacy",
      "plcChannel": "ABLegacyCLX_GW",
      "plcModel": "None",
      "plcAddress": "string",
      "refreshRate": 0,
      "manualRead": true,
      "connectionTimeout": 0,
      "transactionTimeout": 0,
      "connectionAttempts": 0,
      "enabled": true,
      "plcSettings1": "string",
      "plcSettings2": "string",
      "nodeMapping": [
        {
          "plcTag": "string",
          "plcTagType": "Byte",
          "accessType": "Write",
          "plcTagElement": 0,
          "modifyValueBy10": false,
          "modifyValueBy": 0,
          "description": "string",
          "template": "string",
          "opcNode": "string"
        }
      ]
    }
  ]
}

ConvertJSONIntoExcel Method:

The ConvertJSONIntoExcel method import JSON data and converting it to Excel files with respect to the JSON request. Here's how you can use it:

Parameters:
  • opcNode: OPCNodeConfig Type data.
  • filePath: folder path to save the extracted files.
  • columnData: It refers to Excel column header information.
  • attributes: It refers to the list of attributes used in the files.
Example:
class Program
{
    static void Main(string[] args)
    {
        // Create an instance of your class
        PLCConversion yourClassInstance = new PLCConversion();

       Dictionary<string, List<string[]>> dicData = new Dictionary<string, List<string[]>>()
        // Add sample data to opcNode

        string filePath = yourFilePath.json; //JSON file path
        List<string> columnData = new List<string> { "ColumnData1", "ColumnData2", "ColumnData3" };

        // Call the ConvertJSONIntoExcel
        yourClassInstance.ConvertJSONIntoExcel(string filePath, PLCDictionaryDataType dicData, List<string> columnData)
    }
}
Return Value:

No return, it will save the file as Excel in the given file path location

Example Response:

File saved as
- excelFile1.xlsx
- excelFile2.xlsx ...

Contributing

Contributions to the ConfigSupport library are welcome!

License

This project is licensed under the MIT License

Author Information

SIVA SHANMUGA VADIVEL

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.9 32 6/27/2024
1.0.8 31 6/27/2024
1.0.7 29 6/27/2024
1.0.6 33 6/27/2024
1.0.5 31 6/27/2024
1.0.4 32 6/27/2024
1.0.3 34 6/27/2024
1.0.2 29 6/27/2024
1.0.1 30 6/25/2024
1.0.0 35 6/25/2024

Initial version added PLC conversion