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