Getting started with the AppDrill C# SDK
Introduction
Each AppDrill troubleshooting session will always consist of the following steps:
- Connect to an AppDrill backend instance and retrieve a list of models
- Choose a model to work with in the session (only one model can be used for each session)
- Get Failures, Tests and Corrective actions associated with symptoms defined for the selected model
- Update test results, and advance in the troubleshooting session
Getting the list of models from an AppDrill server
Before starting a troubleshooting session, one would need to choose a model to work with for that session. SessionManager provides the means for retrieving a list of model names that one server holds/manages.
The following example depict code for using the function GetModelNames to get the list of model names:
try
{
var modelNames = await Task.Run(() => SessionManager.Instance.GetModelNames("http://model.appdrill.io");
if (modelNames != null)
{
// Do something with the list of model names
}
else
{
// Server error, or no models available
}
}
catch (Exception)
{
// Connection issue, handle error
}
Starting and ending a session
The SessionManager is responsible for the life cycle of a session.
In order to create a new session, one would need to provide a ConnectionInfo instance, which holds the necessary information for initiating the session.
A session can be started by calling BeginSession, and end by calling EndSession:
class MyClass : ISessionDataListener
{
// ...
private ISession _session;
private void Initialize()
{
// Generate a connection info object - a server address, and a model name
ConnectionInfo connectionInfo = new ConnectionInfo("http://model.appdrill.io", "mymodel");
// Begin the session, use 'this' instance as the callback handler
_session = SessionManager.Instance.BeginSession(this, connectionInfo);
}
private void Finalize()
{
// End the session
SessionManager.Instance.CloseSession(_session);
}
// ...
}
Working with a session instance
Once an instance of an ISession type is aquired through the SessionManager, we may now begin a troubleshooting session for the selected model.
The workflow would normally be as follows:
- Use GetSymptoms to get the symptoms available for the selected model
- Call RefreshSymptomData on a specific symptom to retrieve symptom data from the server
- Use the various GetXXX() calls in order to get available Failures, Tests, Components and Corrective Actions
- Set test result using SetTestResult, then go back to step #2
The following example depict in code the steps described above:
class MyClass : ISessionDataListener
{
// ...
private void HandleSomeSymptom()
{
// Get all symptoms associated with the model
var symptoms = _session.GetSymptoms();
// Refresh data for the first symptom in the list
if (_session.RefreshSymptomData(symptoms[0].Id))
{
// Expect async callback through SessionDataChanged
}
else
{
// Handle failure
}
}
public void SessionDataChanged(ISessionDataListener.SessionDataChangedEventType eventType)
{
// Session is now up-to-date, do something with the data
var tests = _session.GetCommonTests(); // Or, GetTestsBySymptomId()
// ...
}
// ...
}
Setting test result
When a test is performed by an operator, the backend model needs to get updated with the result, so the new data can be taken into account. The new data will be used to re-evaluate the weight of pending tests and how failures get ranked.
To update the result of a test execution, use the SetTestResult function:
public void MyUpdateFunc(Test test)
{
if (testFailed(test))
{
_session.SetTestResult(test.id, TestResult.Failed)
}
else if (testPassed(test))
{
_session.SetTestResult(test.id, TestResult.Passed)
}
else
{
_session.SetTestResult(test.id, TestResult.Skipped)
}
}