Stateless Programming
The stateless way of working with the .NET API is a more simple approach to communicate with the Core. The intention of it is to provide a lightweight library for applications that live only for a short period of time and do not deal with model events.
Example: SimplestSLI – Synchronously read a value using the StatelessInterface singleton
using inmation.api;
using System;
namespace APISamples.SimplestSLI
{
class Program
{
static void Main()
{
TcpConfig tcpcfg = new TcpConfig() { HostNameOrIp = "CoreVM", Port = 6512 };
StatelessInterface sli = new StatelessInterface(tcpcfg);
string path = "/System/CoreVM/Examples/DemoData/ProcessValues/FC4711";
ReadItem readItem = new ReadItem(path);
Result result = sli.ReadValue(new SecurityCredentials() { ProfileName = "so", Password = "<password>" }, readItem);
Console.WriteLine(readItem.Timestamp.ToString() + " : " + readItem.Value.ToString());
Console.WriteLine("... hit ENTER to end application.");
Console.ReadLine();
}
}
}
Note how the StatelessInterface singleton is instantiated with the TCP configuration, and then used to carry out the read. Multiple calls can be made from the singleton if required, before the call of the Disconnect() method. This is typically done when the application is going out of scope, and is the proper way to tell the Core to free the TCP resources used for this connection. The calling syntax of the functions available in the stateless singleton matches the stateful ones.Refer to the examples in Stateful Programming section where applicable.