From 0bc748023cb77f78f3f425bbd84ce52e4a4d0ba8 Mon Sep 17 00:00:00 2001 From: wei-mclarenapplied <71443454+wei-mclarenapplied@users.noreply.github.com> Date: Fri, 17 Nov 2023 10:14:49 +0000 Subject: [PATCH 1/3] Restore floating version of Sqlrace so sample code always uses latest version (#27) * Restore floating version of Sqlrace so sample code always uses latest available * increase restore verbosity * try normal * use * --------- Co-authored-by: Wei Li --- .github/workflows/pr.yml | 2 +- .../MAT.SQLRace.BaseExampleLoadSSN.csproj | 2 +- .../MAT.SQLRace.CreateSessionWithMultipleParameters.csproj | 2 +- .../MAT.SQLRace.FileLoaderSample.csproj | 2 +- .../MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj | 2 +- MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj | 2 +- .../MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj | 2 +- .../MAT.SqlRace.Functions.HelloDotNet.csproj | 2 +- .../MAT.SqlRace.StandaloneRecorder.csproj | 2 +- .../MESL.SqlRace.Examples.Sessions.CSharp.csproj | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ebc02dc..a7243f3 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -42,7 +42,7 @@ jobs: dotnet-version: '6.0.x' - name: Install dependencies - run: dotnet restore + run: dotnet restore --verbosity normal - name: Build run: dotnet build --configuration Release --no-restore diff --git a/MAT.SQLRace.BaseExampleLoadSSN/MAT.SQLRace.BaseExampleLoadSSN.csproj b/MAT.SQLRace.BaseExampleLoadSSN/MAT.SQLRace.BaseExampleLoadSSN.csproj index 32cd9f3..d36c3cd 100644 --- a/MAT.SQLRace.BaseExampleLoadSSN/MAT.SQLRace.BaseExampleLoadSSN.csproj +++ b/MAT.SQLRace.BaseExampleLoadSSN/MAT.SQLRace.BaseExampleLoadSSN.csproj @@ -28,7 +28,7 @@ - + diff --git a/MAT.SQLRace.CreateSessionWithMultipleParameters/MAT.SQLRace.CreateSessionWithMultipleParameters.csproj b/MAT.SQLRace.CreateSessionWithMultipleParameters/MAT.SQLRace.CreateSessionWithMultipleParameters.csproj index 6250da6..7100c92 100644 --- a/MAT.SQLRace.CreateSessionWithMultipleParameters/MAT.SQLRace.CreateSessionWithMultipleParameters.csproj +++ b/MAT.SQLRace.CreateSessionWithMultipleParameters/MAT.SQLRace.CreateSessionWithMultipleParameters.csproj @@ -21,7 +21,7 @@ - + diff --git a/MAT.SQLRace.FileLoaderSample/MAT.SQLRace.FileLoaderSample.csproj b/MAT.SQLRace.FileLoaderSample/MAT.SQLRace.FileLoaderSample.csproj index 359f5a1..6bea7b8 100644 --- a/MAT.SQLRace.FileLoaderSample/MAT.SQLRace.FileLoaderSample.csproj +++ b/MAT.SQLRace.FileLoaderSample/MAT.SQLRace.FileLoaderSample.csproj @@ -18,7 +18,7 @@ - + diff --git a/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj b/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj index 7194048..090a31a 100644 --- a/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj +++ b/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj @@ -19,7 +19,7 @@ - + diff --git a/MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj b/MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj index 28c4b47..f9fd231 100644 --- a/MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj +++ b/MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj @@ -33,7 +33,7 @@ - + diff --git a/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj b/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj index 7194048..090a31a 100644 --- a/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj +++ b/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj @@ -19,7 +19,7 @@ - + diff --git a/MAT.SqlRace.Functions.HelloDotNet/MAT.SqlRace.Functions.HelloDotNet.csproj b/MAT.SqlRace.Functions.HelloDotNet/MAT.SqlRace.Functions.HelloDotNet.csproj index 86b345a..93e494d 100644 --- a/MAT.SqlRace.Functions.HelloDotNet/MAT.SqlRace.Functions.HelloDotNet.csproj +++ b/MAT.SqlRace.Functions.HelloDotNet/MAT.SqlRace.Functions.HelloDotNet.csproj @@ -21,7 +21,7 @@ - + diff --git a/MAT.SqlRace.StandaloneRecorder/MAT.SqlRace.StandaloneRecorder.csproj b/MAT.SqlRace.StandaloneRecorder/MAT.SqlRace.StandaloneRecorder.csproj index 7194048..090a31a 100644 --- a/MAT.SqlRace.StandaloneRecorder/MAT.SqlRace.StandaloneRecorder.csproj +++ b/MAT.SqlRace.StandaloneRecorder/MAT.SqlRace.StandaloneRecorder.csproj @@ -19,7 +19,7 @@ - + diff --git a/MESL.SqlRace.Examples.Sessions.CSharp/MESL.SqlRace.Examples.Sessions.CSharp.csproj b/MESL.SqlRace.Examples.Sessions.CSharp/MESL.SqlRace.Examples.Sessions.CSharp.csproj index 02ebdc7..acf08e1 100644 --- a/MESL.SqlRace.Examples.Sessions.CSharp/MESL.SqlRace.Examples.Sessions.CSharp.csproj +++ b/MESL.SqlRace.Examples.Sessions.CSharp/MESL.SqlRace.Examples.Sessions.CSharp.csproj @@ -32,7 +32,7 @@ - + From 8b7de3bbbf81d5cb9d9be1685e9e980a8ff6b9c8 Mon Sep 17 00:00:00 2001 From: salman-mclarenapplied <140796235+salman-mclarenapplied@users.noreply.github.com> Date: Thu, 23 Nov 2023 17:07:55 +0000 Subject: [PATCH 2/3] updated support files (#28) Co-authored-by: Salman Alfarisyi --- .../MAT.SQLRace.BaseExampleLoadSSN.csproj | 2 +- MAT.SQLRace.BaseExampleLoadSSN/Program.cs | 4 ++-- .../MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj | 2 +- MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj | 2 +- ...AT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj | 2 +- .../MAT.SqlRace.StandaloneRecorder.csproj | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/MAT.SQLRace.BaseExampleLoadSSN/MAT.SQLRace.BaseExampleLoadSSN.csproj b/MAT.SQLRace.BaseExampleLoadSSN/MAT.SQLRace.BaseExampleLoadSSN.csproj index d36c3cd..b9acadf 100644 --- a/MAT.SQLRace.BaseExampleLoadSSN/MAT.SQLRace.BaseExampleLoadSSN.csproj +++ b/MAT.SQLRace.BaseExampleLoadSSN/MAT.SQLRace.BaseExampleLoadSSN.csproj @@ -21,7 +21,7 @@ - + diff --git a/MAT.SQLRace.BaseExampleLoadSSN/Program.cs b/MAT.SQLRace.BaseExampleLoadSSN/Program.cs index e031f28..f3892e4 100644 --- a/MAT.SQLRace.BaseExampleLoadSSN/Program.cs +++ b/MAT.SQLRace.BaseExampleLoadSSN/Program.cs @@ -12,14 +12,14 @@ class Program /// In order to be able to use this example follow these instructions; /// https://github.com/mat-docs/packages /// - /// Whenever you are setting up your project you should use .NETFramework 4.8. + /// Whenever you are setting up your project you should use .NETCore 6.0. /// /// Once registered in Visual Studio, you need to install MESL.SQLRace.API package from NuGet making sure that you have selected the McLaren Applied Github packages in the top /// right corner (defaults to nuget.org, where if you search for the package it would not show). /// Apart from this NuGet package, if you plan to use SSN files you need to follow these steps too: /// - Install MAT.ATLAS.SupportFiles from NuGet directory making sure that you have selected on the top right corner MA repository /// - Setup the build config to build in x64 based CPUs. This is required for SSNs to be loaded. - /// Once this package is installed, you would only need to pay attenion to the TODOs written in the code. + /// Once this package is installed, you would only need to pay attention to the TODOs written in the code. /// /// Find the documentation for the API in the link below /// https://mat-docs.github.io/Atlas.SQLRaceAPI.Documentation/api/index.html diff --git a/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj b/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj index 090a31a..8470d67 100644 --- a/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj +++ b/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters/MAT.SQLRace.HelloCreateSSN2FromZeroWithParameters.csproj @@ -12,7 +12,7 @@ - + diff --git a/MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj b/MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj index f9fd231..76c93e1 100644 --- a/MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj +++ b/MAT.SQLRace.HelloData/MAT.SQLRace.HelloData.csproj @@ -26,7 +26,7 @@ - + diff --git a/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj b/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj index 090a31a..8470d67 100644 --- a/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj +++ b/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters/MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj @@ -12,7 +12,7 @@ - + diff --git a/MAT.SqlRace.StandaloneRecorder/MAT.SqlRace.StandaloneRecorder.csproj b/MAT.SqlRace.StandaloneRecorder/MAT.SqlRace.StandaloneRecorder.csproj index 090a31a..8470d67 100644 --- a/MAT.SqlRace.StandaloneRecorder/MAT.SqlRace.StandaloneRecorder.csproj +++ b/MAT.SqlRace.StandaloneRecorder/MAT.SqlRace.StandaloneRecorder.csproj @@ -12,7 +12,7 @@ - + From c10b22704d1780d69e0cd0fc00710bd0a8111d47 Mon Sep 17 00:00:00 2001 From: Owen Foo <74505400+owentmfoo@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:02:20 +0000 Subject: [PATCH 3/3] Server listener example (#29) * New ServerListener Example --- MAT.OCS.SQLRace.Examples.sln | 19 +- MAT.SqlRace.ServerListener/App.config | 62 +++++ .../MAT.SqlRace.ServerListener.csproj | 50 ++++ MAT.SqlRace.ServerListener/Program.cs | 80 +++++++ MAT.SqlRace.ServerListener/SessionHelper.cs | 223 ++++++++++++++++++ 5 files changed, 431 insertions(+), 3 deletions(-) create mode 100644 MAT.SqlRace.ServerListener/App.config create mode 100644 MAT.SqlRace.ServerListener/MAT.SqlRace.ServerListener.csproj create mode 100644 MAT.SqlRace.ServerListener/Program.cs create mode 100644 MAT.SqlRace.ServerListener/SessionHelper.cs diff --git a/MAT.OCS.SQLRace.Examples.sln b/MAT.OCS.SQLRace.Examples.sln index c12aa2a..80ad936 100644 --- a/MAT.OCS.SQLRace.Examples.sln +++ b/MAT.OCS.SQLRace.Examples.sln @@ -1,7 +1,6 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29102.190 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33829.357 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MAT.SQLRace.HelloData", "MAT.SQLRace.HelloData\MAT.SQLRace.HelloData.csproj", "{FB3E8850-40AF-443E-82C1-183C1C76D460}" EndProject @@ -35,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MAT.SQLRace.HelloCreateSSN2 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters", "MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters\MAT.SQLRace.LoadSessionFromDatabaseAndReadParameters.csproj", "{FF2BE15F-8E2A-4247-B25D-0FFE2FEFFF20}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MAT.SqlRace.ServerListener", "MAT.SqlRace.ServerListener\MAT.SqlRace.ServerListener.csproj", "{C4281449-70AD-4A9F-A5F8-A11C6E58E460}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -161,6 +162,18 @@ Global {FF2BE15F-8E2A-4247-B25D-0FFE2FEFFF20}.Release|x64.Build.0 = Release|Any CPU {FF2BE15F-8E2A-4247-B25D-0FFE2FEFFF20}.Release|x86.ActiveCfg = Release|Any CPU {FF2BE15F-8E2A-4247-B25D-0FFE2FEFFF20}.Release|x86.Build.0 = Release|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Debug|x64.ActiveCfg = Debug|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Debug|x64.Build.0 = Debug|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Debug|x86.ActiveCfg = Debug|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Debug|x86.Build.0 = Debug|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Release|Any CPU.Build.0 = Release|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Release|x64.ActiveCfg = Release|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Release|x64.Build.0 = Release|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Release|x86.ActiveCfg = Release|Any CPU + {C4281449-70AD-4A9F-A5F8-A11C6E58E460}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MAT.SqlRace.ServerListener/App.config b/MAT.SqlRace.ServerListener/App.config new file mode 100644 index 0000000..03c57c2 --- /dev/null +++ b/MAT.SqlRace.ServerListener/App.config @@ -0,0 +1,62 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MAT.SqlRace.ServerListener/MAT.SqlRace.ServerListener.csproj b/MAT.SqlRace.ServerListener/MAT.SqlRace.ServerListener.csproj new file mode 100644 index 0000000..8470d67 --- /dev/null +++ b/MAT.SqlRace.ServerListener/MAT.SqlRace.ServerListener.csproj @@ -0,0 +1,50 @@ + + + net6.0-windows + Exe + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MAT.SqlRace.ServerListener/Program.cs b/MAT.SqlRace.ServerListener/Program.cs new file mode 100644 index 0000000..58a1ffb --- /dev/null +++ b/MAT.SqlRace.ServerListener/Program.cs @@ -0,0 +1,80 @@ +using MAT.OCS.Core; +using MESL.SqlRace.Common.Extensions; +using MESL.SqlRace.Domain; +using System; +using System.Linq; +using System.Threading; +using System.Net; + + +namespace MAT.SqlRace.ServerListenerLive +{ + /// + /// Record live data to a local SqlRace (Sqlite) + /// + /// NOTE: + /// If the session is in the state LiveNotInServer, + /// make sure Server Listener port in ATLAS is different to the one specified here. + /// + internal class Program + { + // The server listener configuration + private const int ServerListenerPortNumber = 6565; + private const string ServerListenerIpAddress = "127.0.0.1"; + + public static void Main(string[] args) + { + var dataSource = @"C:\temp\livesession.ssndb"; + Console.WriteLine(dataSource); + + /// connection strings are case and whitespace sensitive, the following format must be strightly followed for the Server Listener Protocol to successfully establish. + /// SQLite: "DbEngine=SQLite;Data Source={dataSource};Pooling=false;" + /// SQLServer: "server={dataSource};Initial Catalog={database};Trusted_Connection=True;" + var connectionString = $@"DbEngine=SQLite;Data Source={dataSource};Pooling=false;"; + var sessionIdentifier = "Server Listener Live Demo"; + + Console.WriteLine("Initialising"); + Core.Initialize(); + + Console.WriteLine("Setting up Server Listener Instance"); + Core.ConfigureServer(true, new IPEndPoint(IPAddress.Parse(ServerListenerIpAddress),ServerListenerPortNumber)); + var sessionManager = SessionManager.CreateSessionManager(); + var recordersConfiguration = RecordersConfiguration.GetRecordersConfiguration(); + recordersConfiguration.AddConfiguration(Guid.NewGuid(), "SQLite", dataSource, dataSource, connectionString, false); + + + Console.WriteLine("Creating new Session"); + var clientSession = sessionManager.CreateSession(connectionString, SessionKey.NewKey(), sessionIdentifier, DateTime.Now, "Session"); + var session = clientSession.Session; + try + { + var parameter = SessionHelper.CreateSessionConfigurationForOneParameter(session); + + for (int i = 0; i < 1000; i++) + { + var newTimestamp = DateTime.Now.ToNanoseconds(); + var newValue = Math.Sin(i / 360.0); + + session.AddChannelData( + parameter.ChannelIds.FirstOrDefault(), + newTimestamp, + 1, //value of 1 param + BitConverter.GetBytes(newValue)); + Thread.Sleep(100); + Console.WriteLine($"Written sample. Timestamp: {newTimestamp.ToTimeString()} Value:{newValue}"); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + finally + { + session.EndData(); + clientSession.Close(); + } + } + + + } +} diff --git a/MAT.SqlRace.ServerListener/SessionHelper.cs b/MAT.SqlRace.ServerListener/SessionHelper.cs new file mode 100644 index 0000000..5ec9cde --- /dev/null +++ b/MAT.SqlRace.ServerListener/SessionHelper.cs @@ -0,0 +1,223 @@ +// +// Copyright (c) McLaren Applied Technologies Ltd. + +using System.Collections.Generic; +using MESL.SqlRace.Domain; +using MESL.SqlRace.Domain.Infrastructure.DataPipeline; +using MESL.SqlRace.Enumerators; + +namespace MAT.SqlRace.ServerListenerLive +{ + internal class SessionHelper + { + public static Dictionary CreateSessionConfigurationForMultipleParameter( + IClientSession clientSession, + IEnumerable identifiers) + { + var channels = new Dictionary(); + + const string ConversionFunctionName = "CONV_MyParam:MyApp"; + const string ApplicationGroupName = "MyApp"; + const string ParameterGroupIdentifier = "MyParamGroup"; + + var session = clientSession.Session; + + var config = session.CreateConfiguration(); + + var group1 = new ParameterGroup(ParameterGroupIdentifier, "pg1_description"); + + var applicationGroup1 = new ApplicationGroup( + ApplicationGroupName, + ApplicationGroupName, + new List + { + group1.Identifier + }) + { + SupportsRda = false + }; + + config.AddGroup(applicationGroup1); + config.AddParameterGroup(group1); + + config.AddConversion( + new RationalConversion(ConversionFunctionName, "kph", "%5.2f", 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)); + + var vCarFrequency = new Frequency(2, FrequencyUnit.Hz); + + uint channelId = 1; + foreach (var identifier in identifiers) + { + channels[identifier] = channelId; + + var channel = new Channel( + channelId++, + "Channel" + channelId, + vCarFrequency.ToInterval(), + DataType.Signed16Bit, + ChannelDataSourceType.Periodic); + + var parameter = new Parameter( + identifier, + identifier, + identifier, + 400, //vCar maximum value + 0, //vCar minimum value + 1, + 0, + 0, + 255, + 0, + ConversionFunctionName, + new List + { + ParameterGroupIdentifier + }, + channel.Id, + ApplicationGroupName); + + config.AddChannel(channel); + config.AddParameter(parameter); + } + + config.Commit(); + + return channels; + } + + public static Parameter CreateSessionConfigurationForOneParameter(Session session) + { + const string ConversionFunctionName = "CONV_MyParam:MyApp"; + const string ApplicationGroupName = "MyApp"; + const string ParameterGroupIdentifier = "MyParamGroup"; + const string ParameterName = "MyParam"; + const uint MyParamChannelId = 999998; //must be unique + const int ApplicationId = 998; + var parameterIdentifier = $"{ParameterName}:{ApplicationGroupName}"; + + var config = session.CreateConfiguration(); + + var group1 = new ParameterGroup(ParameterGroupIdentifier, "pg1_description"); + + var applicationGroup1 = new ApplicationGroup( + ApplicationGroupName, + ApplicationGroupName, + ApplicationId, + new List + { + group1.Identifier + }) + { + SupportsRda = false + }; + + config.AddGroup(applicationGroup1); + config.AddParameterGroup(group1); + + config.AddConversion( + new RationalConversion(ConversionFunctionName, "kph", "%5.2f", 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)); + + var myParamFrequency = new Frequency(2, FrequencyUnit.Hz); + + var myParameterChannel = new Channel( + MyParamChannelId, + "MyParamChannel", + myParamFrequency.ToInterval(), + DataType.Double64Bit, + ChannelDataSourceType.Periodic); + + var myParameter = new Parameter( + parameterIdentifier, + ParameterName, + ParameterName + "Description", + 400, + 0, + 1, + 0, + 0, + 255, + 0, + ConversionFunctionName, + new List + { + ParameterGroupIdentifier + }, + myParameterChannel.Id, + ApplicationGroupName); + + config.AddChannel(myParameterChannel); + config.AddParameter(myParameter); + + config.Commit(); + + return myParameter; + } + + public static Parameter CreateTransientConfigurationForOneParameter(Session session) + { + const string ConversionFunctionName = "CONV_MyParam:MyApp"; + const string ApplicationGroupName = "MyApp"; + const string ParameterGroupIdentifier = "MyParamGroup"; + const string ParameterName = "MyParam"; + const uint MyParamChannelId = 999999; //must be unique + const int ApplicationId = 999; + var parameterIdentifier = $"{ParameterName}:{ApplicationGroupName}"; + + var transientConfigSet = session.CreateTransientConfiguration(); + + var parameterGroup = new ParameterGroup(ParameterGroupIdentifier, "some description!"); + transientConfigSet.AddParameterGroup(parameterGroup); + + var applicationGroup = new ApplicationGroup( + ApplicationGroupName, + ApplicationGroupName + "App Group Desc!!", + ApplicationId, + new List + { + parameterGroup.Identifier + }); + transientConfigSet.AddGroup(applicationGroup); + + var conversion = RationalConversion.CreateSimple1To1Conversion(ConversionFunctionName, "myunit", "%5.2f"); + transientConfigSet.AddConversion(conversion); + + var paramFrequency = new Frequency(2, FrequencyUnit.Hz); + + var paramChannel = new Channel( + MyParamChannelId, + "MyParamChannel", + paramFrequency.ToInterval(), + DataType.Double64Bit, + ChannelDataSourceType.Periodic, + string.Empty, + true); + + transientConfigSet.AddChannel(paramChannel); + + var myParameter = new Parameter( + parameterIdentifier, + ParameterName, + ParameterName + "Description", + 400, //maximum value + 0, //minimum value + 1, + 0, + 0, + 255, + 0, + ConversionFunctionName, + new List + { + ParameterGroupIdentifier + }, + paramChannel.Id, + ApplicationGroupName); + + transientConfigSet.AddParameter(myParameter); + + transientConfigSet.Commit(); + + return myParameter; + } + } +} \ No newline at end of file