-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.cs
424 lines (404 loc) · 18 KB
/
options.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Windows.Forms;
using System.Globalization;
namespace Script_Builder
{
public class option
{
private string name;
private string value;
public option(string name, string value)
{
this.name = name;
this.value = value;
}
public string Name
{
get
{
return this.name;
}
}
public string Value
{
get
{
return this.value;
}
set
{
this.value = value;
}
}
}
public class makroKeys
{
private string keyName;
private string keyTarget;
private string targetTextBox;
public makroKeys(string keyName, string keyTarget, string targetTextBox)
{
this.keyName = keyName;
this.keyTarget = keyTarget;
this.targetTextBox = targetTextBox;
/*
switch (targetTextBox)
{
case "Tabelle":
this.targetTextBox = "Tabelle";
break;
case "Einfach (Header, Footer)":
this.targetTextBox = "Once";
break;
case "Wiederholt (Body)":
this.targetTextBox = "Multi";
break;
case "Wie in Makrodatei definiert":
this.targetTextBox = "None";
break;
default:
this.targetTextBox = targetTextBox;
break;
}*/
}
public string KeyName
{
get
{
return this.keyName;
}
}
public string KeyTarget
{
get
{
return this.keyTarget;
}
}
public string TargetTextBox
{
get
{
return this.targetTextBox;
}
}
}
public class options
{
private string optionsFile;
private Dictionary<string,option> optionList = new Dictionary<string,option>();
public Dictionary<int, makroKeys> makroList = new Dictionary<int, makroKeys>();
private mainForm mainForm;
public options(string optionsFile, mainForm mainForm)
{
this.optionsFile = optionsFile;
this.mainForm = mainForm;
}
public option GetOptions(string optionName)
{
if (optionList.ContainsKey(optionName))
return optionList[optionName];
else
return null;
}
public void SetOptions(string optionName, string optionValue)
{
if (optionList.ContainsKey(optionName))
optionList[optionName].Value = optionValue;
else
optionList.Add(optionName, new option(optionName,optionValue));
}
public bool ReadOptions()
{
if (!File.Exists(optionsFile))
{
if(File.Exists(Path.Combine(Application.StartupPath, "OSV-Scripting-Help_V10.pdf")))
SetOptions("DokuPath", Path.Combine(Application.StartupPath, "OSV-Scripting-Help_V10.pdf"));
int tempMakroIndex = 0;
if (File.Exists(Path.Combine(Application.StartupPath, "example - DLS - change E164 DisplayID Remark.txt")))
SetMakros(tempMakroIndex++.ToString(), "Example - DLS - Change E164", Path.Combine(Application.StartupPath, "example - DLS - change E164 DisplayID Remark.txt").ToString(), "Repeated");
if (File.Exists(Path.Combine(Application.StartupPath, "example - OSV - Add Subscribers.txt")))
SetMakros(tempMakroIndex++.ToString(), "Example - OSV - New Subscriber", Path.Combine(Application.StartupPath, "example - OSV - Add Subscribers.txt").ToString(), "Repeated");
//SetOptions("Language", "English");
SetOptions("Language", "Deutsch");
WriteOptions();
if(mainForm.programmStrings != null)
MessageBox.Show(mainForm.programmStrings.GetString("textOptionsXMLNotFound"), mainForm.programmStrings.GetString("textReadOptions"), MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("There was no \"options.xml\" file found.\r\nNew preference file was created with default values.", "Read Preferences", MessageBoxButtons.OK, MessageBoxIcon.Information);
//return false;
}
try
{
XmlDocument options = new XmlDocument();
string optionsChildName;
options.Load(optionsFile);
XmlElement optionsRoot = options.DocumentElement;
foreach (XmlNode optionsKnoten in optionsRoot.ChildNodes)
{
optionsChildName = optionsKnoten.Name.ToString();
if (optionsKnoten.HasChildNodes)
{
foreach (XmlNode optionsDaten in optionsKnoten.ChildNodes)
{
switch (optionsChildName)
{
case "Basic":
SetOptions(optionsDaten.Name.ToString(), optionsDaten.InnerText.ToString());
break;
case "MakroKeys":
if (optionsDaten.Name == "MakroKey" && optionsDaten.HasChildNodes && optionsDaten.ChildNodes.Count == 4)
{
string index = "";
string keyName = "";
string keyTarget = "";
string targetTextBox = "";
for (int feldIndex = 0; feldIndex < 4; feldIndex++)
{
switch (optionsDaten.ChildNodes[feldIndex].Name)
{
case "Index":
index = optionsDaten.ChildNodes[feldIndex].InnerText;
break;
case "KeyName":
keyName = optionsDaten.ChildNodes[feldIndex].InnerText;
break;
case "KeyTarget":
keyTarget = optionsDaten.ChildNodes[feldIndex].InnerText;
break;
case "TargetTextBox":
switch (optionsDaten.ChildNodes[feldIndex].InnerText)
{
case "Body":
case "Multi":
targetTextBox = "Repeated";
break;
case "Header":
case "Footer":
case "Once":
targetTextBox = "Simple";
break;
case "Tabelle":
targetTextBox = "Table";
break;
case "None":
targetTextBox = "Define";
break;
default:
targetTextBox = optionsDaten.ChildNodes[feldIndex].InnerText;
break;
}
break;
}
}
SetMakros(index, keyName, keyTarget, targetTextBox);
}
break;
}
}
}
}
}
catch (XmlException expt)
{
MessageBox.Show(expt.Message, mainForm.programmStrings.GetString("textErrorReadOptions"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
bool needWrite = false;
if (GetOptions("VariableMarker") == null)
{
SetOptions("VariableMarker", "%");
needWrite = true;
}
if (GetOptions("StartPathType") == null)
{
SetOptions("StartPathType", "AnybodysLast");
needWrite = true;
}
if (GetOptions("Language") == null)
{
SetOptions("Language", "Deutsch");
needWrite = true;
}
if ((GetOptions("StartPathType").Value == "AnybodysLast" || GetOptions("StartPathType").Value == "AlwaysSame") && GetOptions("StartPath") == null)
{
SetOptions("StartPath", Application.StartupPath.ToString());
}
else if (GetOptions("StartPathType").Value == "GroupssLast")
{
if (GetOptions("StartPathOptions") == null)
{
SetOptions("StartPathOptions", Application.StartupPath.ToString());
}
if (GetOptions("StartPathOutput") == null)
{
SetOptions("StartPathOutput", Application.StartupPath.ToString());
}
if (GetOptions("StartPathTemplate") == null)
{
SetOptions("StartPathTemplate", Application.StartupPath.ToString());
}
if (GetOptions("StartPathTable") == null)
{
SetOptions("StartPathTable", Application.StartupPath.ToString());
}
}
if(needWrite)
WriteOptions();
return true;
}
public void CreateMakroMenu()
{
List<makroKeys> tempList = orderKeyList(makroList);
mainForm.createMakroMenu(tempList);
}
private void SetMakros(string index, string keyName, string keyTarget, string targetTextBox)
{
if (index == "" || keyName == "" || keyTarget == "" || targetTextBox == "") return;
int intIndex;
try
{
intIndex = Convert.ToInt16(index);
}
catch
{
return;
}
if (makroList.ContainsKey(intIndex))
{
makroList[intIndex] = new makroKeys(keyName, keyTarget, targetTextBox);
}
else
{
makroKeys testTempKey = new makroKeys(keyName, keyTarget, targetTextBox);
makroList.Add(intIndex, testTempKey);
}
}
public bool WriteOptions()
{
try
{
using (XmlTextWriter myXmlTextWriter = new XmlTextWriter(optionsFile, System.Text.Encoding.UTF8))
{
myXmlTextWriter.WriteStartDocument(false);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteComment("Options File for Script Builder");
myXmlTextWriter.WriteStartElement("Options");
myXmlTextWriter.WriteStartElement("Basic");
if (GetOptions("VariableMarker") != null)
myXmlTextWriter.WriteElementString("VariableMarker", GetOptions("VariableMarker").Value);
if (GetOptions("DokuPath") != null)
myXmlTextWriter.WriteElementString("DokuPath", GetOptions("DokuPath").Value);
if (GetOptions("Debugging") != null)
myXmlTextWriter.WriteElementString("Debugging", GetOptions("Debugging").Value);
if (GetOptions("Language") != null)
myXmlTextWriter.WriteElementString("Language", GetOptions("Language").Value);
if (GetOptions("StartPathType") != null)
{
myXmlTextWriter.WriteElementString("StartPathType", GetOptions("StartPathType").Value);
if (GetOptions("StartPathType").Value == "AlwaysSame")
myXmlTextWriter.WriteElementString("StartPath", GetOptions("StartPath").Value);
}
if (GetOptions("WriteStartPathOnEnd") != null)
{
myXmlTextWriter.WriteElementString("WriteStartPathOnEnd", GetOptions("WriteStartPathOnEnd").Value);
if (GetOptions("WriteStartPathOnEnd").Value == "True")
{
if (GetOptions("StartPathType").Value == "AnybodysLast")
{
myXmlTextWriter.WriteElementString("StartPath", GetOptions("StartPath").Value);
}
else if (GetOptions("StartPathType").Value == "GroupsLast")
{
myXmlTextWriter.WriteElementString("StartPathOptions", GetOptions("StartPathOptions").Value);
myXmlTextWriter.WriteElementString("StartPathOutput", GetOptions("StartPathOutput").Value);
myXmlTextWriter.WriteElementString("StartPathTemplate", GetOptions("StartPathTemplate").Value);
myXmlTextWriter.WriteElementString("StartPathTable", GetOptions("StartPathTable").Value);
}
}
}
myXmlTextWriter.WriteEndElement();
if (makroList.Count > 0)
{
myXmlTextWriter.WriteStartElement("MakroKeys");
foreach (KeyValuePair<int, makroKeys> thisKey in makroList)
{
myXmlTextWriter.WriteStartElement("MakroKey");
myXmlTextWriter.WriteElementString("Index", thisKey.Key.ToString());
myXmlTextWriter.WriteElementString("KeyName", thisKey.Value.KeyName);
myXmlTextWriter.WriteElementString("KeyTarget", thisKey.Value.KeyTarget);
myXmlTextWriter.WriteElementString("TargetTextBox", thisKey.Value.TargetTextBox);
myXmlTextWriter.WriteEndElement();
}
myXmlTextWriter.WriteEndElement();
}
myXmlTextWriter.WriteEndElement();
}
this.mainForm.createMakroMenu(orderKeyList(makroList));
return true;
}
catch (XmlException expt)
{
MessageBox.Show(expt.Message, mainForm.programmStrings.GetString("textErrorWriteOptions"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
catch
{
return false;
}
}
public List<makroKeys> orderKeyList(Dictionary<int, makroKeys> inputDictionary)
{
List<KeyValuePair<int, makroKeys>> TempKeyList = new List<KeyValuePair<int, makroKeys>>();
List<makroKeys> outputKeys = new List<makroKeys>();
foreach (KeyValuePair<int,makroKeys> thisKeyPair in inputDictionary)
{
if (TempKeyList.Count > 0)
{
for (int I = 0; I <= TempKeyList.Count; I++)
{
if (I == TempKeyList.Count)
{
TempKeyList.Add(thisKeyPair);
break;
}
else if (thisKeyPair.Key < TempKeyList[I].Key)
{
TempKeyList.Insert(I, thisKeyPair);
break;
}
}
}
else
{
TempKeyList.Add(thisKeyPair);
}
}
foreach (KeyValuePair<int, makroKeys> thisKeyPair in TempKeyList)
{
outputKeys.Add(thisKeyPair.Value);
}
return outputKeys;
}
public makroKeys GetMakroKey(string KeyName)
{
foreach (KeyValuePair<int, makroKeys> thisKeyPair in makroList)
{
if (thisKeyPair.Value.KeyName == KeyName) return thisKeyPair.Value;
}
return null;
}
public CultureInfo GetCulture()
{
if (GetOptions("Language") != null && GetOptions("Language").Value == "English")
return new CultureInfo("en-US");
else
//return new CultureInfo("de-DE");
return new CultureInfo("");
}
}
}