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.
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);
}
}
}
}
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.");
}
}
}