186 lines
6.3 KiB
C#
186 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Tecan.At.AutomationInterface.SampleApp
|
|
{
|
|
public class SampleApp
|
|
{
|
|
public void GetInstrument(SessionData sessionData, string aliasPart)
|
|
{
|
|
try
|
|
{
|
|
var availableInstruments = AutomationInterfaceAccess.GetInstruments();
|
|
sessionData.SelectedInstrument = availableInstruments.FirstOrDefault(x => string.IsNullOrEmpty(aliasPart) || x.Alias.Contains(aliasPart));
|
|
|
|
if (sessionData.SelectedInstrument == null)
|
|
{
|
|
sessionData.SelectedInstrument = availableInstruments.FirstOrDefault(x => string.IsNullOrEmpty(aliasPart) || x.SerialNumber.Contains(aliasPart));
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
public void GetMethods(SessionData sessionData)
|
|
{
|
|
try
|
|
{
|
|
sessionData.AvailableMethods = AutomationInterfaceAccess.GetMethods();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
public string GetMethodXml(string methodName)
|
|
{
|
|
try
|
|
{
|
|
return AutomationInterfaceAccess.GetMethodXml(methodName);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public void CheckMethod(SessionData sessionData, string methodFile, out IEnumerable<string> messages)
|
|
{
|
|
sessionData.EnforceSetInstrument();
|
|
|
|
messages = null;
|
|
try
|
|
{
|
|
string methodAsXml = System.IO.File.ReadAllText(methodFile);
|
|
sessionData.MethodIsValid = AutomationInterfaceAccess.CheckMethod(sessionData.SelectedInstrument, methodAsXml, "MethodToCheck", out messages);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
public void ExecuteMethod(SessionData sessionData, string methodFile, string methodName, int[] wellsToSelect, bool isStacker = false)
|
|
{
|
|
sessionData.EnforceSetInstrument();
|
|
|
|
try
|
|
{
|
|
string methodAsXml = System.IO.File.ReadAllText(methodFile);
|
|
|
|
if (wellsToSelect.Any())
|
|
{
|
|
methodAsXml = AutomationInterfaceAccess.ChangePlateLayout(methodAsXml, wellsToSelect);
|
|
}
|
|
|
|
var result = AutomationInterfaceAccess.ExecuteMethod(sessionData.SelectedInstrument, methodAsXml, methodName, isStacker);
|
|
if (result != null)
|
|
{
|
|
sessionData.WorkspaceId = result.WorkspaceId;
|
|
sessionData.ExecutionId = result.ExecutionId;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Error executing method (checkMethod failed).");
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
public void ExecuteMethodAsync(SessionData sessionData, string methodFile, string methodName, int[] wellsToSelect, bool isStacker = false)
|
|
{
|
|
sessionData.EnforceSetInstrument();
|
|
|
|
try
|
|
{
|
|
string methodAsXml = System.IO.File.ReadAllText(methodFile);
|
|
|
|
if (wellsToSelect.Any())
|
|
{
|
|
methodAsXml = AutomationInterfaceAccess.ChangePlateLayout(methodAsXml, wellsToSelect);
|
|
}
|
|
|
|
var task = AutomationInterfaceAccess.ExecuteMethodAsync(sessionData.SelectedInstrument, methodAsXml, methodName, isStacker);
|
|
|
|
Console.WriteLine($"Started method '{methodName}'...");
|
|
while (task.Status == TaskStatus.Running)
|
|
{
|
|
Thread.Sleep(1000);
|
|
Console.Write(".");
|
|
}
|
|
|
|
task.Wait();
|
|
|
|
if (task.Result != null)
|
|
{
|
|
sessionData.WorkspaceId = task.Result.WorkspaceId;
|
|
sessionData.ExecutionId = task.Result.ExecutionId;
|
|
|
|
Console.WriteLine();
|
|
Console.WriteLine($"Executed method '{methodName}'. WorkspaceId: '{sessionData.WorkspaceId}'.");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Error executing method (checkMethod failed).");
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
public void ExecuteMethodAsyncAndCancel(SessionData sessionData, string methodFile, string methodName, int[] wellsToSelect, bool isStacker = false)
|
|
{
|
|
sessionData.EnforceSetInstrument();
|
|
|
|
try
|
|
{
|
|
string methodAsXml = System.IO.File.ReadAllText(methodFile);
|
|
|
|
if (wellsToSelect.Any())
|
|
{
|
|
methodAsXml = AutomationInterfaceAccess.ChangePlateLayout(methodAsXml, wellsToSelect);
|
|
}
|
|
|
|
var task = AutomationInterfaceAccess.ExecuteMethodAsync(sessionData.SelectedInstrument, methodAsXml, methodName, isStacker);
|
|
Console.WriteLine($"Started method '{methodName}'...");
|
|
|
|
// method should be a rather complex method that it takes longer to execute as this thread is sleeping
|
|
Thread.Sleep(5000);
|
|
Console.WriteLine($"Cancel method execution.");
|
|
|
|
AutomationInterfaceAccess.CancelAsyncMethodExecution(sessionData.SelectedInstrument);
|
|
Console.WriteLine($"Cancellation finished.");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
public void ExportData(SessionData sessionData)
|
|
{
|
|
try
|
|
{
|
|
sessionData.ExportedDataFile = AutomationInterfaceAccess.ExportData(sessionData.WorkspaceId, sessionData.ExecutionId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
}
|
|
}
|