Version 11.1 by Robin Huisman on 2023/05/23 13:18

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