ConfigSupport 1.0.8

dotnet add package ConfigSupport --version 1.0.8                
NuGet\Install-Package ConfigSupport -Version 1.0.8                
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="ConfigSupport" Version="1.0.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConfigSupport --version 1.0.8                
#r "nuget: ConfigSupport, 1.0.8"                
#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 ConfigSupport as a Cake Addin
#addin nuget:?package=ConfigSupport&version=1.0.8

// Install ConfigSupport as a Cake Tool
#tool nuget:?package=ConfigSupport&version=1.0.8                

Cougar Config Support:

This ConfigSupport 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 ConfigSupport Install latest package

Usage

using ConfigSupport;

class Program
{
    private static OpcUaExcelJsonConverter yourClassInstance = new OpcUaExcelJsonConverter();
    private static PLCExcelJsonConverter yourClassInstance = new PLCExcelJsonConverter();

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

OpcUaExcelJsonConverter Class:

The OpcUaExcelJsonConverter class provides a two methods

  • ConvertExcelToJson -- Convert Excel to JSON structure string
  • ConvertJsonToExcel -- Convert JSON to Excel / Json data with respect to the JSON

ConvertExcelToJson Method

The ConvertExcelToJson 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)
    {
        OpcUaExcelJsonConverter yourClassInstance = new OpcUaExcelJsonConverter();
        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
        OpcUaExcelJsonConverter yourClassInstance = new OpcUaExcelJsonConverter();

        // 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 ...

PLCExcelJsonConverter Class:

The PLCExcelJsonConverter 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)
    {
        PLCExcelJsonConverter yourClassInstance = new PLCExcelJsonConverter();
        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)
    {
        PLCExcelJsonConverter yourClassInstance = new PLCExcelJsonConverter();

        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
        PLCExcelJsonConverter yourClassInstance = new PLCExcelJsonConverter();

       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.8 81 6/15/2024
1.0.6 71 6/11/2024
1.0.5 67 6/11/2024
1.0.4 62 6/7/2024
1.0.3 68 6/7/2024
1.0.2 72 6/7/2024
1.0.1 62 6/7/2024
1.0.0 64 6/7/2024

Added type "Description" to the JSON to File creation