Compare commits
3 Commits
8e8664b0e8
...
5ebf847b73
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ebf847b73 | ||
|
|
a61610a90a | ||
|
|
5343e051e9 |
4
Modules.Interfaces/GrapQLInterface/LoginData.vb
Normal file
4
Modules.Interfaces/GrapQLInterface/LoginData.vb
Normal file
@@ -0,0 +1,4 @@
|
||||
Public Class LoginData
|
||||
Public email As String
|
||||
Public token As String
|
||||
End Class
|
||||
3
Modules.Interfaces/GrapQLInterface/LogoutData.vb
Normal file
3
Modules.Interfaces/GrapQLInterface/LogoutData.vb
Normal file
@@ -0,0 +1,3 @@
|
||||
Public Class LogoutData
|
||||
Public email As String
|
||||
End Class
|
||||
5
Modules.Interfaces/GrapQLInterface/QueryData.vb
Normal file
5
Modules.Interfaces/GrapQLInterface/QueryData.vb
Normal file
@@ -0,0 +1,5 @@
|
||||
Public Class QueryData
|
||||
Public Query As String
|
||||
Public OperationName As String
|
||||
Public Variables As New Object
|
||||
End Class
|
||||
119
Modules.Interfaces/GraphQLInterface.vb
Normal file
119
Modules.Interfaces/GraphQLInterface.vb
Normal file
@@ -0,0 +1,119 @@
|
||||
Imports System.IO
|
||||
Imports System.Net
|
||||
Imports System.Security.Cryptography.X509Certificates
|
||||
Imports System.Text
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Newtonsoft.Json
|
||||
|
||||
Public Class GraphQLInterface
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
Private _baseUrl As String
|
||||
Private _userEmail As String
|
||||
Private _userPassword As String
|
||||
Private _certificate As X509Certificate
|
||||
Private _cookieJar As CookieContainer
|
||||
|
||||
Private _Encoding As New UTF8Encoding
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, BaseUrl As String, Email As String, Password As String, CertificateFile As String, CertificatePassword As String)
|
||||
Try
|
||||
_logConfig = LogConfig
|
||||
_logger = LogConfig.GetLogger()
|
||||
_baseUrl = BaseUrl
|
||||
_userEmail = Email
|
||||
_userPassword = Password
|
||||
|
||||
_certificate = New X509Certificate(CertificateFile, CertificatePassword)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Sub SaveCookies(Cookie As Cookie)
|
||||
GetCookies().Add(Cookie)
|
||||
End Sub
|
||||
|
||||
Public Function Login() As HttpWebResponse
|
||||
Try
|
||||
Dim oLoginData As New LoginData() With {.email = _userEmail, .token = _userPassword}
|
||||
Dim oBytes As Byte() = ToBytes(JsonConvert.SerializeObject(oLoginData))
|
||||
Dim oRequest As HttpWebRequest = GetRequest("/login", oBytes)
|
||||
|
||||
Using oStream = oRequest.GetRequestStream()
|
||||
oStream.Write(oBytes, 0, oBytes.Length)
|
||||
End Using
|
||||
|
||||
Return oRequest.GetResponse()
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Logout() As HttpWebResponse
|
||||
Try
|
||||
Dim oLogoutData As New LogoutData() With {.email = _userEmail}
|
||||
Dim oBytes As Byte() = ToBytes(JsonConvert.SerializeObject(oLogoutData))
|
||||
Dim oRequest As HttpWebRequest = GetRequest("/logout", oBytes)
|
||||
|
||||
Using stream = oRequest.GetRequestStream()
|
||||
stream.Write(oBytes, 0, oBytes.Length)
|
||||
End Using
|
||||
|
||||
Return oRequest.GetResponse()
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetData(Query As String, OperationName As String) As HttpWebResponse
|
||||
Try
|
||||
Dim oQueryData As New QueryData() With {
|
||||
.OperationName = OperationName,
|
||||
.Query = Query,
|
||||
.Variables = New Object
|
||||
}
|
||||
Dim oBytes = ToBytes(JsonConvert.SerializeObject(oQueryData))
|
||||
Dim oRequest = GetRequest("/graphql", oBytes)
|
||||
|
||||
Using stream = oRequest.GetRequestStream()
|
||||
stream.Write(oBytes, 0, oBytes.Length)
|
||||
End Using
|
||||
|
||||
Return oRequest.GetResponse()
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest
|
||||
Try
|
||||
Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}")
|
||||
oRequest.Method = "POST"
|
||||
oRequest.ContentType = "application/json"
|
||||
oRequest.ContentLength = PostData.Length
|
||||
oRequest.ClientCertificates.Add(_certificate)
|
||||
oRequest.CookieContainer = GetCookies()
|
||||
|
||||
Return oRequest
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetCookies() As CookieContainer
|
||||
If _cookieJar Is Nothing Then
|
||||
_cookieJar = New CookieContainer()
|
||||
End If
|
||||
|
||||
Return _cookieJar
|
||||
End Function
|
||||
|
||||
Private Function ToBytes(Str As String) As Byte()
|
||||
Return _Encoding.GetBytes(Str)
|
||||
End Function
|
||||
End Class
|
||||
@@ -44,6 +44,9 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.6.7\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -83,6 +86,10 @@
|
||||
<Compile Include="ActiveDirectoryInterface\SyncUsers.MSSQL.vb" />
|
||||
<Compile Include="ActiveDirectoryInterface\UserEqualityComparer.vb" />
|
||||
<Compile Include="ActiveDirectoryInterface\UserPrincipalEx.vb" />
|
||||
<Compile Include="GraphQLInterface.vb" />
|
||||
<Compile Include="GrapQLInterface\LoginData.vb" />
|
||||
<Compile Include="GrapQLInterface\LogoutData.vb" />
|
||||
<Compile Include="GrapQLInterface\QueryData.vb" />
|
||||
<Compile Include="ZUGFeRDInterface\Exceptions.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
@@ -143,5 +150,6 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
</Project>
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
|
||||
<package id="NLog" version="4.6.7" targetFramework="net461" />
|
||||
</packages>
|
||||
@@ -90,55 +90,8 @@ Public Class JobRunner
|
||||
Await _scheduler.Shutdown()
|
||||
End Sub
|
||||
|
||||
Public Class ADJob
|
||||
Implements Quartz.IJob
|
||||
|
||||
Public Function Execute(context As IJobExecutionContext) As Task Implements Quartz.IJob.Execute
|
||||
Dim oJobData = context.MergedJobDataMap
|
||||
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
|
||||
Dim oFirebird As Firebird = oJobData.Item("Firebird")
|
||||
Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
|
||||
Dim oArgs As Dictionary(Of String, String) = oJobData.Item("Args")
|
||||
Dim oADJobArgs = New ADSyncArgs()
|
||||
|
||||
If oArgs.ContainsKey("RootPath") Then
|
||||
oADJobArgs.RootPath = oArgs.Item("RootPath")
|
||||
End If
|
||||
|
||||
If oArgs.ContainsKey("DisableFirebird") AndAlso oArgs.Item("DisableFirebird") = "True" Then
|
||||
oFirebird = Nothing
|
||||
End If
|
||||
|
||||
If oArgs.ContainsKey("DisableMSSQL") AndAlso oArgs.Item("DisableMSSQL") = "True" Then
|
||||
oMSSQL = Nothing
|
||||
End If
|
||||
|
||||
Dim oADSyncJob As New ADSyncJob(oLogConfig, oFirebird, oMSSQL)
|
||||
oADSyncJob.Start(oADJobArgs)
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
Public Class TestJob
|
||||
Implements Quartz.IJob
|
||||
|
||||
Public Function Execute(context As IJobExecutionContext) As Task Implements Quartz.IJob.Execute
|
||||
Dim oJobData = context.MergedJobDataMap
|
||||
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
|
||||
Dim oLogger = oLogConfig.GetLogger()
|
||||
|
||||
Dim oArgs As Dictionary(Of String, String) = oJobData.Item("Args")
|
||||
|
||||
If oArgs.ContainsKey("Arg1") Then
|
||||
Dim oArg1 As String = oArgs.Item("Arg1")
|
||||
oLogger.Info("Running Test Job With Arg1: {0}", oArg1)
|
||||
Else
|
||||
oLogger.Warn("Running Test Job With missing Arg1 :/")
|
||||
End If
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Private Class LogProvider
|
||||
Implements ILogProvider
|
||||
|
||||
@@ -87,6 +87,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="JobRunner.vb" />
|
||||
<Compile Include="Jobs\ADJob.vb" />
|
||||
<Compile Include="Jobs\TestJob.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
@@ -148,6 +150,10 @@
|
||||
<Project>{EAF0EA75-5FA7-485D-89C7-B2D843B03A96}</Project>
|
||||
<Name>Database</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Modules.Jobs\Jobs.vbproj">
|
||||
<Project>{39EC839A-3C30-4922-A41E-6B09D1DDE5C3}</Project>
|
||||
<Name>Jobs</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
|
||||
<Project>{903B2D7D-3B80-4BE9-8713-7447B704E1B0}</Project>
|
||||
<Name>Logging</Name>
|
||||
|
||||
34
Service.JobRunner/Jobs/ADJob.vb
Normal file
34
Service.JobRunner/Jobs/ADJob.vb
Normal file
@@ -0,0 +1,34 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Jobs
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Quartz
|
||||
|
||||
Public Class ADJob
|
||||
Implements Quartz.IJob
|
||||
|
||||
Public Function Execute(context As IJobExecutionContext) As Task Implements Quartz.IJob.Execute
|
||||
Dim oJobData = context.MergedJobDataMap
|
||||
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
|
||||
Dim oFirebird As Firebird = oJobData.Item("Firebird")
|
||||
Dim oArgs As Dictionary(Of String, String) = oJobData.Item("Args")
|
||||
Dim oADJobArgs = New ADSyncArgs()
|
||||
|
||||
If oArgs.ContainsKey("RootPath") Then
|
||||
oADJobArgs.RootPath = oArgs.Item("RootPath")
|
||||
End If
|
||||
|
||||
If oArgs.ContainsKey("DisableFirebird") AndAlso oArgs.Item("DisableFirebird") = "True" Then
|
||||
oFirebird = Nothing
|
||||
End If
|
||||
|
||||
Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
|
||||
If oArgs.ContainsKey("DisableMSSQL") AndAlso oArgs.Item("DisableMSSQL") = "True" Then
|
||||
oMSSQL = Nothing
|
||||
End If
|
||||
|
||||
Dim oADSyncJob As New ADSyncJob(oLogConfig, oFirebird, oMSSQL)
|
||||
oADSyncJob.Start(oADJobArgs)
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
23
Service.JobRunner/Jobs/TestJob.vb
Normal file
23
Service.JobRunner/Jobs/TestJob.vb
Normal file
@@ -0,0 +1,23 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Quartz
|
||||
|
||||
Public Class TestJob
|
||||
Implements Quartz.IJob
|
||||
|
||||
Public Function Execute(context As IJobExecutionContext) As Task Implements Quartz.IJob.Execute
|
||||
Dim oJobData = context.MergedJobDataMap
|
||||
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
|
||||
Dim oLogger = oLogConfig.GetLogger()
|
||||
|
||||
Dim oArgs As Dictionary(Of String, String) = oJobData.Item("Args")
|
||||
|
||||
If oArgs.ContainsKey("Arg1") Then
|
||||
Dim oArg1 As String = oArgs.Item("Arg1")
|
||||
oLogger.Info("Running Test Job With Arg1: {0}", oArg1)
|
||||
Else
|
||||
oLogger.Warn("Running Test Job With missing Arg1 :/")
|
||||
End If
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user