-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDefineContent.cs
More file actions
174 lines (159 loc) · 7.14 KB
/
Copy pathDefineContent.cs
File metadata and controls
174 lines (159 loc) · 7.14 KB
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
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;
public static int ApplicationVersion = -1;
private bool mNoConfigTransfer = false;
private string mConfigTransferName = "";
public string prefix = "LOG";
public string prefixDoc = "LOG";
public string prefixSubmodule = "";
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 mVerifyVersion = -1;
public string share;
public string template;
public bool useApplicationVersion = false;
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 int VerifyVersion
{
get
{
if (mVerifyVersion < 0 && useApplicationVersion && ApplicationVersion >= 0)
return ApplicationVersion;
else
return mVerifyVersion;
}
set { mVerifyVersion = value; }
}
public string VerifyVersionString
{
get {
if (VerifyVersion < 0)
return "-.-";
else
return string.Format("{0}.{1}", VerifyVersion / 16, VerifyVersion % 16);
}
}
public static DefineContent Factory(XmlNode iDefineNode)
{
DefineContent lResult = new();
string lPrefix = iDefineNode.NodeAttr("prefix", "LOG");
if (sDefines.TryGetValue(lPrefix, out DefineContent lDefine))
{
lResult = lDefine;
}
else
{
lResult.prefix = lPrefix;
lResult.prefixDoc = iDefineNode.NodeAttr("prefixDoc", lPrefix);
lResult.prefixSubmodule = iDefineNode.NodeAttr("isSubmoduleOf", lResult.prefixDoc);
lResult.header = iDefineNode.NodeAttr("header");
if (!int.TryParse(iDefineNode.NodeAttr("NumChannels"), out lResult.NumChannels)) lResult.NumChannels = 0;
if (lResult.NumChannels > 0)
{
// we add a config which replaces the old %N% macro
ProcessInclude.AddConfig($"{lPrefix}_N", lResult.NumChannels.ToString(), true);
}
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;
while (lVerify != null && lVerify.NodeType != XmlNodeType.Element)
lVerify = lVerify.NextSibling;
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.useApplicationVersion = iDefineNode.NodeAttr("useApplicationVersion") == "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;
}
}
}