Version 6.8 by Robert Jan Daams on 2022/08/24 15:17

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