Version 6.4 by Robert Jan Daams on 2022/08/23 11:15

Show last authors
1 (% class="jumbotron" %)
2 (((
3 (% class="container" %)
4 (((
5 To connect with the TerraIndex database to retreive projects from or upload new projects, you can connect to a webservice. This webservice provides Exports and enables these export with changes to be uploaded again.
6
7 There are two steps to consider, it’s possible to request an exact projectcode export or you could request all changed projects from a timestamp. This last option is an additional Webservice call that is very easy to use. It will tell you what Project to download because they have changes since a timestamp. This Timestamp could be your last donwload moment.
8 )))
9 )))
10
11 {{box title="**Contents**"}}
12 [[image:data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==||height="15" role="presentation" title="Click and drag to move" width="15"]]
13 {{/box}}
14
15 (% class="row" %)
16 (((
17 (% class="col-xs-12 col-sm-8" %)
18 (((
19 == Changelog ==
20
21 === Update 2022-08-23 ===
22
23 As part of on-going efforts to improve performance and scalability, we have introduced a dedicated version of DataWS named DataWSExternals.  This new service should be used for external API consumers.
24
25 | |**URL**|
26 |**Old**|{{code language="none"}}https://web.terraindex.com/DataWS/{{/code}}|[[https:~~/~~/web.terraindex.com/DataWS/ITWImportExportServiceASMX_V1_0.asmx?wsdl>>https://web.terraindex.com/DataWS/ITWImportExportServiceASMX_V1_0.asmx?wsdl]]
27 |**New**|​{{code language="none"}}https://web.terraindex.com/DataWSExternals/{{/code}}|[[https:~~/~~/web.terraindex.com/DataWSExternals/ITWImportExportServiceASMX_V1_0.asmx?wsdl>>https://web.terraindex.com/DataWSExternals/ITWImportExportServiceASMX_V1_0.asmx?wsdl]]
28
29 == ==
30
31 == 1. Retreive all changed project from TerraIndex ==
32
33 To retreive all changed project from the TerraIndex database since a specific timestamp, there is a webservice call you can do. This will return all project rows that have changes since the timestamp you send within the request.
34 This way you only download projects that have changes, and it will not request project that are not needed, so it won’t keep our servers busy with exports that are not necessary.
35
36 To start connecting this webservice, you should use this URL:
37 [[https:~~/~~/web.terraindex.com/DataWSExternals/ITWDataRestService_V1_0/GetProjectsJSON>>https://web.terraindex.com/DataWSExternals/ITWDataRestService_V1_0/GetProjectsJSON]]
38
39 Fill the **Body **of a **POST **HTTP call with:
40
41 {{code language="JSON" layout="LINENUMBERS"}}
42 {
43 "Authorisation": {
44 "Username": "username",
45 "Password": "password",
46 "Licensenumber": 123,
47 "ApplicationCode": 12,
48 "Language": "en"
49 },
50 "LanguageCode": "en",
51 "WebserviceVersion": "1.0",
52 "SearchFilter": "",
53 "ArchiveID": 0,
54 "PageSize": 30,
55 "LastRowNR": 0,
56 "OrderPreviewBy": 2,
57 "FromDateContentLastChanged": "2019-04-01T00:00:00"
58 }
59 {{/code}}
60
61
62 Set the correct values for:
63
64 * (% class="mark" %)username(%%); as the username in TerraIndex
65 * (% class="mark" %)password(%%); as the username in TerraIndex
66 * (% class="mark" %)LicenseNumber(%%); as your companies license number
67 * (% class="mark" %)ApplicationCode(%%); as provided by TerraIndex to you, if not provided, request one at: service@terraindex.com
68 * (% class="mark" %)PageSize (%%)is in the example set to 30, it will return max 30 projects if possible. This can be upgraded to more records, but it will take longer.
69 * (% class="mark" %)FromDateContentLastChanged(%%); set the correct timestamp of your last call, it will return all projects that have been changed since that timestamp.
70 * (% class="mark" %)SearchFilter(%%); set a part of the projectcode in this field and it will search for projectcodes with this specific text part in it. It will add wildcars in front and at the end of the searchfilter automatically. So not needed to provide. The searchfilter will be applied on three columns: Project Code, Project Name and Project location City name.
71 * (% class="mark" %)LastRowNR(%%); fill default with zero/'0'. If your project isn’t in the first page of 30, you could use this field for lazy loading. Call the webservice with in the request the LastRowNR = 30, and you will receive project rows 31 t/m 60 (when the pagesize is 30).
72
73 Fill the header with:
74
75 {{code language="none"}}
76 application/json
77 {{/code}}
78
79
80 You will receive a reponse like this:
81
82 {{code language="JSON" layout="LINENUMBERS"}}
83 [
84 {
85 "PrID": 242,
86 "PrCode": "2018-010-DEMO",
87 "PrName": "TU Delft, the Netherlands",
88 "PrTypeCode": null,
89 "PrLocName": null,
90 "PrLocCity": null,
91 "PrLeaderCode": "Consult",
92 "PrConsultancyFirm": "TerraIndex",
93 "PrFieldworkFirm": "TerraIndex",
94 "PrPrincipalName": null,
95 "PrDateLastChanged": "2018-08-31T11:12:50.45",
96 "RowNumber": 1,
97 "Uitwissel": 0,
98 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
99 },
100 {
101 "PrID": 241,
102 "PrCode": "2018-009-DEMO",
103 "PrName": "TU Delft, the Netherlands",
104 "PrTypeCode": null,
105 "PrLocName": null,
106 "PrLocCity": null,
107 "PrLeaderCode": "Consult",
108 "PrConsultancyFirm": "TerraIndex",
109 "PrFieldworkFirm": "TerraIndex",
110 "PrPrincipalName": null,
111 "PrDateLastChanged": "2018-08-31T11:12:48.603",
112 "RowNumber": 2,
113 "Uitwissel": 0,
114 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
115 },
116 {
117 "PrID": 240,
118 "PrCode": "2018-008-DEMO",
119 "PrName": "TU Delft, the Netherlands",
120 "PrTypeCode": null,
121 "PrLocName": null,
122 "PrLocCity": null,
123 "PrLeaderCode": "Consult",
124 "PrConsultancyFirm": "TerraIndex",
125 "PrFieldworkFirm": "TerraIndex",
126 "PrPrincipalName": null,
127 "PrDateLastChanged": "2018-08-31T11:12:46.46",
128 "RowNumber": 3,
129 "Uitwissel": 0,
130 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
131 },
132 {
133 "PrID": 239,
134 "PrCode": "2018-007-DEMO",
135 "PrName": "TU Delft, the Netherlands",
136 "PrTypeCode": null,
137 "PrLocName": null,
138 "PrLocCity": null,
139 "PrLeaderCode": "Consult",
140 "PrConsultancyFirm": "TerraIndex",
141 "PrFieldworkFirm": "TerraIndex",
142 "PrPrincipalName": null,
143 "PrDateLastChanged": "2018-08-31T11:12:44.853",
144 "RowNumber": 4,
145 "Uitwissel": 0,
146 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
147 },
148 {
149 "PrID": 238,
150 "PrCode": "2018-006-DEMO",
151 "PrName": "TU Delft, the Netherlands",
152 "PrTypeCode": null,
153 "PrLocName": null,
154 "PrLocCity": null,
155 "PrLeaderCode": "Consult",
156 "PrConsultancyFirm": "TerraIndex",
157 "PrFieldworkFirm": "TerraIndex",
158 "PrPrincipalName": null,
159 "PrDateLastChanged": "2018-08-31T11:12:43.033",
160 "RowNumber": 5,
161 "Uitwissel": 0,
162 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
163 },
164 {
165 "PrID": 237,
166 "PrCode": "2018-005-DEMO",
167 "PrName": "TU Delft, the Netherlands",
168 "PrTypeCode": null,
169 "PrLocName": null,
170 "PrLocCity": null,
171 "PrLeaderCode": "Consult",
172 "PrConsultancyFirm": "TerraIndex",
173 "PrFieldworkFirm": "TerraIndex",
174 "PrPrincipalName": null,
175 "PrDateLastChanged": "2018-08-31T11:12:41.273",
176 "RowNumber": 6,
177 "Uitwissel": 0,
178 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
179 },
180 {
181 "PrID": 236,
182 "PrCode": "2018-004-DEMO",
183 "PrName": "TU Delft, the Netherlands",
184 "PrTypeCode": null,
185 "PrLocName": null,
186 "PrLocCity": null,
187 "PrLeaderCode": "Consult",
188 "PrConsultancyFirm": "TerraIndex",
189 "PrFieldworkFirm": "TerraIndex",
190 "PrPrincipalName": null,
191 "PrDateLastChanged": "2018-08-31T11:12:39.57",
192 "RowNumber": 7,
193 "Uitwissel": 0,
194 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
195 },
196 {
197 "PrID": 235,
198 "PrCode": "2018-003-DEMO",
199 "PrName": "TU Delft, the Netherlands",
200 "PrTypeCode": null,
201 "PrLocName": null,
202 "PrLocCity": null,
203 "PrLeaderCode": "Consult",
204 "PrConsultancyFirm": "TerraIndex",
205 "PrFieldworkFirm": "TerraIndex",
206 "PrPrincipalName": null,
207 "PrDateLastChanged": "2018-08-31T11:12:37.77",
208 "RowNumber": 8,
209 "Uitwissel": 0,
210 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
211 },
212 {
213 "PrID": 234,
214 "PrCode": "2018-002-DEMO",
215 "PrName": "TU Delft, the Netherlands",
216 "PrTypeCode": null,
217 "PrLocName": null,
218 "PrLocCity": null,
219 "PrLeaderCode": "Consult",
220 "PrConsultancyFirm": "TerraIndex",
221 "PrFieldworkFirm": "TerraIndex",
222 "PrPrincipalName": null,
223 "PrDateLastChanged": "2018-08-31T11:12:36.02",
224 "RowNumber": 9,
225 "Uitwissel": 0,
226 "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
227 },
228 {
229 "PrID": 233,
230 "PrCode": "2018-001-DEMO",
231 "PrName": "TU Delft, the Netherlands",
232 "PrTypeCode": null,
233 "PrLocName": null,
234 "PrLocCity": null,
235 "PrLeaderCode": "Consult",
236 "PrConsultancyFirm": "TerraIndex",
237 "PrFieldworkFirm": "TerraIndex",
238 "PrPrincipalName": null,
239 "PrDateLastChanged": "2018-08-31T11:12:30.037",
240 "RowNumber": 10,
241 "Uitwissel": 0,
242 "geometryWKT_WGS84": "POINT (4.3694882989839243 52.00722295311251)"
243 }
244 ]
245 {{/code}}
246
247 The **PrID **can be used as **ProjectID **in the next call to get the actual project xml file export.
248
249
250 == 2. Retreive the project export from TerraIndex ==
251
252 To request the export from TerraIndex we have a SOAP webservice. This webservice is called the ExportService, and it will provide a full project in TerraIndex Format.
253 The format of the projectfile is documentated here: [[Documentation TerraIndex Export format - dsFieldProject.xsd>>Implementation documentation.Documentation TerraIndex Export format - dsFieldProject\.xsd.WebHome]]
254
255 To start connecting this webservice, you should use this URL of the Import Export Webservice:
256 [[https:~~/~~/web.terraindex.com/DataWSExternals/ITWImportExportServiceASMX_V1_0.asmx>>https://web.terraindex.com/DataWSExternals/ITWImportExportServiceASMX_V1_0.asmx]]
257
258 With this URL many IDE’s can create a proxy for you, just by providing the URL. Once this proxy is created, you will have a few classes looking like the call in the image below.
259
260 [[image:image-20200108-123431.png]]
261
262 The image is created with WebserviceStudio to visualise the SOAP call to send to the webservice.
263 This is the explanation of each number inside the image~:
264 1; The endpoint URL
265 2; Create the proxy based on the WSDL
266 3; Select the export call to see what it looks like
267 4; Fill the username + password of the TerraIndex user* to call the webservice with.
268 Also fill the license and the applicationCode. //(These two fields can be requested at the TerraIndex Servicedesk.)//
269 5; Fill the **ExportType **'**Export_FIELD_XML_v1_0_0**’. This export corresponds with dsFieldProject.xsd and is the best XML to connect TI with.
270 Create at least create 2 parameters as in the image. Beacause 2 parameters are needed.
271 //If JSON is prevered use: ExportType = 'Export_FIELD_JSON_v1_0_0'//
272 6; Fill the parameter with the FileName.
273 7; Fill the parameter with **projectID**. Instead of ‘ProjectID' it’s also possible to fill the parameter ‘ProjectCode'.
274 8; Send the request and wait for the reponse. In response field ‘ResultCode’ should be 'SUCCES’ when it all went OK. If not it will tell what went wrong.
275 9; The response field 'Filecontent’is filled if it went OK, and it contains XML you can serialize.
276 10; an extra parameter is added calles: **UseZipStream**. The result data is default Base64 encoded, if you add UseZipStream = true, the result string is GZIPSTREAMED Base64 encoded. **At the end of this page, we have added an class as code, to parse the base64 or ZIPStream Base64 to a normal string.**
277 *Username and password are known by each TI user and the application manager of your company can create new usernames.
278
279
280 **EXAMPLE CODE**
281
282 ExportType:
283 ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportType.Export_Field_XML_v1_0_0;
284
285 {{code language="C#" layout="LINENUMBERS"}}
286 [TestMethod] public void Export_FieldXml_Local() {
287 ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.TWImportExportServiceASMX_V1_0SoapClient client = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.TWImportExportServiceASMX_V1_0SoapClient();
288 ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportRequest req = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportRequest() {
289 AuthorisationRequest = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.AuthorisationRequest() {
290 Username = "xxxxx", Password = "xxxxx", Licensenumber = "x"
291 }, LanguageCode = "eng", WebserviceVersion = "1.0",
292 };
293 req.TypeOfExport = ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportType.Export_Field_XML_v1_0_0;
294 req.UseZipStream = true;
295 List < ExportParameter > paramsList = new List < ExportParameter > ();
296 paramsList.Add(new ExportParameter() {
297 ParameterType = ExportParameterType.FileName, StringValue = "Export"
298 });
299 paramsList.Add(new ExportParameter() {
300 ParameterType = ExportParameterType.ProjectID, FloatValue = 917
301 });
302 req.Parameters = paramsList;
303 try {
304 var result = client.Export(req);
305 if (result != null) {
306 if (result.ResultCode == ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportResultCode.Export_Succes) {
307 System.IO.File.WriteAllText(@ "C:\Temp\ExportTestField.xml", result.Files[0].FileContent);
308 System.IO.File.WriteAllText(@ "C:\Temp\ExportTestField.html", result.ExportLog);
309 } else {
310 throw new Exception(result.ResultCode.ToString() + " - " + result.ResultMessage);
311 }
312 }
313 } catch (Exception e) {
314 throw e;
315 }
316 }
317 {{/code}}
318
319 Example call
320
321 {{code language="none" layout="LINENUMBERS"}}
322 <soapenv:Envelope
323 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
324 xmlns:itw="https://wsterraindex.terraindex.com/ITWorks.TerraIndex/">
325 <soapenv:Header></soapenv:Header>
326 <soapenv:Body>
327 <itw:Export>
328 <itw:request>
329 <itw:AuthorisationRequest>
330 <itw:Username>USERNAME</itw:Username>
331 <itw:Password>PASSWORD</itw:Password>
332 <itw:Licensenumber>LICENSE</itw:Licensenumber>
333 <itw:ApplicationCode>APPCODE</itw:ApplicationCode>
334 </itw:AuthorisationRequest>
335 <itw:WebserviceVersion>1.0</itw:WebserviceVersion>
336 <itw:LanguageCode>nld</itw:LanguageCode>
337 <itw:UseCompression>true</itw:UseCompression>
338 <itw:TypeOfExport>Export_FIELD_XML_v1_0_0</itw:TypeOfExport>
339 <itw:Parameters>
340 <itw:ExportParameter>
341 <itw:ParameterType>FileName</itw:ParameterType>
342 <itw:StringValue>Export</itw:StringValue>
343 </itw:ExportParameter>
344 <itw:ExportParameter>
345 <itw:ParameterType>projectID</itw:ParameterType>
346 <itw:FloatValue>917</itw:FloatValue>
347 </itw:ExportParameter> -----
348 <itw:ExportParameter>
349 <itw:ParameterType>ProjectCode</itw:ParameterType>
350 <itw:StringValue>202020</itw:StringValue>
351 </itw:ExportParameter> ----
352 </itw:Parameters>
353 <itw:LogFormat>XML</itw:LogFormat>
354 <itw:UseZipStream>true</itw:UseZipStream>
355 </itw:request>
356 </itw:Export>
357 </soapenv:Body>
358 </soapenv:Envelope>
359 {{/code}}
360
361 Example response:
362
363 {{code language="none"}}
364 <soap:Envelope
365 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
366 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
367 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
368 <soap:Body>
369 <ExportResponse
370 xmlns="https://wsterraindex.terraindex.com/ITWorks.TerraIndex/">
371 <ExportResult>
372 <ResultCode>Export_Succes</ResultCode>
373 <TypeOfExport>Export_TI_v1_0_0</TypeOfExport>
374 <Files>
375 <File>
376 <FileName>917.xml</FileName>
377 <TypeOfFile>Field_XML_Compressed</TypeOfFile>
378 <FileContent>H4sIAAAAAAAEAFWRuZaqQABEP4hAGnAGggm6odlREFkkA2WRRRCBxv76YeYF70yFVXUqqBvgl4KQBzcZ8Aho2iqxdhxDSPDmNGjz9Z/weMa8/aimTAUeF42KgxRRzd3YaGfdXtvECEBvWafSNwf+dOsjVXpZUzs+lw/p3gBhuXQ5S8T3MdIBlxUQEam+LOVgVo4D8w4c2E8pEgp3haewcpQx1KQ41Z8DKWv16seaDLp3GABLuIKXK5Ucq31EfSXm0172YvG87hcbayYGdB1t0CbcuueLpU5UawgHSitFr564Aet5LeegD0/tocZDTvuIuc9Ja0tDFt/m7kZnomdVJc+2SkqBGXmTdPiiPzJa2OznLkX67p2PCNM7iHU11QbIilVkMDBVd0J8gK4Ams6ycJQagnww/SaxuiZ/EdS6DZ0cf17BIhUq87CSkQvxat/2dEG1xu94BoaeT7C8XR38/C1DZbpygwfW+gk8Z+Mgm3DDhAj8r6099Rj+5YNs5F3+5R5EUPmd6+EvYvj1Dd8o9lLwAQAA</FileContent>
379 </File>
380 <File>
381 <FileName>ProjectInfo.xml</FileName>
382 <TypeOfFile>Field_XML_Compressed</TypeOfFile>
383 <FileContent>H4sIAAAAAAAEAI1Qy5JDQAD8IAdj1/M4hJggDBnEbTxDsV7BxtdvNqm9bx+6urq7+tBEnw+qiuETCLrcTlst9Pajtb0soj7JeynztNIubHK9XZJOXoojN8dXpaxltOlOwAZzK033Edx7HWT1ZFVYNljpsT7iCVDbxb5tlmw3GhV7vgty5jqiGzWSYEvL7RCIQifzchIoMJnHz+fO17C4JAwA0hNRb247SR1ba8OunCV4ralK1rjwBhUAJ2pihopeuxqXIUecePETLhx8zT6IZX5GzafC0XHTrauISeyIM2+2g1PzEymRZrTtglKlsFYHXDKmoYTp+jw1zNDyAFZOTN9XHkuNGmU33905uipWMTsjm2ccm6+bxqk2xAjCf/z3BwS1j+qVqTjrlDGJziCIhC59CHwafeNgI8d3U4cQQ+VXSdXb+QGLuAuvrAEAAA==</FileContent>
384 </File>
385 </Files>
386 </ExportResult>
387 </ExportResponse>
388 </soap:Body>
389 </soap:Envelope>
390 {{/code}}
391
392
393 == Zip Stream class ==
394
395 If needed, this is the Zip Stream class you can use to extract the zipstream as used above:
396
397 {{code language="Csharp" layout="LINENUMBERS"}}
398 /// <summary>
399 /// Helper class for compress en decompress of file data
400 /// </summary>
401 public static class ZipStreamHelper {
402 #region Compress and encode
403 /// <summary>
404 /// Comprimeer een string en geeft deze terug in Base64 string.
405 /// </summary>
406 /// <param name="content">filecontent</param>
407 /// <returns>gecomprimeerde string</returns>
408 public static string CompressToBase64String(string content) {
409 //string to byte[]
410 byte[] contentArray = stringToByteArray(content);
411 // Compress
412 byte[] compressed = Compress(contentArray);
413 return base64_encode(compressed);
414 }
415
416 /// <summary>
417 /// Zet een string om naar een ByteArray
418 /// </summary>
419 /// <param name="content">filecontent</param>
420 /// <returns>ByteArray</returns>
421 public static byte[] stringToByteArray(string content) {
422 System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
423 return encoding.GetBytes(content);
424 }
425
426 /// <summary>
427 /// comprimeer een ByteArray
428 /// </summary>
429 /// <param name="data">filedata als ByteArray</param>
430 /// <returns>gecomprimeerde ByteArray</returns>
431 public static byte[] Compress(byte[] data) {
432 using(var compressedStream = new MemoryStream())
433 using(var zipStream = new GZipStream(compressedStream, CompressionMode.Compress)) {
434 zipStream.Write(data, 0, data.Length);
435 zipStream.Close();
436 return compressedStream.ToArray();
437 }
438 }
439
440 /// <summary>
441 /// Zet een ByteArray om naar een Base64 string
442 /// </summary>
443 /// <param name="data">gecomprimeerde ByteArray</param>
444 /// <returns>Base 64 string</returns>
445 public static string base64_encode(byte[] data) {
446 if (data == null)
447 return string.Empty;
448 return Convert.ToBase64String(data);
449 }
450
451 /// <summary>
452 /// Zet een string om naar een Base64 string
453 /// </summary>
454 /// <param name="data">string</param>
455 /// <returns>Base 64 string</returns>
456 public static string string_base64_encode(string data) {
457 if (string.IsNullOrEmpty(data))
458 return string.Empty;
459
460 //string to byte[]
461 byte[] contentArray = stringToByteArray(data);
462 return base64_encode(contentArray);
463 }
464 #endregion
465
466 #region Decompress and decode
467 // Decode and decompress
468 /// <summary>
469 /// Decomprimeer een Base64 string naar een string
470 /// </summary>
471 /// <param name="contentBase64">GZIP Base64 string</param>
472 /// <returns>string</returns>
473 public static string DecompressBase64StringToString(string contentBase64) {
474 // Decompress
475 byte[] decoded = base64_decode(contentBase64);
476 byte[] decompressed = Decompress(decoded);
477
478 return byteArrayTostring(decompressed);
479 }
480
481 /// <summary>
482 /// Zet een ByteArray om in een normale string
483 /// </summary>
484 /// <param name="data">ByteArray</param>
485 /// <returns>string</returns>
486 public static string byteArrayTostring(byte[] data) {
487 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
488 return enc.GetString(data);
489 }
490
491 /// <summary>
492 /// Zet een Base64 string om naar een ByteArray
493 /// </summary>
494 /// <param name="encodedData">Base64 string</param>
495 /// <returns>gecomprimeerde ByteArray</returns>
496 public static byte[] base64_decode(string encodedData) {
497 byte[] encodedDataAsBytes = Convert.FromBase64String(encodedData);
498 return encodedDataAsBytes;
499 }
500
501 /// <summary>
502 /// Zet een gecomprimeerde ByteArray om in een ByteArray
503 /// </summary>
504 /// <param name="data">gecomprimeerde ByteArray</param>
505 /// <returns>ByteArray (gedecomprimeerd)</returns>
506 public static byte[] Decompress(byte[] data) {
507 using(var compressedStream = new MemoryStream(data))
508 using(var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
509 using(var resultStream = new MemoryStream()) {
510 var buffer = new byte[4096];
511 int read;
512
513 while ((read = zipStream.Read(buffer, 0, buffer.Length)) > 0) {
514 resultStream.Write(buffer, 0, read);
515 }
516
517 return resultStream.ToArray();
518 }
519 }
520 #endregion
521 }
522 {{/code}}
523 )))
524
525
526 (% class="col-xs-12 col-sm-4" %)
527 (((
528
529 )))
530 )))