This repository was archived by the owner on Jul 26, 2019. It is now read-only.
forked from claude-uk/loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipelineDdiLists.cs
211 lines (194 loc) · 8.04 KB
/
PipelineDdiLists.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using Algenta.Colectica.Model;
using Algenta.Colectica.Model.Repository;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace CloserDataPipeline
{
public class PipelineDdiLists
{
public List<batch> batchList { get; protected set; }
public string basePath { get; protected set; }
public PipelineDdiLists(string importPath)
{
batchList = new List<batch>();
string[] lines = File.ReadAllLines(importPath);
foreach (string line in lines)
{
string line2 = line.Trim();
if (String.Equals(line2, ""))
{
continue;
}
else if (line2[0] == '#')
//Console.WriteLine("Commented line: " + line);
continue;
else
{
//ddiFileList.Add(line2);
ParseLine(line2);
}
}
}
private void ParseLine(string line)
{
string[] parts = line.Split(new char[] { '\t' });
if ((parts.Length == 2) && (parts[0] == "rootdir"))
{
basePath = parts[1];
}
else if ((parts.Length == 2) && (parts[0] == "batch"))
{
string parsedBatchName = parts[1];
batch newBatch = new batch(parsedBatchName);
batchList.Add(newBatch);
}
else
{
//if the line starts with the name of a batch
var relevantBatch = batchList.Find(x => string.Compare(x.batchName, parts[0], ignoreCase: true) == 0);
if (relevantBatch != null)
{
if ((parts.Length == 3) && (parts[1] == "CONCEPTS"))
{
relevantBatch.ddiFileList.Add(parts[2].Trim());
}
else if ((parts.Length == 3) && (parts[1] == "CADDIES"))
{
relevantBatch.ddiFileList.Add(parts[2].Trim());
}
else if ((parts.Length == 3) && (parts[1] == "TOPLEVEL"))
{
relevantBatch.ddiToplevelFileList.Add(parts[2].Trim());
}
else if ((parts.Length == 3) && (parts[1] == "VARIABLES"))
{
relevantBatch.ddiFileList.Add(parts[2].Trim());
}
else if ((parts.Length == 5) && (parts[1] == "MAPPING"))
{
string mappingFile = parts[2].Trim();
string ccScheme = parts[3].Trim();
List<string> ccSchemeList = ReadCcScheme(ccScheme);
string vScheme = parts[4].Trim();
ddiMappingFile mf = new ddiMappingFile(mappingFile, ccScheme, ccSchemeList, vScheme);
relevantBatch.ddiMappingFileList.Add(mf);
}
else if ((parts.Length == 4) && (parts[1] == "LINKING"))
{
string linkingFile = parts[2].Trim();
string vScheme = parts[3].Trim();
ddiLinkingFile lf = new ddiLinkingFile(linkingFile, vScheme);
relevantBatch.ddiLinkingFileList.Add(lf);
}
else if ((parts.Length == 4) && (parts[1] == "QLINK"))
{
string questionLinkingFile = parts[2].Trim();
string qcScheme = parts[3].Trim();
ddiQuestionLinkingFile lf = new ddiQuestionLinkingFile(questionLinkingFile, qcScheme);
relevantBatch.ddiQuestionLinkingFileList.Add(lf);
}
else if ((parts.Length == 4) && (parts[1] == "DERIVATION"))
{
string derivationFile = parts[2].Trim();
string vScheme = parts[3].Trim();
ddiDerivationFile df = new ddiDerivationFile(derivationFile, vScheme);
relevantBatch.ddiDerivationFileList.Add(df);
}
else
{
Trace.WriteLine("ERROR: Invalid batch line: " + line);
}
}
else
{
//Trace.WriteLine("Irrelevant line: " + line);
}
}
}
private List<string> ReadCcScheme(string ccScheme)
{
//check whether we have multiple instruments as sources
if (ccScheme.StartsWith("[") && ccScheme.EndsWith("]"))
{
//trim the square brackets, split on the comma, extract the trimmed strings, convert to list
//string[] parts = ccScheme.Trim(new char[] { '[', ']' }).Split(new char[] { ',' });
//return parts.ToList<string>();
return ccScheme.Trim(new char[] { '[', ']' }).Split(new char[] { ',' }).Select(p => p.Trim()).ToList<string>();
//List<string> parts = line.Split(';').Select(p => p.Trim()).ToList();
}
else
{
return null;
}
}
}
public class batch
{
public String batchName { get; protected set; }
public List<string> ddiFileList { get; protected set; }
public List<ddiMappingFile> ddiMappingFileList { get; protected set; }
public List<ddiLinkingFile> ddiLinkingFileList { get; protected set; }
public List<ddiQuestionLinkingFile> ddiQuestionLinkingFileList { get; protected set; }
public List<ddiDerivationFile> ddiDerivationFileList { get; protected set; }
public List<string> ddiToplevelFileList { get; protected set; }
public batch(string bn)
{
batchName = bn;
ddiFileList = new List<string>();
ddiMappingFileList = new List<ddiMappingFile>();
ddiLinkingFileList = new List<ddiLinkingFile>();
ddiQuestionLinkingFileList = new List<ddiQuestionLinkingFile>();
ddiDerivationFileList = new List<ddiDerivationFile>();
ddiToplevelFileList = new List<string>();
}
}
public class ddiMappingFile
{
public String mappingFileName { get; protected set; }
public String ccsName { get; protected set; }
public List<string> ccsNameList { get; protected set; }
public String vsName { get; protected set; }
public ddiMappingFile(string mf, string ccs, List<string> ccsl, string vs)
{
mappingFileName = mf;
ccsName = ccs;
ccsNameList = ccsl;
vsName = vs;
}
}
public class ddiLinkingFile
{
public String linkingFileName { get; protected set; }
public String vsName { get; protected set; }
public ddiLinkingFile(string lf, string vs)
{
linkingFileName = lf;
vsName = vs;
}
}
public class ddiQuestionLinkingFile
{
public String questionLinkingFileName { get; protected set; }
public String qcsName { get; protected set; }
public ddiQuestionLinkingFile(string qclf, string qcs)
{
questionLinkingFileName = qclf;
qcsName = qcs;
}
}
public class ddiDerivationFile
{
public String derivationFileName { get; protected set; }
public String vsName { get; protected set; }
public ddiDerivationFile(string df, string vs)
{
derivationFileName = df;
vsName = vs;
}
}
}