-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDefineContent.cs
139 lines (127 loc) · 5.79 KB
/
DefineContent.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
using System.Xml;
namespace OpenKNXproducer
{
public class DefineContent
{
private static readonly Dictionary<string, DefineContent> sDefines = new();
public static DefineContent Empty = new();
private static bool sWithConfigTransfer = false;
private bool mNoConfigTransfer = false;
private string mConfigTransferName = "";
public string prefix = "LOG";
public string prefixDoc = "LOG";
public int KoOffset = 1;
public int KoSingleOffset;
public int KoBlockSize = 0;
public string[] ReplaceKeys = Array.Empty<string>();
public string[] ReplaceValues = Array.Empty<string>();
public int NumChannels = 1;
public int ModuleType = 1;
public string header;
public bool IsTemplate;
public bool IsParameter = true;
public string VerifyFile = "";
public string VerifyRegex = "";
public int VerifyVersion = -1;
public string share;
public string template;
public static bool WithConfigTransfer
{
get { return sWithConfigTransfer; }
private set { sWithConfigTransfer = value; }
}
public bool NoConfigTransfer
{
get { return mNoConfigTransfer; }
private set { mNoConfigTransfer = value; }
}
public string ConfigTransferName
{
get { return mConfigTransferName; }
private set { mConfigTransferName = value; }
}
public static DefineContent Factory(XmlNode iDefineNode)
{
DefineContent lResult = new();
string lPrefix = iDefineNode.NodeAttr("prefix", "LOG");
if (sDefines.ContainsKey(lPrefix))
{
lResult = sDefines[lPrefix];
}
else
{
lResult.prefix = lPrefix;
lResult.prefixDoc = iDefineNode.NodeAttr("prefixDoc", lPrefix);
lResult.header = iDefineNode.NodeAttr("header");
if (!int.TryParse(iDefineNode.NodeAttr("NumChannels"), out lResult.NumChannels)) lResult.NumChannels = 0;
if (!int.TryParse(iDefineNode.NodeAttr("KoOffset"), out lResult.KoOffset)) lResult.KoOffset = 1;
if (!int.TryParse(iDefineNode.NodeAttr("KoSingleOffset"), out lResult.KoSingleOffset)) lResult.KoSingleOffset = 0;
string lReplaceKeys = iDefineNode.NodeAttr("ReplaceKeys");
string lReplaceValues = iDefineNode.NodeAttr("ReplaceValues");
if (lReplaceKeys.Length > 0)
{
lResult.ReplaceKeys = lReplaceKeys.Split(" ");
lResult.ReplaceValues = lReplaceValues.Split(" ");
}
lResult.ModuleType = int.Parse(iDefineNode.NodeAttr("ModuleType"));
XmlNode lVerify = iDefineNode.FirstChild;
if (lVerify != null && lVerify.Name == "op:verify")
{
lResult.VerifyFile = lVerify.NodeAttr("File");
lResult.VerifyRegex = lVerify.NodeAttr("Regex", "\\s\"version\":\\s\"(\\d{1,2}).(\\d{1,2}).*\",");
lResult.VerifyVersion = TemplateApplication.ParseNumberValue("ModuleVersion", lVerify.NodeAttr("ModuleVersion", "-1"));
// int.TryParse(lVerify.NodeAttr("ModuleVersion", "-1"), out lResult.VerifyVersion);
}
lResult.share = iDefineNode.NodeAttr("share");
lResult.NoConfigTransfer = iDefineNode.NodeAttr("noConfigTransfer") == "true";
lResult.ConfigTransferName = iDefineNode.NodeAttr("configTransferName");
if (lResult.share.Contains("ConfigTransfer.share.xml"))
{
lResult.NoConfigTransfer = true;
DefineContent.WithConfigTransfer = true;
}
lResult.template = iDefineNode.NodeAttr("template");
lResult.IsParameter = false;
lResult.IsTemplate = false;
sDefines.Add(lPrefix, lResult);
}
return lResult;
}
public static DefineContent GetDefineContent(string iPrefix)
{
DefineContent lResult;
lResult = sDefines.ContainsKey(iPrefix) ? sDefines[iPrefix] : Empty;
return lResult;
}
public static bool ValidateDefines()
{
bool lResult = false;
int[] lModuleTypes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
foreach (var lDefineEntry in sDefines)
{
DefineContent lDefine = lDefineEntry.Value;
int lModuleTypeLen = lDefine.ModuleType.ToString().Length;
int lModuleTypeIndex = lDefine.ModuleType < 10 ? lDefine.ModuleType : lDefine.ModuleType / 10;
switch (lModuleTypes[lModuleTypeIndex])
{
case 1:
if (lModuleTypeLen == 2)
Program.Message(true, "Inconsistent ModuleType definitions found: {0} and {1}. Use always 2-digit ModuleTypes except you know what you are doing!", lModuleTypeIndex, lDefine.ModuleType);
break;
case 2:
if (lModuleTypeLen == 1)
Program.Message(true, "Inconsistent ModuleType definitions found: {0}x and {0}. Use always 2-digit ModuleTypes except you know what you are doing!", lModuleTypeIndex);
break;
default:
lModuleTypes[lModuleTypeIndex] = lModuleTypeLen;
break;
}
}
return lResult;
}
public static Dictionary<string, DefineContent> Defines()
{
return sDefines;
}
}
}