Overview

The Tsplice .NET API defines classes that allow a .NET application to interact with a Tsplice host. Generally speaking, the flow of code is as follows:

Response Data

Every Tsplice client method returns a TPRI.Tsplice.Models.ApiResponse object:

Error Handling

Any error that occurs during a Tsplice client method will throw an exception:

If a Tsplice client method returns without an exception, then the call completed successfully.

Async vs. Sync

All Tsplice client calls are defined as async calls intended to be awaited.

// Request the system status
var response = await client.GetSystemStatus();

If async calls are not possible in the calling application, the Tsplice client class offers a Sync(..) method that can be used to wrap any client async method:

// Request the system status
var response = TPRI.Tsplice.Client.Sync(() => client.GetSystemStatus());

Cancelling Long-Running Requests

Each client method includes an optional cancelToken parameter that can be used to interrupt and cancel a long-running call.

// Create a cancellation source
CancelSource = new CancellationTokenSource();

//...

try
   {
   // Download a bunch of files from the Tsplice host
   var response = await client.GetSharedFiles("SharedFolder", "*",
                                              "D:\LocalFolder\",
                                              CancelSource.Token);
   }
catch (TaskCanceledException)
   {
   // Someone called CancelSource.Cancel() before all of
   // the files were downloaded
   }

Example

Following is an example usage of the Tsplice client:

var client = new TPRI.Tsplice.Client();
client.BaseUri = new Uri("https://www.somewhere.com");

try
   {
   // Request a shared file from the Tsplice host
   var response = await client.GetSharedFile(sharePath, localPath);
   // ...
   }
catch (Exception ex)
   {
   MessageBox.Show(ex.Message);
   }