Code examples
Example 1: Access Tachyon using default credentials
Creating default connector
TachyonConnector connector = new TachyonConnector("http://myserver.mydomain.com/consumer", "myConsumer", null);
Example 2: Access Tachyon using specific credentials
Custom Http manager class
class MyManager : IHttpClientManager
{
private readonly string userName;
private readonly string password;
public MyManager(string userName, string password)
{
this.userName = userName;
this.password = password;
}
public System.Net.Http.HttpClient GetClient()
{
HttpClientHandler httpMessageHandler = new HttpClientHandler
{
UseDefaultCredentials = false,
Credentials = new NetworkCredential(this.userName, this.password)
};
return new HttpClient(httpMessageHandler);
}
public void DisposeOfClient(System.Net.Http.HttpClient client)
{
client.Dispose();
}
}
Creating connector
IHttpClientManager clientManager = new MyManager("username goes here", "password goes here");
ITransportProxy proxy = new DefaultTransportProxy(null, "myConsumer", clientManager);
TachyonConnector connector = new TachyonConnector("http://myserver.mydomain.com/consumer", proxy, null);
Example 3: Access Tachyon using a custom transport proxy
Creating a connector with custom transport proxy
class myConnectionProxy : ITransportProxy
{
[...]
}
[...]
var myConnectionProxyInstance = new myConnectionProxy([...]);
TachyonConnector connector = new TachyonConnector("http://myserver.mydomain.com/consumer", myConnectionProxyInstance, null);
Example 4: A complete example
A complete SDK example Expand source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tachyon.SDK.Consumer;
using Tachyon.SDK.Consumer.Enums;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
var connector = new TachyonConnector("http://localhost/consumer", "MyCustomConsumer", null);
var devices = connector.Devices.GetDevices();
if (devices.Success)
{
foreach (var device in devices.ReceivedObject)
{
Console.WriteLine("Name: {0} - Os: {1}", device.Fqdn, device.OsVerTxt);
}
}
var instructionDefinitions = connector.InstructionDefinitions.Get(new List<InstructionType> {InstructionType.Question});
if (instructionDefinitions.Success)
{
foreach (var instructionDefinition in instructionDefinitions.ReceivedObject)
{
Console.WriteLine(instructionDefinition.Name);
}
}
var definition = connector.InstructionDefinitions.GetInstructionDefinition("1E-Explorer-TachyonCore-DisabledServices");
if (definition.Success)
{
var def = definition.ReceivedObject;
Console.WriteLine("Name: {0}", def.Name);
Console.WriteLine("Description: {0}", def.Description);
Console.WriteLine("Instruction TTL: {0}", def.InstructionTtlMinutes);
Console.WriteLine("Responses TTL: {0}", def.ResponseTtlMinutes);
Console.WriteLine("Schema:");
foreach (var schemaColumn in def.Schema)
{
Console.WriteLine(" Field Name: {0}. Data Type: {1}", schemaColumn.Name, schemaColumn.Type);
}
Console.WriteLine("Aggregation:");
foreach (var aggregationColumn in def.Aggregation.Schema)
{
Console.WriteLine(" Field Name: {0}. Data Type: {1}", aggregationColumn.Name, aggregationColumn.Type);
}
}
var myDefinition = connector.InstructionDefinitions.GetInstructionDefinition("1E-Explorer-TachyonCore-DisabledServices");
if (myDefinition.Success)
{
var result = connector.Instructions.SendInstruction(myDefinition.ReceivedObject.Id, null, 60, 120);
if (result.Success)
{
Console.WriteLine("successfully issued an instruction");
Thread.Sleep(2000);
var answers = connector.Responses.GetAllAggregatedResponses(result.ReceivedObject.Id);
if (answers.Success)
{
foreach (var answer in answers.ReceivedObject.Responses)
{
Console.WriteLine("Caption: {0} - Count :{1}",answer.Values["Caption"], answer.Values["Count"]);
}
}
}
}
}
}
}