work on jobrunner
This commit is contained in:
parent
720618f29b
commit
2855cc6208
@ -19,9 +19,6 @@
|
|||||||
<setting name="JOB_ADSYNC_ENABLED" serializeAs="String">
|
<setting name="JOB_ADSYNC_ENABLED" serializeAs="String">
|
||||||
<value>False</value>
|
<value>False</value>
|
||||||
</setting>
|
</setting>
|
||||||
<setting name="JOB_ADSYNC_INTERVAL" serializeAs="String">
|
|
||||||
<value>1,2,3,4,5,6,7,8,9,10</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="DB_DATASOURCE" serializeAs="String">
|
<setting name="DB_DATASOURCE" serializeAs="String">
|
||||||
<value />
|
<value />
|
||||||
</setting>
|
</setting>
|
||||||
@ -37,6 +34,12 @@
|
|||||||
<setting name="JOB_INTERVAL" serializeAs="String">
|
<setting name="JOB_INTERVAL" serializeAs="String">
|
||||||
<value>120</value>
|
<value>120</value>
|
||||||
</setting>
|
</setting>
|
||||||
|
<setting name="JOB_ADSYNC_INTERVAL" serializeAs="String">
|
||||||
|
<value>120</value>
|
||||||
|
</setting>
|
||||||
|
<setting name="JOB_ADSYNC_ROOT_PATH" serializeAs="String">
|
||||||
|
<value />
|
||||||
|
</setting>
|
||||||
</DigitalData.Services.JobRunner.My.MySettings>
|
</DigitalData.Services.JobRunner.My.MySettings>
|
||||||
</applicationSettings>
|
</applicationSettings>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -60,8 +60,17 @@ Public Class JobRunner
|
|||||||
_logger.Debug("Background worker running..")
|
_logger.Debug("Background worker running..")
|
||||||
|
|
||||||
' TODO: WORK
|
' TODO: WORK
|
||||||
'Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird)
|
|
||||||
'job.Start(args)
|
Dim oJob As New ADSyncJob(_logConfig, _firebird)
|
||||||
|
Dim oArgs As New ADSyncArgs() With {
|
||||||
|
.Enabled = My.Settings.JOB_ADSYNC_ENABLED,
|
||||||
|
.Interval = My.Settings.JOB_ADSYNC_INTERVAL,
|
||||||
|
.RootPath = My.Settings.JOB_ADSYNC_ROOT_PATH
|
||||||
|
}
|
||||||
|
If oJob.ShouldStart(oArgs) Then
|
||||||
|
oJob.Start(oArgs)
|
||||||
|
End If
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Warn("Background worker failed!")
|
_logger.Warn("Background worker failed!")
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
|
|||||||
@ -47,13 +47,6 @@
|
|||||||
<OptionInfer>On</OptionInfer>
|
<OptionInfer>On</OptionInfer>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="DevExpress.Data.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
|
||||||
<Reference Include="DevExpress.Utils.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
|
||||||
<Reference Include="DevExpress.XtraEditors.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
|
||||||
<Reference Include="DevExpress.XtraGrid.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
|
||||||
<Reference Include="DigitalData.Controls.LookupGrid">
|
|
||||||
<HintPath>..\LookupGrid\obj\Debug\DigitalData.Controls.LookupGrid.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>
|
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>
|
||||||
|
|||||||
27
JobRunner/My Project/Settings.Designer.vb
generated
27
JobRunner/My Project/Settings.Designer.vb
generated
@ -81,15 +81,6 @@ Namespace My
|
|||||||
End Get
|
End Get
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
|
|
||||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
|
||||||
Global.System.Configuration.DefaultSettingValueAttribute("1,2,3,4,5,6,7,8,9,10")> _
|
|
||||||
Public ReadOnly Property JOB_ADSYNC_INTERVAL() As String
|
|
||||||
Get
|
|
||||||
Return CType(Me("JOB_ADSYNC_INTERVAL"),String)
|
|
||||||
End Get
|
|
||||||
End Property
|
|
||||||
|
|
||||||
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
|
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
|
||||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||||
Global.System.Configuration.DefaultSettingValueAttribute("")> _
|
Global.System.Configuration.DefaultSettingValueAttribute("")> _
|
||||||
@ -134,6 +125,24 @@ Namespace My
|
|||||||
Return CType(Me("JOB_INTERVAL"),Long)
|
Return CType(Me("JOB_INTERVAL"),Long)
|
||||||
End Get
|
End Get
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
|
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
|
||||||
|
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||||
|
Global.System.Configuration.DefaultSettingValueAttribute("120")> _
|
||||||
|
Public ReadOnly Property JOB_ADSYNC_INTERVAL() As Long
|
||||||
|
Get
|
||||||
|
Return CType(Me("JOB_ADSYNC_INTERVAL"),Long)
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
|
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
|
||||||
|
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||||
|
Global.System.Configuration.DefaultSettingValueAttribute("")> _
|
||||||
|
Public ReadOnly Property JOB_ADSYNC_ROOT_PATH() As String
|
||||||
|
Get
|
||||||
|
Return CType(Me("JOB_ADSYNC_ROOT_PATH"),String)
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
End Class
|
End Class
|
||||||
End Namespace
|
End Namespace
|
||||||
|
|
||||||
|
|||||||
@ -11,9 +11,6 @@
|
|||||||
<Setting Name="JOB_ADSYNC_ENABLED" Type="System.Boolean" Scope="Application">
|
<Setting Name="JOB_ADSYNC_ENABLED" Type="System.Boolean" Scope="Application">
|
||||||
<Value Profile="(Default)">False</Value>
|
<Value Profile="(Default)">False</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
<Setting Name="JOB_ADSYNC_INTERVAL" Type="System.String" Scope="Application">
|
|
||||||
<Value Profile="(Default)">1,2,3,4,5,6,7,8,9,10</Value>
|
|
||||||
</Setting>
|
|
||||||
<Setting Name="DB_DATASOURCE" Type="System.String" Scope="Application">
|
<Setting Name="DB_DATASOURCE" Type="System.String" Scope="Application">
|
||||||
<Value Profile="(Default)" />
|
<Value Profile="(Default)" />
|
||||||
</Setting>
|
</Setting>
|
||||||
@ -29,5 +26,11 @@
|
|||||||
<Setting Name="JOB_INTERVAL" Type="System.Int64" Scope="Application">
|
<Setting Name="JOB_INTERVAL" Type="System.Int64" Scope="Application">
|
||||||
<Value Profile="(Default)">120</Value>
|
<Value Profile="(Default)">120</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="JOB_ADSYNC_INTERVAL" Type="System.Int64" Scope="Application">
|
||||||
|
<Value Profile="(Default)">120</Value>
|
||||||
|
</Setting>
|
||||||
|
<Setting Name="JOB_ADSYNC_ROOT_PATH" Type="System.String" Scope="Application">
|
||||||
|
<Value Profile="(Default)" />
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
@ -33,6 +33,7 @@ Public Class WindowsService
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Protected Overrides Sub OnStop()
|
Protected Overrides Sub OnStop()
|
||||||
|
_jobRunner.Stop()
|
||||||
_logger.Info($"{My.Settings.SERVICE_NAME} is stopping.")
|
_logger.Info($"{My.Settings.SERVICE_NAME} is stopping.")
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
Public Class ADSyncArgs
|
Public Class ADSyncArgs
|
||||||
|
Inherits JobArgs
|
||||||
|
|
||||||
|
Public RootPath As String
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -1,9 +1,32 @@
|
|||||||
Imports DigitalData.Modules.Jobs
|
Imports DigitalData.Modules.Database
|
||||||
|
Imports DigitalData.Modules.Interfaces
|
||||||
|
Imports DigitalData.Modules.Jobs
|
||||||
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
Public Class ADSyncJob
|
Public Class ADSyncJob
|
||||||
|
Inherits JobBase
|
||||||
Implements IJob(Of ADSyncArgs)
|
Implements IJob(Of ADSyncArgs)
|
||||||
|
|
||||||
|
Private _ADSync As ActiveDirectoryInterface
|
||||||
|
|
||||||
|
Public Sub New(LogConfig As LogConfig, Firebird As Firebird)
|
||||||
|
MyBase.New(LogConfig, Firebird)
|
||||||
|
End Sub
|
||||||
|
|
||||||
Public Sub Start(Arguments As ADSyncArgs) Implements IJob(Of ADSyncArgs).Start
|
Public Sub Start(Arguments As ADSyncArgs) Implements IJob(Of ADSyncArgs).Start
|
||||||
|
_ADSync = New ActiveDirectoryInterface(_LogConfig, _Firebird, Arguments.RootPath)
|
||||||
|
|
||||||
|
'TODO: Do AD Sync!
|
||||||
|
|
||||||
|
If _ADSync.Authenticate() = False Then
|
||||||
|
_Logger.Warn("Job could not be completed! Authentication failed!")
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Public Function ShouldStart(Arguments As ADSyncArgs) As Boolean Implements IJob(Of ADSyncArgs).ShouldStart
|
||||||
|
Return Arguments.Enabled
|
||||||
|
End Function
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
4
Jobs/JobArgs.vb
Normal file
4
Jobs/JobArgs.vb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Public Class JobArgs
|
||||||
|
Public Enabled As Boolean
|
||||||
|
Public Interval As Long
|
||||||
|
End Class
|
||||||
14
Jobs/JobBase.vb
Normal file
14
Jobs/JobBase.vb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Imports DigitalData.Modules.Database
|
||||||
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
|
Public Class JobBase
|
||||||
|
Protected _LogConfig As LogConfig
|
||||||
|
Protected _Logger As Logger
|
||||||
|
Protected _Firebird As Firebird
|
||||||
|
|
||||||
|
Public Sub New(LogConfig As LogConfig, Firebird As Firebird)
|
||||||
|
_LogConfig = LogConfig
|
||||||
|
_Logger = LogConfig.GetLogger()
|
||||||
|
_Firebird = Firebird
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
@ -4,4 +4,6 @@ End Interface
|
|||||||
|
|
||||||
Public Interface IJob(Of T)
|
Public Interface IJob(Of T)
|
||||||
Sub Start(Arguments As T)
|
Sub Start(Arguments As T)
|
||||||
|
|
||||||
|
Function ShouldStart(Arguments As T) As Boolean
|
||||||
End Interface
|
End Interface
|
||||||
@ -90,7 +90,9 @@
|
|||||||
<Compile Include="EDMI\ZUGFeRD\WorkerArgs.vb" />
|
<Compile Include="EDMI\ZUGFeRD\WorkerArgs.vb" />
|
||||||
<Compile Include="EDMI\ZUGFeRD\XmlItemProperty.vb" />
|
<Compile Include="EDMI\ZUGFeRD\XmlItemProperty.vb" />
|
||||||
<Compile Include="Exceptions.vb" />
|
<Compile Include="Exceptions.vb" />
|
||||||
<Compile Include="IJob.vb" />
|
<Compile Include="JobInterface.vb" />
|
||||||
|
<Compile Include="JobBase.vb" />
|
||||||
|
<Compile Include="JobArgs.vb" />
|
||||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||||
<Compile Include="My Project\Settings.Designer.vb">
|
<Compile Include="My Project\Settings.Designer.vb">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
|
|||||||
@ -147,7 +147,7 @@ Public Class Firebird
|
|||||||
}.ToString()
|
}.ToString()
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function MaybeGetTransaction(Connection As FbConnection, Mode As TransactionMode, Transaction As FbTransaction)
|
Private Function MaybeGetTransaction(Connection As FbConnection, Mode As TransactionMode, Transaction As FbTransaction) As FbTransaction
|
||||||
If Mode = TransactionMode.NoTransaction Then
|
If Mode = TransactionMode.NoTransaction Then
|
||||||
Return Nothing
|
Return Nothing
|
||||||
ElseIf Mode = TransactionMode.ExternalTransaction Then
|
ElseIf Mode = TransactionMode.ExternalTransaction Then
|
||||||
@ -157,7 +157,7 @@ Public Class Firebird
|
|||||||
End If
|
End If
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function MaybeCommitTransaction(Transaction As FbTransaction, TransactionMode As TransactionMode)
|
Private Function MaybeCommitTransaction(Transaction As FbTransaction, TransactionMode As TransactionMode) As Boolean
|
||||||
Select Case TransactionMode
|
Select Case TransactionMode
|
||||||
Case TransactionMode.NoTransaction
|
Case TransactionMode.NoTransaction
|
||||||
Return True
|
Return True
|
||||||
@ -168,7 +168,7 @@ Public Class Firebird
|
|||||||
Transaction.Commit()
|
Transaction.Commit()
|
||||||
Return True
|
Return True
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
Return False
|
Return False
|
||||||
End Try
|
End Try
|
||||||
Case Else
|
Case Else
|
||||||
|
|||||||
@ -112,29 +112,32 @@ Public Class ActiveDirectoryInterface
|
|||||||
Return oSyncedUsers
|
Return oSyncedUsers
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Public Function Authenticate() As Boolean
|
||||||
Public Sub Authenticate()
|
|
||||||
Try
|
Try
|
||||||
Dim oEntry = GetRootNode()
|
Dim oEntry = GetRootNode()
|
||||||
oEntry.RefreshCache()
|
oEntry.RefreshCache()
|
||||||
|
|
||||||
_rootNode = oEntry
|
_rootNode = oEntry
|
||||||
|
Return True
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
_logger.Warn("Could not authenticate with Active Directory.")
|
_logger.Warn("Could not authenticate with Active Directory.")
|
||||||
|
Return False
|
||||||
End Try
|
End Try
|
||||||
End Sub
|
End Function
|
||||||
Public Sub Authenticate(Username As String, Password As String)
|
Public Function Authenticate(Username As String, Password As String) As Boolean
|
||||||
Try
|
Try
|
||||||
Dim oEntry = GetRootNode(Username, Password)
|
Dim oEntry = GetRootNode(Username, Password)
|
||||||
oEntry.RefreshCache()
|
oEntry.RefreshCache()
|
||||||
|
|
||||||
_rootNode = oEntry
|
_rootNode = oEntry
|
||||||
|
Return True
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
_logger.Warn("Could not authenticate with Active Directory.")
|
_logger.Warn("Could not authenticate with Active Directory.")
|
||||||
|
Return False
|
||||||
End Try
|
End Try
|
||||||
End Sub
|
End Function
|
||||||
|
|
||||||
Public Function ListGroups(Optional Query As String = "(&(objectClass=group) (samAccountName=*))") As List(Of ADGroup)
|
Public Function ListGroups(Optional Query As String = "(&(objectClass=group) (samAccountName=*))") As List(Of ADGroup)
|
||||||
Return ListGroups(_rootNode, Query)
|
Return ListGroups(_rootNode, Query)
|
||||||
@ -196,27 +199,8 @@ Public Class ActiveDirectoryInterface
|
|||||||
Throw ex
|
Throw ex
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
Public Function ListUsers(GroupNames As List(Of String)) As List(Of ADUser)
|
|
||||||
Try
|
|
||||||
Dim oUsers As New List(Of ADUser)
|
|
||||||
Dim oComparer As New UserEqualityComparer()
|
|
||||||
|
|
||||||
For Each oGroup In GroupNames
|
Private Function GetGroupId(GroupName As String) As Integer
|
||||||
Dim oGroupUsers = ListUsers(oGroup)
|
|
||||||
Dim oNewUsers = oGroupUsers.
|
|
||||||
Except(oUsers, oComparer).
|
|
||||||
ToList()
|
|
||||||
oUsers.AddRange(oNewUsers)
|
|
||||||
Next
|
|
||||||
|
|
||||||
Return oUsers
|
|
||||||
Catch ex As Exception
|
|
||||||
_logger.Error(ex)
|
|
||||||
Throw ex
|
|
||||||
End Try
|
|
||||||
End Function
|
|
||||||
|
|
||||||
Public Function GetGroupId(GroupName As String) As Integer
|
|
||||||
Try
|
Try
|
||||||
Dim oSQL As String = $"SELECT FNICM_GET_RECORD4SYSKEY('{GroupName}','002-NAME') from RDB$DATABASE"
|
Dim oSQL As String = $"SELECT FNICM_GET_RECORD4SYSKEY('{GroupName}','002-NAME') from RDB$DATABASE"
|
||||||
Dim oGroupId = _firebird.GetScalarValue(oSQL)
|
Dim oGroupId = _firebird.GetScalarValue(oSQL)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user