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