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