This article describes how to get started using the SystemWeaver Client API in .Net Core in both Windows and in Ubuntu (Linux).


The SystemWeaver ClientAPI Connection for .Net Core is available as a Nuget package. Be sure to select the version that is compatible with the version of SystemWeaver you are running.


Note: The .Net Core version does not support Windows network authentication in Linux.


Working in Windows

Prerequisites

  • Visual Studio or the .NET Core command-line interface (CLI) tools
  • Access to a SystemWeaver test server (swTestServer) or a SystemWeaver server in a test environment
  1. Create a new .NET Core Console Application.
  2. Copy all of the DLLs in the Core folder of SystemWeaver to somewhere in your project folder. It should contain the following files:
    • SystemWeaver.ClientAPI.dll
    • SystemWeaver.Common.dll
    • SystemWeaver.Connection.dll

  3. Add all of the above DLLs as references in your project (make sure to select them from the folder in your project and not the SystemWeaver folder).
  4. Install the NLog and K4os.Compression.LZ4 NuGet packages. As o version R31 of SystemWeaver, we used NLog 4.6.7 and K4os.Compression.LZ4 1.1.11.
  5. Try using the API! Here's a code-example:
        ```
        using System;
        using SystemWeaverAPI;

        namespace SwCoreApiTest
        {
            class Program
            {
                static readonly SWConnection _instance = SWConnection.Instance;
                static void Main(string[] args)
                {
                    _instance.LoginName = "yourloginname";
                    _instance.Password = "yourpassword";
                    _instance.ServerMachineName = "yourserver";
                    _instance.ServerPort = 1768;
                    _instance.Login();
                    var item = _instance.Broker.GetItemTypeWithSID("I");
                    Console.WriteLine($"{item.Name} has the handle {item.HandleStr}");
                }
            }
        }
        ```

The output should look like this:



Working in Ubuntu

Prerequisites

  • The .NET Core SDK is installed
  • Access to a SystemWeaver test server (swTestServer)
  1. Create a new .NET Core Console Application project by typing `dotnet new console -o SwCoreApiTest` in a terminal.
  2. Copy all of the DLLs in the Core folder of SystemWeaver to somewhere in your project folder. It should contain the following files:
    • SystemWeaver.ClientAPI.dll
    • SystemWeaver.Common.dll
    • SystemWeaver.Connection.dll
  3. Go into the project folder and open "SwCoreApiTest.csproj" in a text editor.
  4. Add references to the DLLs that you just copied into your project folder. For example, if you create a new folder in your project called `ReferencedDlls` where you put all of the DLLs, you will include that in the path to your references. Your SwCoreApiTest.csproj file should look something like this when you are done:
    ```
    <Project Sdk="Microsoft.NET.Sdk">
    	<PropertyGroup>
    		<OutputType>Exe</OutputType>
    		<TargetFramework>netcoreapp3.0</TargetFramework>
    	</PropertyGroup>
    	<ItemGroup>
    		<Reference Include="ReferencedDlls/SystemWeaver.ClientAPI.dll"/>
    		<Reference Include="ReferencedDlls/SystemWeaver.Common.dll"/>
    		<Reference Include="ReferencedDlls/SystemWeaver.Connection.dll"/>
    	</ItemGroup>
    </Project>
    ```


  5. Add the NLog and K4os.Compression.LZ4 NuGet packages to your project by opening a terminal in your project folder and typing the following commands:
            ```
            dotnet add package NLog --version 4.6.7
            dotnet add package K4os.Compression.LZ4 --version 1.1.11
    
            ```
  6. Try using the API! Here's a code example (run your program with `dotnet run`):
    ```
            using System;
            using SystemWeaverAPI;
            namespace SwCoreApiTest
            {
                class Program
                {
                    static readonly SWConnection _instance = SWConnection.Instance;
                    static void Main(string[] args)
                    {
                        _instance.LoginName = "yourloginname";
                        _instance.Password = "yourpassword";
                        _instance.ServerMachineName = "yourserver";
                        _instance.ServerPort = 1768;
                        _instance.Login();
                        var item = _instance.Broker.GetItemTypeWithSID("I");
                        Console.WriteLine($"{item.Name} has the handle {item.HandleStr}");
                    }
                }
            }
    
            ```
    The output should look like this: