-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProtocol.cs
66 lines (56 loc) · 1.88 KB
/
Protocol.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.IO;
using Fluid;
namespace TecanSparkRelay.Protocols
{
// Abstract class that all protocols should inherit from
public abstract class Protocol
{
public List<object> wells = new List<object>();
private static IFluidTemplate templateXML;
public void Register(string protocolName)
{
// Parse the templated method XML file for each protocol and register it
var template = File.ReadAllText($"./Protocols/{protocolName}/Method.xml");
templateXML = FluidTemplate.Parse(template);
}
public virtual string GenerateMethodXML()
{
// Generate the method XML file using the provided plate and spec
var context = new { plate = this.Plate(), spec = this.SpecContext() };
return templateXML.Render(new TemplateContext(context));
}
public virtual void Validate()
{
// Check that the provided spec matches the expected spec for the protocol
Type type = this.SpecType();
if (this.SpecContext().GetType() != type)
{
throw new ApplicationException($"spec is not of type {type}");
};
}
public virtual object SpecContext()
{
// Return a spec object for populating the method XML template
return this;
}
public virtual Type SpecType()
{
throw new NotImplementedException();
}
public Plate Plate()
{
// Use the number of selected wells to generate the plate configuration
return new Plate(this.Rows(), this.Columns(), this.wells.Count);
}
public virtual int Rows()
{
return 0;
}
public virtual int Columns()
{
return 0;
}
}
}