-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathValidationResult.cs
More file actions
239 lines (214 loc) · 7.35 KB
/
Copy pathValidationResult.cs
File metadata and controls
239 lines (214 loc) · 7.35 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NetLicensingClient.Entities
{
/// <summary>
/// Contains result of the Licensee.validate() operation. See NetLicensingAPI JavaDoc for details:
/// https://go.netlicensing.io/javadoc/v2/com/labs64/netlicensing/domain/vo/ValidationResult.html
/// </summary>
public class ValidationResult : IEntity
{
private String licenseeNumber;
private Dictionary<String, Composition> validations;
private DateTime ttl;
public ValidationResult()
{
validations = new Dictionary<String, Composition>();
}
public ValidationResult(netlicensing source)
{
validations = new Dictionary<String, Composition>();
ttl = source.ttl;
if (source.items.item == null) {
return;
}
foreach (item i in source.items.item)
{
if (Constants.Licensee.TYPE_NAME.Equals(i.type)) {
if (i.property != null)
{
foreach (property p in i.property)
{
if (Constants.NUMBER.Equals(p.name)) {
setLicenseeNumber(p.Value);
break;
}
if (Constants.Licensee.LICENSEE_NUMBER.Equals(p.name)) {
setLicenseeNumber(p.Value);
break;
}
}
}
continue;
}
if (!Constants.ValidationResult.VALIDATION_RESULT_TYPE.Equals(i.type))
{
continue;
}
Composition pmValidateProperties = new Composition();
String productModuleNumber = null;
if (i.property != null)
{
foreach (property p in i.property)
{
switch (p.name)
{
case Constants.ProductModule.PRODUCT_MODULE_NUMBER:
productModuleNumber = p.Value;
break;
default:
pmValidateProperties.put(p.name, p.Value);
break;
}
}
}
if (i.list != null)
{
foreach (list l in i.list)
{
pmValidateProperties.properties.Add(l.name, convertFromList(l));
}
}
if (productModuleNumber == null)
{
throw new NetLicensingException(String.Format("Validation item does not contain property '{0}'", Constants.ProductModule.PRODUCT_MODULE_NUMBER));
}
setProductModuleValidation(productModuleNumber, pmValidateProperties);
}
}
private Composition convertFromList(list l)
{
Composition result = new Composition();
if (l.property != null)
{
foreach (property p in l.property)
{
result.put(p.name, p.Value);
}
}
if (l.list1 != null)
{
foreach (list l1 in l.list1)
{
result.properties.Add(l1.name, convertFromList(l1));
}
}
return result;
}
public Dictionary<String, Composition> getValidations()
{
return validations;
}
public DateTime getTtl ()
{
return ttl;
}
public Composition getProductModuleValidation(String productModuleNumber)
{
try
{
return validations[productModuleNumber];
}
catch (KeyNotFoundException)
{
return new Composition();
}
}
internal void setProductModuleValidation(String productModuleNumber, Composition productModuleValidaton)
{
validations.Add(productModuleNumber, productModuleValidaton);
}
public String getLicenseeNumber() {
return licenseeNumber;
}
internal void setLicenseeNumber(String licenseeNumber) {
this.licenseeNumber = licenseeNumber;
}
/// <summary>
/// Converts ValidationResult object to a String representation. See NetLicensingAPI JavaDoc for details:
/// https://go.netlicensing.io/javadoc/v2/com/labs64/netlicensing/domain/vo/ValidationResult.html
/// </summary>
/// <returns></returns>
public override String ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append(Constants.ValidationResult.VALIDATION_RESULT_TYPE);
sb.Append("[");
bool first = true;
foreach (KeyValuePair<String, Composition> validationEntry in getValidations())
{
if (first) {
first = false;
} else {
sb.Append(", ");
}
sb.Append(Constants.ProductModule.TYPE_NAME);
sb.Append("<");
sb.Append(validationEntry.Key);
sb.Append(">");
sb.Append(validationEntry.Value.ToString());
}
sb.Append("]");
return sb.ToString();
}
}
public class Composition
{
public Dictionary<String, Composition> properties { get; private set; }
public String value { get; set; }
public Composition() // list
{
properties = new Dictionary<String, Composition>();
value = null;
}
public Composition(String value) // property
{
properties = null;
this.value = value;
}
public void put(String key, String value) {
properties.Add(key, new Composition(value));
}
public Composition this[String key]
{
get
{
return properties[key];
}
}
public new String ToString()
{
StringBuilder sb = new StringBuilder();
if (value == null) // list
{
sb.Append("{");
if (properties == null)
{
sb.Append("<null>");
}
else
{
bool first = true;
foreach (KeyValuePair<String, Composition> prop in properties)
{
if (first)
first = false;
else
sb.Append(", ");
sb.Append(prop.Key);
sb.Append("=");
sb.Append(prop.Value.ToString());
}
}
sb.Append("}");
}
else
{
sb.Append(value);
}
return sb.ToString();
}
}
}