C# client
The C# client is compatible with .NET Framework version 4.0 and above.
First instantiate a DataExchangeAPIClient providing a URL, Context, and API key.
Then call the method addEntry()
to send one Entry at a time or the method addEntries()
to send more than one Entry at a time.
Configure the project
In a Visual Studio project, it is necessary to include the DLL files available in the NuGet website.
To configure the project with DLLs from NuGet, follow these steps:
-
Open the project.
-
Open the Solution Explorer.
-
Find the References node in the project tree.
-
Click right and choose Manage NuGet Packages....
-
In the Search field, type: "neotys data exchange".
-
Select dependency name: "NeotysRestDataExchangeAPI".
-
Click the Install button.
Create the C# Data Exchange API client
To use our C# API to inject external data into NeoLoad, use our DLLs to create Context and Entry objects.
The following code results in one path being sent to the NeoLoad Data Exchange API. A new Entry is created each second for 10 seconds.
Example 1
using System.Collections.Generic;
using Neotys.DataExchangeAPI.Model;
using Neotys.DataExchangeAPI.Client;
namespace TestDataExchangeAPIAsDLL
{
class DataExchangeAPIExample
{
static void Main(string[] args)
{
ContextBuilder cb = new ContextBuilder();
cb.Hardware = "example hardware";
cb.Location = "example location";
cb.Software = "example software";
cb.Script = "example script " + EntryBuilder.CurrentTimeMilliseconds;
IDataExchangeAPIClient client = DataExchangeAPIClientFactory.NewClient("http://localhost:7400/DataExchange/v1/Service.svc/", cb.build(), "apiKeyToSend");
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(1000);
EntryBuilder eb = new EntryBuilder(new List<string> { "_ScriptName_", "Entry", "Path" });
eb.Unit = "units";
eb.Value = i;
client.AddEntry(eb.Build());
System.Console.WriteLine("DataExchangeAPIExample.Main() sent entry with value " + i);
}
}
}
}
Example 2
using System.Collections.Generic;
using Neotys.DataExchangeAPI.Model;
using Neotys.DataExchangeAPI.Client;
namespace TestDataExchangeAPIAsDLL
{
class DataExchangeAPIExample2
{
/// <summary> Generate pseudo-random numbers. </summary>
private static System.Random Random = new System.Random(System.Guid.NewGuid().GetHashCode());
static void Main(string[] args)
{
IList<Entry> entriesToSend = new List<Entry>();
ContextBuilder cb = new ContextBuilder();
cb.Hardware = "example hardware";
cb.Location = "example location";
cb.Software = "example software";
cb.Script = "example script " + EntryBuilder.CurrentTimeMilliseconds;
IDataExchangeAPIClient client = DataExchangeAPIClientFactory.NewClient("http://localhost:7400/DataExchange/v1/Service.svc/", cb.build(), "apiKeyToSend");
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(1000);
// create a status.
StatusBuilder sb = new StatusBuilder();
sb.Code = "any string " + i;
sb.Message = "any string " + i;
if (Random.Next(100) >= 9)
{
sb.State = Status.State.Pass;
}
else
{
sb.State = Status.State.Fail;
}
EntryBuilder eb = new EntryBuilder(new List<string> { "_ScriptName_", "Entry", "Path" });
eb.Unit = "units";
eb.Value = i;
eb.Url = "http://www.neotys.com";
eb.Status = sb.Build();
entriesToSend.Add(eb.Build());
System.Console.WriteLine("DataExchangeAPIExample2.Main() stored entry with value " + i);
}
// send the entries.
client.AddEntries(entriesToSend);
System.Console.WriteLine("DataExchangeAPIExample2.Main() sent " + entriesToSend.Count + " entires.");
}
}
}