From a73761c2336f4e71865cf77de30f6b125b1cfba3 Mon Sep 17 00:00:00 2001 From: "d.breimaier" Date: Tue, 12 Sep 2023 12:19:43 +0200 Subject: [PATCH] Bugfix ATEZ und Digicust --- SDL/SDL.vbproj | 2 +- .../DATENSERVER/cDATENSERVER.vb | 2 +- .../ATEZ/VERAG_OUT_ATEZ_IN/cATEZ_NCTS_IN.vb | 23 +- .../Schnittstellen/Digicast/cDigicustAPI.vb | 493 ++++++++++++++---- 4 files changed, 403 insertions(+), 117 deletions(-) diff --git a/SDL/SDL.vbproj b/SDL/SDL.vbproj index cc67c7dc..77deaed3 100644 --- a/SDL/SDL.vbproj +++ b/SDL/SDL.vbproj @@ -90,7 +90,7 @@ false - SDL_TemporaryKey.pfx + Test.pfx diff --git a/VERAG_PROG_ALLGEMEIN/DATENSERVER/cDATENSERVER.vb b/VERAG_PROG_ALLGEMEIN/DATENSERVER/cDATENSERVER.vb index 593c17ae..2fe6fb56 100644 --- a/VERAG_PROG_ALLGEMEIN/DATENSERVER/cDATENSERVER.vb +++ b/VERAG_PROG_ALLGEMEIN/DATENSERVER/cDATENSERVER.vb @@ -121,7 +121,7 @@ Public Class cDATENSERVER Dim top = "" If TopMax > 0 Then top = " TOP (" & TopMax & ") " 'MsgBox("SELECT * FROM tblDatenarchiv WHERE da_KundenNr = '" & Me.da_KundenNr & "' And da_kategorie = '" & Me.da_kategorie & "' And da_ordner ='" & Me.da_ordner & "' AND da_uOrdner1= '" & Me.da_uOrdner1 & "' AND da_uOrdner2= '" & Me.da_uOrdner2 & "' AND da_uOrdner3= '" & Me.da_uOrdner3 & "' AND da_name='" & Me.da_name & "' ") - Using cmd As New SqlCommand("SELECT " & TopMax & " * FROM tblDatenarchiv WHERE da_KundenNr = @da_KundenNr AND da_kategorie = @da_kategorie AND da_ordner=@da_ordner AND da_uOrdner1= @da_uOrdner1 AND da_uOrdner2= @da_uOrdner2 AND da_uOrdner3= @da_uOrdner3 AND da_name=@da_name ", conn) + Using cmd As New SqlCommand("SELECT " & top & " * FROM tblDatenarchiv WHERE da_KundenNr = @da_KundenNr AND da_kategorie = @da_kategorie AND da_ordner=@da_ordner AND da_uOrdner1= @da_uOrdner1 AND da_uOrdner2= @da_uOrdner2 AND da_uOrdner3= @da_uOrdner3 AND da_name=@da_name ", conn) cmd.Parameters.AddWithValue("@da_KundenNr", Me.da_KundenNr) ' cmd.Parameters.AddWithValue("@da_vorlage", Me.da_vorlage) cmd.Parameters.AddWithValue("@da_kategorie", Me.da_kategorie) diff --git a/VERAG_PROG_ALLGEMEIN/Schnittstellen/ATEZ/VERAG_OUT_ATEZ_IN/cATEZ_NCTS_IN.vb b/VERAG_PROG_ALLGEMEIN/Schnittstellen/ATEZ/VERAG_OUT_ATEZ_IN/cATEZ_NCTS_IN.vb index e4bee8bb..ab291b66 100644 --- a/VERAG_PROG_ALLGEMEIN/Schnittstellen/ATEZ/VERAG_OUT_ATEZ_IN/cATEZ_NCTS_IN.vb +++ b/VERAG_PROG_ALLGEMEIN/Schnittstellen/ATEZ/VERAG_OUT_ATEZ_IN/cATEZ_NCTS_IN.vb @@ -607,10 +607,29 @@ Public Class cATEZ_NCTS_IN 'rest.DebugMode = True rest.PercentDoneOnSend = True - rest.IdleTimeoutMs = 30000 + rest.IdleTimeoutMs = 60000 + + + success = rest.SendReqSb("POST", "/api/integrations/verag", sbRequestBody) + + Dim responseStatusCode = rest.ReadResponseHeader() + If (responseStatusCode < 0) Then + For i = 0 To 15 'Versuche den Header 16x abzufragen (funktioniert ab und zu nicht). + responseStatusCode = rest.ReadResponseHeader() + If responseStatusCode > 0 Then Exit For + Thread.Sleep(3000) + i = i + 1 + Next + + If rest.ResponseStatusCode <> 200 Then + MsgBox(rest.LastErrorText) + Return False + End If + + End If Dim sbResponseBody As New Chilkat.StringBuilder - success = rest.FullRequestSb("POST", "/api/integrations/verag", sbRequestBody, sbResponseBody) + rest.ReadRespSb(sbResponseBody) If (rest.LastMethodSuccess <> True) Then Debug.WriteLine(rest.LastErrorText) diff --git a/VERAG_PROG_ALLGEMEIN/Schnittstellen/Digicast/cDigicustAPI.vb b/VERAG_PROG_ALLGEMEIN/Schnittstellen/Digicast/cDigicustAPI.vb index 9ef67502..32efbade 100644 --- a/VERAG_PROG_ALLGEMEIN/Schnittstellen/Digicast/cDigicustAPI.vb +++ b/VERAG_PROG_ALLGEMEIN/Schnittstellen/Digicast/cDigicustAPI.vb @@ -1,16 +1,22 @@ -Imports System.Data.SqlClient +Imports System.ComponentModel.Design +Imports System.Data.SqlClient Imports System.Net Imports System.Reflection +Imports System.ServiceModel.Security Imports System.Threading +Imports System.Windows.Forms +Imports System.Windows.Forms.VisualStyles.VisualStyleElement Imports Chilkat +Imports iTextSharp.text Imports Newtonsoft.Json.Linq +Imports Org.BouncyCastle.Bcpg Imports VERAG_PROG_ALLGEMEIN.cCreditSafeAPI -Public Class cDigicust +Public Class cDigicustSessions Public Property session_Id As Integer Public Property token As String - Public Property datetime As DateTime + Public Property datetime As DateTime = Now() Public Property refresh_token As String Public Property token_validuntil As DateTime @@ -35,8 +41,8 @@ Public Class cDigicust End Sub Sub New(token As String, refreshtoken As String, timestamp As DateTime) - token = Me.token - refreshtoken = Me.refresh_token + Me.token = token + Me.refresh_token = refreshtoken token_validuntil = timestamp SAVE() End Sub @@ -45,7 +51,7 @@ Public Class cDigicust Public Function SAVE(Optional errHinweis = "") As Boolean Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList() - Dim sqlstr = " BEGIN " & getInsertCmd() & " END " & + Dim sqlstr = " BEGIN TRAN " & getInsertCmd() & " commit tran " Dim IdTMP = session_Id @@ -108,11 +114,207 @@ Public Class cDigicust End Class +Public Class cDigicustSettings + Public Property Id As Integer + Public Property customerId As String + Public Property projectId As String + Public Property executionStrategyId As String + Public Property validUntil As DateTime + Public Property valid As Boolean + Public Property companyId As Integer + Public Property description As String + + Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL + + Public hasEntry As Boolean + + Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) + Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) + + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Id", Id, , True, True)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("customerId", customerId)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("projectId", projectId)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("executionStrategyId", executionStrategyId)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("validUntil", validUntil)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("valid", valid)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("companyId", companyId)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("description", description)) + Return list + End Function + + Sub New(id) + Me.Id = id + LOAD() + End Sub + + + Public Sub LOAD() + Try + hasEntry = False + Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL() + Using cmd As New SqlCommand("SELECT * FROM tblDigicust_Settings where Id = @Id ", conn) + cmd.Parameters.AddWithValue("@Id", Id) + Dim dr = cmd.ExecuteReader() + + If dr.Read Then + For Each li In getParameterList() + Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable) + + If dr.Item(li.Text) Is DBNull.Value Then + propInfo.SetValue(Me, Nothing) + Else + propInfo.SetValue(Me, dr.Item(li.Text)) + End If + + Next + hasEntry = True + End If + dr.Close() + End Using + End Using + Catch ex As Exception + VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) + + End Try + End Sub + +End Class + +Public Class cDigicustSendungen + + Public Property Id As Integer + Public Property reference As String + Public Property digicustId As String + Public Property status As String + Public Property createdAt As DateTime + Public Property modifiedAt As DateTime + Public Property avisoId As Integer + Public Property uploadedDocuments As Integer + Public Property projectId As String + Public Property companyId As String + + + Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL + + Public hasEntry As Boolean + + Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) + Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) + + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Id", Id, , True, True)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("reference", reference)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("digicustId", digicustId)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("status", status)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("createdAt", createdAt)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("modifiedAt", modifiedAt)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("avisoId", avisoId)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("uploadedDocuments", uploadedDocuments)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("projectId", projectId)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("companyId", companyId)) + + Return list + End Function + + Sub New() + + End Sub + + Sub New(id As Integer) + Me.Id = id + LOAD() + End Sub + + Public Function SAVE(Optional errHinweis = "") As Boolean + Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList() + + + Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblDigicust_Sendungen WITH(updlock,serializable) WHERE Id=@Id) " & + " BEGIN " & getUpdateCmd() & " END " & + " Else " & + " BEGIN " & getInsertCmd() & " END " & + " commit tran " + + Dim IdTMP = Id + IdTMP = SQL.doSQLVarListID(IdTMP, sqlstr, "FMZOLL", , list, , errHinweis) + If Id <= 0 Then Id = IdTMP + Return Id > 0 + End Function + + + Public Function getInsertCmd() As String + Try + Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList() + Dim str As String = "" + Dim values As String = "" + For Each i In list + If Not i.isPrimaryParam Then + str &= "[" & i.Text & "]," + values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & "," + End If + Next + str = str.Substring(0, str.Length - 1) 'wg. ',' + values = values.Substring(0, values.Length - 1) 'wg. ',' + Return (" INSERT INTO tblDigicust_Sendungen (" & str & ") VALUES(" & values & ") ") + Catch ex As Exception + VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) + End Try + Return "" + End Function + + Public Function getUpdateCmd() As String + Try + Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList() + + Dim str As String = "" + For Each i In list + If Not i.isPrimaryParam Then + str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & "," + End If + Next + str = str.Substring(0, str.Length - 1) 'wg. ',' + Return (" UPDATE [tblDigicust_Sendungen] SET " & str & " WHERE Id=@Id ") + + Catch ex As Exception + VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) + End Try + Return "" + End Function + + + Public Sub LOAD() + Try + hasEntry = False + Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL() + Using cmd As New SqlCommand("SELECT * FROM tblDigicust_Sendungen where Id = @Id ", conn) + cmd.Parameters.AddWithValue("@Id", Id) + Dim dr = cmd.ExecuteReader() + + If dr.Read Then + For Each li In getParameterList() + Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable) + + If dr.Item(li.Text) Is DBNull.Value Then + propInfo.SetValue(Me, Nothing) + Else + propInfo.SetValue(Me, dr.Item(li.Text)) + End If + + Next + hasEntry = True + End If + dr.Close() + End Using + End Using + Catch ex As Exception + VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) + + End Try + End Sub + +End Class Public Class cDigicustAPI - 'Test - 'Shared API_STRING As String = "https://connect.sandbox.creditsafe.com" 'PROD Shared API_STRING As String = "https://api.digicust.com" Shared token As String = "" @@ -120,12 +322,16 @@ Public Class cDigicustAPI Public dataTable As New DataTable() - Shared Function SendRequestAuthentificationToken(ByVal myuri As String, ByVal contentType As String, ByVal method As String) As String + Shared Function SendRequestAuthentificationToken(ByVal myuri As String, ByVal contentType As String, ByVal method As String, ByRef _token As String) As String Try - Dim session = New cDigicust() + Dim session = New cDigicustSessions() - If Not IsDBNull(session.token) AndAlso session.token IsNot Nothing Then Return "token filled" + If Not IsDBNull(session.token) AndAlso session.token IsNot Nothing Then + _token = session.token + token = _token + Return "200" + End If VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() @@ -160,11 +366,12 @@ Public Class cDigicustAPI Dim jsonResp = New Chilkat.JsonObject() jsonResp.LoadSb(sbResponseBody) - token = jsonResp.StringOf("access_token") + _token = jsonResp.StringOf("access_token") + token = _token refresh_token = jsonResp.StringOf("refresh_token") Dim now As DateTime = DateTime.Now() now = now.AddSeconds(jsonResp.IntOf("expires_in")) - session = New cDigicust(token, refresh_token, now.ToString("yyyy-MM-dd HH:mm:ss")) + session = New cDigicustSessions(_token, refresh_token, now.ToString("yyyy-MM-dd HH:mm:ss")) '"yyyyMMdd HH:mm:ss" Return rest.ResponseStatusCode & " " & rest.ResponseStatusText @@ -176,85 +383,14 @@ Public Class cDigicustAPI Shared Function authenticate(ByRef token As String) As String Dim myUri As String = "/generic/api/auth/authenticate" - Dim response = SendRequestAuthentificationToken(myUri, "application/json", "POST") + Dim response = SendRequestAuthentificationToken(myUri, "application/json", "POST", token) Return response End Function - Shared Function SendRequestWithAuthHeader(acceptContentType As String, ByRef failureDesc As String) As String - Try - - VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() - - Dim rest As New Chilkat.Rest - Dim success As Boolean - - - Dim bTls As Boolean = True - Dim port As Integer = 443 - Dim bAutoReconnect As Boolean = True - success = rest.Connect(API_STRING, port, bTls, bAutoReconnect) - If (success <> True) Then - Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason) - Debug.WriteLine(rest.LastErrorText) - failureDesc = rest.LastErrorText - Return failureDesc - End If - - - rest.AddHeader("Content-Type", "application/json") - rest.AddHeader("Authorization", "Bearer " & token) - rest.AddHeader("Accept", acceptContentType) - - Dim sbRequestBody As New Chilkat.StringBuilder - 'jsonData.EmitSb(sbRequestBody) - 'Debug.WriteLine(sbRequestBody) - - 'DEBUG-Mode -> no request will be sent! - 'rest.DebugMode = True - - Dim sbResponseBody As New Chilkat.StringBuilder - success = rest.FullRequestSb("POST", "/api/integrations/verag", sbRequestBody, sbResponseBody) - - If (rest.LastMethodSuccess <> True) Then - Debug.WriteLine(rest.LastErrorText) - failureDesc = rest.LastErrorText - Return failureDesc - - Else - If (rest.ResponseStatusCode <> 200) Then - If rest.ResponseStatusCode = 500 Then - Dim jsonResultFailure As New Chilkat.JsonObject - jsonResultFailure.LoadSb(sbResponseBody) - jsonResultFailure.Emit() - failureDesc = jsonResultFailure.StringOf("code") & "-" & jsonResultFailure.StringOf("message") - Return failureDesc - Else - - failureDesc = rest.ResponseStatusCode & "-" & rest.ResponseStatusText - Return failureDesc - End If - - Else - - Dim jsonResult As New Chilkat.JsonObject - success = jsonResult.LoadSb(sbResponseBody) - jsonResult.Emit() - Return jsonResult.StringOf("atezId") - - End If - - End If - - - Catch ex As WebException - VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) - End Try - End Function - - Shared Sub uploadginCase() + Shared Function uploadingCase(dig As cDigicustSendungen, settings As cDigicustSettings, dgv As DataGridView) As Boolean Dim rest As New Chilkat.Rest Dim success As Boolean @@ -263,44 +399,66 @@ Public Class cDigicustAPI Dim bTls As Boolean = True Dim port As Integer = 443 Dim bAutoReconnect As Boolean = True - success = rest.Connect("api.digicust.com", port, bTls, bAutoReconnect) + success = rest.Connect(API_STRING, port, bTls, bAutoReconnect) If (success <> True) Then Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason) Debug.WriteLine(rest.LastErrorText) - Exit Sub + Return False End If + rest.VerboseLogging = True + Dim counter As Integer = 1 + Dim jsonFileArray = New Chilkat.JsonArray() - rest.PartSelector = "1" - Dim fileStream1 As New Chilkat.Stream - fileStream1.SourceFile = " path to file1.pdf" - rest.AddHeader("Content-Disposition", "form-data; name=""files[]""; filename="" path to file1.pdf""") - rest.AddHeader("Content-Type", "application/pdf") - rest.SetMultipartBodyStream(fileStream1) + For Each r As DataGridViewRow In dgv.Rows - rest.PartSelector = "2" - Dim fileStream2 As New Chilkat.Stream - fileStream2.SourceFile = " path to file2.pdf" - rest.AddHeader("Content-Disposition", "form-data; name=""files[]""; filename="" path to file2.pdf""") - rest.AddHeader("Content-Type", "application/pdf") - rest.SetMultipartBodyStream(fileStream2) + Dim isSelected = IIf(DBNull.Value Is r.Cells("anh_selekt").Value, False, r.Cells("anh_selekt").Value) + If isSelected Then + Dim j = 0 + Dim json As Chilkat.JsonObject + Dim filePath = VERAG_PROG_ALLGEMEIN.cDATENSERVER.GET_PDFPath_BY_DocID(r.Cells("anh_docId").Value) + Dim filename = New System.IO.FileInfo(filePath).Name - rest.PartSelector = "3" + rest.PartSelector = counter + Dim fileStream As New Chilkat.Stream + fileStream.SourceFile = filePath + rest.AddHeader("Content-Disposition", "form-data; name=""files[]""; filename=""" & filename & """") + rest.AddHeader("Content-Type", "application/pdf") + rest.SetMultipartBodyStream(fileStream) + + jsonFileArray.AddObjectAt(j) + json = jsonFileArray.ObjectAt(j) + json.UpdateString("fileName", filename) + json.UpdateString("documentType", r.Cells("anh_Art").Value) + + Debug.WriteLine(jsonFileArray.Emit) + counter += 1 + j += 1 + + End If + Next + + rest.PartSelector = counter rest.AddHeader("Content-Disposition", "form-data; name=""classifications""") - rest.SetMultipartBodyString("[{""fileName"":""file1.pdf"",""documentType"":""invoice""},{""fileName"":""file2.pdf"",""documentType"":""waybill""}]") + rest.SetMultipartBodyString(jsonFileArray.Emit) + counter += 1 - rest.PartSelector = "4" + rest.PartSelector = counter rest.AddHeader("Content-Disposition", "form-data; name=""executionStrategyId""") - rest.SetMultipartBodyString("{executionStrategyId}") + rest.SetMultipartBodyString(settings.executionStrategyId) + counter += 1 - rest.PartSelector = "5" + rest.PartSelector = counter rest.AddHeader("Content-Disposition", "form-data; name=""reference""") - rest.SetMultipartBodyString("{reference}") + rest.SetMultipartBodyString(dig.reference) + counter += 1 - rest.PartSelector = "6" + rest.PartSelector = counter rest.AddHeader("Content-Disposition", "form-data; name=""documents""") - rest.SetMultipartBodyString("[{""priority"":""afterNormalization"",""annotatedAggregated"":{}}]") + rest.SetMultipartBodyString("[{""priority"":""afterNormalization""}]") + 'rest.SetMultipartBodyString("[{""priority"":""afterNormalization"",""annotatedAggregated"":{}}]") + counter += 1 rest.PartSelector = "0" @@ -309,10 +467,104 @@ Public Class cDigicustAPI rest.AddHeader("Authorization", "Bearer " & token) rest.AddHeader("Expect", "100-continue") - Dim strResponseBody As String = rest.FullRequestMultipart("POST", "/upload/api/{customerId}/{projectId}/new") + 'Debuging + 'rest.DebugMode = True + rest.IdleTimeoutMs = 60000 + + rest.SendReqMultipart("POST", "/upload/api/" & settings.customerId & "/" & settings.projectId & "/new") + + Dim responseStatusCode = rest.ReadResponseHeader() + If (responseStatusCode < 0) Then + For i = 0 To 15 'Versuche den Header 16x abzufragen (funktioniert ab und zu nicht). + responseStatusCode = rest.ReadResponseHeader() + If responseStatusCode > 0 Then Exit For + Thread.Sleep(3000) + i = i + 1 + Next + + If rest.ResponseStatusCode <> 200 Then + MsgBox(rest.LastErrorText) + Return False + End If + + End If + If (rest.LastMethodSuccess <> True) Then + MsgBox(rest.LastErrorText) + Return False + End If + + Dim responseBodyStr As String = rest.ReadRespBodyString() + If (rest.LastMethodSuccess <> True) Then + MsgBox(rest.LastErrorText) + Return False + End If + + + Dim respStatusCode As Integer = rest.ResponseStatusCode + Debug.WriteLine("response status code = " & respStatusCode) + If (respStatusCode >= 400) Then + Debug.WriteLine("Response Status Code = " & respStatusCode) + Debug.WriteLine("Response Header:") + Debug.WriteLine(rest.ResponseHeader) + Debug.WriteLine("Response Body:") + Debug.WriteLine(responseBodyStr) + Return False + End If + + + Dim jsonResp = New Chilkat.JsonObject() + jsonResp.Load(responseBodyStr) + + Dim dateTime As New Chilkat.CkDateTime + Dim getAsLocal As Boolean = False + jsonResp.DateOf("result.createdAt", dateTime) + dig.createdAt = dateTime.GetAsTimestamp(getAsLocal) + + jsonResp.DateOf("result.status.modifiedAt", dateTime) + dig.modifiedAt = dateTime.GetAsTimestamp(getAsLocal) + + dig.status = jsonResp.StringOf("result.status.value") + dig.digicustId = jsonResp.StringOf("result.id") + dig.uploadedDocuments = jsonResp.SizeOfArray("result.uploadedFiles") + + + Return True + + End Function + + Shared Function fetchingCase(sendung As cDigicustSendungen) As Boolean + + Dim rest As New Chilkat.Rest + Dim success As Boolean + + ' URL: https://api.digicust.com/generic/api///cases/ + Dim bTls As Boolean = True + Dim port As Integer = 443 + Dim bAutoReconnect As Boolean = True + success = rest.Connect(API_STRING, port, bTls, bAutoReconnect) + If (success <> True) Then + Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason) Debug.WriteLine(rest.LastErrorText) - Exit Sub + Return False + End If + + Dim session = New cDigicustSessions() + + If Not IsDBNull(session.token) AndAlso session.token IsNot Nothing Then + token = session.token + Else + authenticate("") + End If + + rest.AddHeader("accept", "application/json") + rest.AddHeader("Authorization", "Bearer " & token) + + Dim sbResponseBody As New Chilkat.StringBuilder + success = rest.FullRequestNoBodySb("GET", "/generic/api/" & sendung.companyId & "/" & sendung.projectId & "/cases/" & sendung.digicustId, sbResponseBody) + If (success <> True) Then + Debug.WriteLine(rest.LastErrorText) + Return False End If Dim respStatusCode As Integer = rest.ResponseStatusCode @@ -322,9 +574,24 @@ Public Class cDigicustAPI Debug.WriteLine("Response Header:") Debug.WriteLine(rest.ResponseHeader) Debug.WriteLine("Response Body:") - Debug.WriteLine(strResponseBody) - Exit Sub + Debug.WriteLine(sbResponseBody.GetAsString()) + Return False End If - End Sub + + Dim jsonResp = New Chilkat.JsonObject() + jsonResp.LoadSb(sbResponseBody) + + sendung.status = jsonResp.StringOf("status.value") + + Dim dateTime As New Chilkat.CkDateTime + Dim getAsLocal As Boolean = False + jsonResp.DateOf("status.modifiedAt", dateTime) + sendung.modifiedAt = dateTime.GetAsTimestamp(getAsLocal) + + sendung.uploadedDocuments = jsonResp.SizeOfArray("uploadedFiles") + + sendung.SAVE() + + End Function End Class