-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRunbook.cs
79 lines (62 loc) · 2.32 KB
/
Runbook.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
67
68
69
70
71
72
73
74
75
76
77
78
79
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization;
using Azure;
using System.Collections;
using YamlDotNet.Core;
namespace VectorIndexScenarioSuite
{
internal class Operation
{
[YamlMember(Alias = "start")]
public int? Start { get; set; }
[YamlMember(Alias = "end")]
public int? End { get; set; }
[YamlMember(Alias = "ids_start")]
public int? IdsStart { get; set; }
[YamlMember(Alias = "ids_end")]
public int? IdsEnd { get; set; }
[YamlMember(Alias = "tags_start")]
public int? TagsStart { get; set; }
[YamlMember(Alias = "tags_end")]
public int? TagsEnd { get; set; }
[YamlMember(Alias = "operation")]
public required string Name { get; set; }
}
internal class RunbookData
{
[YamlMember(Alias = "operations")]
public required Dictionary<string, Operation> Operation { get; set; }
[YamlMember(Alias = "max_pts")]
public int MaxPoints { get; set; }
[YamlMember(Alias = "gt_url")]
public required string GroundTruthURL { get; set; }
}
internal class Runbook
{
[YamlMember(Alias = "scenario")]
public RunbookData RunbookData;
[YamlMember(Alias = "version")]
public int Version;
// Default constructor is required for deserialization
public Runbook()
{
this.Version = 0;
this.RunbookData = new RunbookData() {
GroundTruthURL = string.Empty, MaxPoints = 0, Operation = new Dictionary<string, Operation>()
};
}
public static async Task<Runbook> Parse(string filePath)
{
if (string.IsNullOrEmpty(filePath))
{
throw new ArgumentException("File path cannot be null or empty", nameof(filePath));
}
using var reader = new StreamReader(filePath);
var yamlContent = await reader.ReadToEndAsync();
var deserializer = new DeserializerBuilder().Build();
var runbook = deserializer.Deserialize<Runbook>(yamlContent);
Console.WriteLine($"Runbook version: {runbook.Version}");
return runbook;
}
}
}