Version 7.1 by Robin Huisman on 2022/08/24 17:07

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