work on jobrunner
This commit is contained in:
parent
720618f29b
commit
2855cc6208
@ -19,9 +19,6 @@
|
||||
<setting name="JOB_ADSYNC_ENABLED" serializeAs="String">
|
||||
<value>False</value>
|
||||
</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">
|
||||
<value />
|
||||
</setting>
|
||||
@ -37,6 +34,12 @@
|
||||
<setting name="JOB_INTERVAL" serializeAs="String">
|
||||
<value>120</value>
|
||||
</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>
|
||||
</applicationSettings>
|
||||
</configuration>
|
||||
@ -60,8 +60,17 @@ Public Class JobRunner
|
||||
_logger.Debug("Background worker running..")
|
||||
|
||||
' 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
|
||||
_logger.Warn("Background worker failed!")
|
||||
_logger.Error(ex)
|
||||
|
||||
@ -47,13 +47,6 @@
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<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="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<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 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.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Configuration.DefaultSettingValueAttribute("")> _
|
||||
@ -134,6 +125,24 @@ Namespace My
|
||||
Return CType(Me("JOB_INTERVAL"),Long)
|
||||
End Get
|
||||
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 Namespace
|
||||
|
||||
|
||||
@ -11,9 +11,6 @@
|
||||
<Setting Name="JOB_ADSYNC_ENABLED" Type="System.Boolean" Scope="Application">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</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">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
@ -29,5 +26,11 @@
|
||||
<Setting Name="JOB_INTERVAL" Type="System.Int64" Scope="Application">
|
||||
<Value Profile="(Default)">120</Value>
|
||||
</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>
|
||||
</SettingsFile>
|
||||
@ -33,6 +33,7 @@ Public Class WindowsService
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnStop()
|
||||
_jobRunner.Stop()
|
||||
_logger.Info($"{My.Settings.SERVICE_NAME} is stopping.")
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
Public Class ADSyncArgs
|
||||
Inherits JobArgs
|
||||
|
||||
Public RootPath As String
|
||||
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
|
||||
Inherits JobBase
|
||||
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
|
||||
_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
|
||||
|
||||
Public Function ShouldStart(Arguments As ADSyncArgs) As Boolean Implements IJob(Of ADSyncArgs).ShouldStart
|
||||
Return Arguments.Enabled
|
||||
End Function
|
||||
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)
|
||||
Sub Start(Arguments As T)
|
||||
|
||||
Function ShouldStart(Arguments As T) As Boolean
|
||||
End Interface
|
||||
@ -90,7 +90,9 @@
|
||||
<Compile Include="EDMI\ZUGFeRD\WorkerArgs.vb" />
|
||||
<Compile Include="EDMI\ZUGFeRD\XmlItemProperty.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\Settings.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
||||
@ -147,7 +147,7 @@ Public Class Firebird
|
||||
}.ToString()
|
||||
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
|
||||
Return Nothing
|
||||
ElseIf Mode = TransactionMode.ExternalTransaction Then
|
||||
@ -157,7 +157,7 @@ Public Class Firebird
|
||||
End If
|
||||
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
|
||||
Case TransactionMode.NoTransaction
|
||||
Return True
|
||||
@ -168,7 +168,7 @@ Public Class Firebird
|
||||
Transaction.Commit()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
Case Else
|
||||
|
||||
@ -112,29 +112,32 @@ Public Class ActiveDirectoryInterface
|
||||
Return oSyncedUsers
|
||||
End Function
|
||||
|
||||
|
||||
Public Sub Authenticate()
|
||||
Public Function Authenticate() As Boolean
|
||||
Try
|
||||
Dim oEntry = GetRootNode()
|
||||
oEntry.RefreshCache()
|
||||
|
||||
_rootNode = oEntry
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
_logger.Warn("Could not authenticate with Active Directory.")
|
||||
Return False
|
||||
End Try
|
||||
End Sub
|
||||
Public Sub Authenticate(Username As String, Password As String)
|
||||
End Function
|
||||
Public Function Authenticate(Username As String, Password As String) As Boolean
|
||||
Try
|
||||
Dim oEntry = GetRootNode(Username, Password)
|
||||
oEntry.RefreshCache()
|
||||
|
||||
_rootNode = oEntry
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
_logger.Warn("Could not authenticate with Active Directory.")
|
||||
Return False
|
||||
End Try
|
||||
End Sub
|
||||
End Function
|
||||
|
||||
Public Function ListGroups(Optional Query As String = "(&(objectClass=group) (samAccountName=*))") As List(Of ADGroup)
|
||||
Return ListGroups(_rootNode, Query)
|
||||
@ -196,27 +199,8 @@ Public Class ActiveDirectoryInterface
|
||||
Throw ex
|
||||
End Try
|
||||
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
|
||||
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
|
||||
Private Function GetGroupId(GroupName As String) As Integer
|
||||
Try
|
||||
Dim oSQL As String = $"SELECT FNICM_GET_RECORD4SYSKEY('{GroupName}','002-NAME') from RDB$DATABASE"
|
||||
Dim oGroupId = _firebird.GetScalarValue(oSQL)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user