Version 6.7 by Robert Jan Daams on 2022/08/24 15:16

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 [[https:~~/~~/web.terraindex.com/DataWSExternals/ITWImportExportServiceASMX_V1_0.asmx>>https://web.terraindex.com/DataWSExternals/ITWImportExportServiceASMX_V1_0.asmx]]
265
266 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.
267
268 [[image:image-20200108-123431.png]]
269
270 The image is created with WebserviceStudio to visualise the SOAP call to send to the webservice.
271 This is the explanation of each number inside the image~:
272 1; The endpoint URL
273 2; Create the proxy based on the WSDL
274 3; Select the export call to see what it looks like
275 4; Fill the username + password of the TerraIndex user* to call the webservice with.
276 Also fill the license and the applicationCode. //(These two fields can be requested at the TerraIndex Servicedesk.)//
277 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.
278 Create at least create 2 parameters as in the image. Beacause 2 parameters are needed.
279 //If JSON is prevered use: ExportType = 'Export_FIELD_JSON_v1_0_0'//
280 6; Fill the parameter with the FileName.
281 7; Fill the parameter with **projectID**. Instead of ‘ProjectID' it’s also possible to fill the parameter ‘ProjectCode'.
282 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.
283 9; The response field 'Filecontent’is filled if it went OK, and it contains XML you can serialize.
284 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.**
285 *Username and password are known by each TI user and the application manager of your company can create new usernames.
286
287
288 **EXAMPLE CODE**
289
290 ExportType:
291 ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportType.Export_Field_XML_v1_0_0;
292
293 {{code language="C#" layout="LINENUMBERS"}}
294 [TestMethod] public void Export_FieldXml_Local() {
295 ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.TWImportExportServiceASMX_V1_0SoapClient client = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.TWImportExportServiceASMX_V1_0SoapClient();
296 ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportRequest req = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportRequest() {
297 AuthorisationRequest = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.AuthorisationRequest() {
298 Username = "xxxxx", Password = "xxxxx", Licensenumber = "x"
299 }, LanguageCode = "eng", WebserviceVersion = "1.0",
300 };
301 req.TypeOfExport = ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportType.Export_Field_XML_v1_0_0;
302 req.UseZipStream = true;
303 List < ExportParameter > paramsList = new List < ExportParameter > ();
304 paramsList.Add(new ExportParameter() {
305 ParameterType = ExportParameterType.FileName, StringValue = "Export"
306 });
307 paramsList.Add(new ExportParameter() {
308 ParameterType = ExportParameterType.ProjectID, FloatValue = 917
309 });
310 req.Parameters = paramsList;
311 try {
312 var result = client.Export(req);
313 if (result != null) {
314 if (result.ResultCode == ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportResultCode.Export_Succes) {
315 System.IO.File.WriteAllText(@ "C:\Temp\ExportTestField.xml", result.Files[0].FileContent);
316 System.IO.File.WriteAllText(@ "C:\Temp\ExportTestField.html", result.ExportLog);
317 } else {
318 throw new Exception(result.ResultCode.ToString() + " - " + result.ResultMessage);
319 }
320 }
321 } catch (Exception e) {
322 throw e;
323 }
324 }
325 {{/code}}
326
327 Example call
328
329 {{code language="none" layout="LINENUMBERS"}}
330 <soapenv:Envelope
331 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
332 xmlns:itw="https://wsterraindex.terraindex.com/ITWorks.TerraIndex/">
333 <soapenv:Header></soapenv:Header>
334 <soapenv:Body>
335 <itw:Export>
336 <itw:request>
337 <itw:AuthorisationRequest>
338 <itw:Username>USERNAME</itw:Username>
339 <itw:Password>PASSWORD</itw:Password>
340 <itw:Licensenumber>LICENSE</itw:Licensenumber>
341 <itw:ApplicationCode>APPCODE</itw:ApplicationCode>
342 </itw:AuthorisationRequest>
343 <itw:WebserviceVersion>1.0</itw:WebserviceVersion>
344 <itw:LanguageCode>nld</itw:LanguageCode>
345 <itw:UseCompression>true</itw:UseCompression>
346 <itw:TypeOfExport>Export_FIELD_XML_v1_0_0</itw:TypeOfExport>
347 <itw:Parameters>
348 <itw:ExportParameter>
349 <itw:ParameterType>FileName</itw:ParameterType>
350 <itw:StringValue>Export</itw:StringValue>
351 </itw:ExportParameter>
352 <itw:ExportParameter>
353 <itw:ParameterType>projectID</itw:ParameterType>
354 <itw:FloatValue>917</itw:FloatValue>
355 </itw:ExportParameter> -----
356 <itw:ExportParameter>
357 <itw:ParameterType>ProjectCode</itw:ParameterType>
358 <itw:StringValue>202020</itw:StringValue>
359 </itw:ExportParameter> ----
360 </itw:Parameters>
361 <itw:LogFormat>XML</itw:LogFormat>
362 <itw:UseZipStream>true</itw:UseZipStream>
363 </itw:request>
364 </itw:Export>
365 </soapenv:Body>
366 </soapenv:Envelope>
367 {{/code}}
368
369 Example response:
370
371 {{code language="none"}}
372 <soap:Envelope
373 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
374 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
375 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
376 <soap:Body>
377 <ExportResponse
378 xmlns="https://wsterraindex.terraindex.com/ITWorks.TerraIndex/">
379 <ExportResult>
380 <ResultCode>Export_Succes</ResultCode>
381 <TypeOfExport>Export_TI_v1_0_0</TypeOfExport>
382 <Files>
383 <File>
384 <FileName>917.xml</FileName>
385 <TypeOfFile>Field_XML_Compressed</TypeOfFile>
386 <FileContent>H4sIAAAAAAAEAFWRuZaqQABEP4hAGnAGggm6odlREFkkA2WRRRCBxv76YeYF70yFVXUqqBvgl4KQBzcZ8Aho2iqxdhxDSPDmNGjz9Z/weMa8/aimTAUeF42KgxRRzd3YaGfdXtvECEBvWafSNwf+dOsjVXpZUzs+lw/p3gBhuXQ5S8T3MdIBlxUQEam+LOVgVo4D8w4c2E8pEgp3haewcpQx1KQ41Z8DKWv16seaDLp3GABLuIKXK5Ucq31EfSXm0172YvG87hcbayYGdB1t0CbcuueLpU5UawgHSitFr564Aet5LeegD0/tocZDTvuIuc9Ja0tDFt/m7kZnomdVJc+2SkqBGXmTdPiiPzJa2OznLkX67p2PCNM7iHU11QbIilVkMDBVd0J8gK4Ams6ycJQagnww/SaxuiZ/EdS6DZ0cf17BIhUq87CSkQvxat/2dEG1xu94BoaeT7C8XR38/C1DZbpygwfW+gk8Z+Mgm3DDhAj8r6099Rj+5YNs5F3+5R5EUPmd6+EvYvj1Dd8o9lLwAQAA</FileContent>
387 </File>
388 <File>
389 <FileName>ProjectInfo.xml</FileName>
390 <TypeOfFile>Field_XML_Compressed</TypeOfFile>
391 <FileContent>H4sIAAAAAAAEAI1Qy5JDQAD8IAdj1/M4hJggDBnEbTxDsV7BxtdvNqm9bx+6urq7+tBEnw+qiuETCLrcTlst9Pajtb0soj7JeynztNIubHK9XZJOXoojN8dXpaxltOlOwAZzK033Edx7HWT1ZFVYNljpsT7iCVDbxb5tlmw3GhV7vgty5jqiGzWSYEvL7RCIQifzchIoMJnHz+fO17C4JAwA0hNRb247SR1ba8OunCV4ralK1rjwBhUAJ2pihopeuxqXIUecePETLhx8zT6IZX5GzafC0XHTrauISeyIM2+2g1PzEymRZrTtglKlsFYHXDKmoYTp+jw1zNDyAFZOTN9XHkuNGmU33905uipWMTsjm2ccm6+bxqk2xAjCf/z3BwS1j+qVqTjrlDGJziCIhC59CHwafeNgI8d3U4cQQ+VXSdXb+QGLuAuvrAEAAA==</FileContent>
392 </File>
393 </Files>
394 </ExportResult>
395 </ExportResponse>
396 </soap:Body>
397 </soap:Envelope>
398 {{/code}}
399
400
401 == Zip Stream class ==
402
403 If needed, this is the Zip Stream class you can use to extract the zipstream as used above:
404
405 {{code language="Csharp" layout="LINENUMBERS"}}
406 /// <summary>
407 /// Helper class for compress en decompress of file data
408 /// </summary>
409 public static class ZipStreamHelper {
410 #region Compress and encode
411 /// <summary>
412 /// Comprimeer een string en geeft deze terug in Base64 string.
413 /// </summary>
414 /// <param name="content">filecontent</param>
415 /// <returns>gecomprimeerde string</returns>
416 public static string CompressToBase64String(string content) {
417 //string to byte[]
418 byte[] contentArray = stringToByteArray(content);
419 // Compress
420 byte[] compressed = Compress(contentArray);
421 return base64_encode(compressed);
422 }
423
424 /// <summary>
425 /// Zet een string om naar een ByteArray
426 /// </summary>
427 /// <param name="content">filecontent</param>
428 /// <returns>ByteArray</returns>
429 public static byte[] stringToByteArray(string content) {
430 System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
431 return encoding.GetBytes(content);
432 }
433
434 /// <summary>
435 /// comprimeer een ByteArray
436 /// </summary>
437 /// <param name="data">filedata als ByteArray</param>
438 /// <returns>gecomprimeerde ByteArray</returns>
439 public static byte[] Compress(byte[] data) {
440 using(var compressedStream = new MemoryStream())
441 using(var zipStream = new GZipStream(compressedStream, CompressionMode.Compress)) {
442 zipStream.Write(data, 0, data.Length);
443 zipStream.Close();
444 return compressedStream.ToArray();
445 }
446 }
447
448 /// <summary>
449 /// Zet een ByteArray om naar een Base64 string
450 /// </summary>
451 /// <param name="data">gecomprimeerde ByteArray</param>
452 /// <returns>Base 64 string</returns>
453 public static string base64_encode(byte[] data) {
454 if (data == null)
455 return string.Empty;
456 return Convert.ToBase64String(data);
457 }
458
459 /// <summary>
460 /// Zet een string om naar een Base64 string
461 /// </summary>
462 /// <param name="data">string</param>
463 /// <returns>Base 64 string</returns>
464 public static string string_base64_encode(string data) {
465 if (string.IsNullOrEmpty(data))
466 return string.Empty;
467
468 //string to byte[]
469 byte[] contentArray = stringToByteArray(data);
470 return base64_encode(contentArray);
471 }
472 #endregion
473
474 #region Decompress and decode
475 // Decode and decompress
476 /// <summary>
477 /// Decomprimeer een Base64 string naar een string
478 /// </summary>
479 /// <param name="contentBase64">GZIP Base64 string</param>
480 /// <returns>string</returns>
481 public static string DecompressBase64StringToString(string contentBase64) {
482 // Decompress
483 byte[] decoded = base64_decode(contentBase64);
484 byte[] decompressed = Decompress(decoded);
485
486 return byteArrayTostring(decompressed);
487 }
488
489 /// <summary>
490 /// Zet een ByteArray om in een normale string
491 /// </summary>
492 /// <param name="data">ByteArray</param>
493 /// <returns>string</returns>
494 public static string byteArrayTostring(byte[] data) {
495 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
496 return enc.GetString(data);
497 }
498
499 /// <summary>
500 /// Zet een Base64 string om naar een ByteArray
501 /// </summary>
502 /// <param name="encodedData">Base64 string</param>
503 /// <returns>gecomprimeerde ByteArray</returns>
504 public static byte[] base64_decode(string encodedData) {
505 byte[] encodedDataAsBytes = Convert.FromBase64String(encodedData);
506 return encodedDataAsBytes;
507 }
508
509 /// <summary>
510 /// Zet een gecomprimeerde ByteArray om in een ByteArray
511 /// </summary>
512 /// <param name="data">gecomprimeerde ByteArray</param>
513 /// <returns>ByteArray (gedecomprimeerd)</returns>
514 public static byte[] Decompress(byte[] data) {
515 using(var compressedStream = new MemoryStream(data))
516 using(var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
517 using(var resultStream = new MemoryStream()) {
518 var buffer = new byte[4096];
519 int read;
520
521 while ((read = zipStream.Read(buffer, 0, buffer.Length)) > 0) {
522 resultStream.Write(buffer, 0, read);
523 }
524
525 return resultStream.ToArray();
526 }
527 }
528 #endregion
529 }
530 {{/code}}
531 )))
532
533
534 (% class="col-xs-12 col-sm-4" %)
535 (((
536
537 )))
538 )))