84 lines
2.8 KiB
VB.net
84 lines
2.8 KiB
VB.net
Imports System.IO
|
|
Imports DigitalData.Modules.Interfaces
|
|
Imports DigitalData.Modules.Jobs
|
|
Imports DigitalData.Modules.Config
|
|
Imports DigitalData.Modules.Logging
|
|
Imports Newtonsoft.Json.Linq
|
|
|
|
Public Class GraphQLJob
|
|
Inherits JobBase
|
|
Implements IJob(Of GraphQLArgs)
|
|
|
|
Public Sub New(LogConfig As LogConfig)
|
|
MyBase.New(LogConfig, Nothing, Nothing)
|
|
End Sub
|
|
|
|
Public Sub Start(Args As GraphQLArgs) Implements IJob(Of GraphQLArgs).Start
|
|
Try
|
|
Dim oConfigPath As String = Args.QueryConfigPath
|
|
Dim oConfigManager As New ConfigManager(Of GraphQLConfig)(_LogConfig, oConfigPath)
|
|
|
|
Dim oInterface As GraphQLInterface
|
|
|
|
With oConfigManager.Config
|
|
oInterface = New GraphQLInterface(_LogConfig, .BaseUrl, .Email, .Password, .CertificateFingerprint)
|
|
End With
|
|
|
|
' Login to get cookie
|
|
_Logger.Info("Logging in..")
|
|
Dim oLoginResponse = oInterface.Login()
|
|
|
|
' save cookie for future requests
|
|
oInterface.SaveCookies(oLoginResponse.Cookies.Item(0))
|
|
|
|
_Logger.Info("Getting the data..")
|
|
|
|
For Each oQuery As GraphQLConfig.Query In oConfigManager.Config.Queries
|
|
Dim oCurrentQuery = oQuery
|
|
|
|
' get the data
|
|
Dim oDataResponse = oInterface.GetData(oCurrentQuery.QueryString, oCurrentQuery.OperationName)
|
|
Dim oResult As String
|
|
|
|
' write data to string
|
|
Using oStream = oDataResponse.GetResponseStream()
|
|
Using oReader As New StreamReader(oStream)
|
|
oResult = oReader.ReadToEnd()
|
|
End Using
|
|
End Using
|
|
|
|
oCurrentQuery = HandleResponse(oResult, oCurrentQuery)
|
|
Next
|
|
|
|
' logout
|
|
_Logger.Info("Logging out..")
|
|
Dim oLogoutResponse = oInterface.Logout()
|
|
Catch ex As Exception
|
|
_Logger.Error(ex)
|
|
Throw ex
|
|
End Try
|
|
End Sub
|
|
|
|
Private Function HandleResponse(JsonString As String, QueryData As GraphQLConfig.Query) As GraphQLConfig.Query
|
|
Dim oObj As JObject = JObject.Parse(JsonString)
|
|
Dim oResultList = oObj.SelectToken(QueryData.MappingBasePath)
|
|
Dim oMappings = QueryData.MappingFields
|
|
|
|
For Each oResultItem In oResultList
|
|
For Each oMapping In oMappings
|
|
Dim oValue = oResultItem.SelectToken(oMapping.SourcePath).ToString()
|
|
|
|
' TODO: Build SQL
|
|
Next
|
|
|
|
'TODO: Insert into db
|
|
Next
|
|
|
|
Return QueryData
|
|
End Function
|
|
|
|
Public Function ShouldStart(Arguments As GraphQLArgs) As Boolean Implements IJob(Of GraphQLArgs).ShouldStart
|
|
Return Arguments.Enabled
|
|
End Function
|
|
End Class
|