Monorepo/Jobs/EDMI/ADSync/ADSyncJob.vb
2019-04-10 11:58:17 +02:00

49 lines
1.6 KiB
VB.net

Imports System.Collections.Generic
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)
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
Dim oSync = New ActiveDirectoryInterface(_LogConfig, _Firebird, Arguments.RootPath)
Dim oJobName As String = [GetType]().Name
_Logger.Info("Running job {0}", oJobName)
If oSync.Authenticate() = False Then
_Logger.Warn("Job {0} could not be completed! Authentication failed!", oJobName)
Exit Sub
End If
Dim oGroups As List(Of ADGroup) = oSync.ListGroups()
_Logger.Debug("Found {0} Groups", oGroups.Count)
For Each oGroup In oGroups
_Logger.Debug("Syncing Group {0}", oGroup.Name)
Dim oSyncedUsers = oSync.SyncUsersForGroup(oGroup.Name)
If oSyncedUsers Is Nothing Then
_Logger.Warn("Group {0} could not be synced!", oGroup)
Else
_Logger.Debug("Group {0} synced", oGroup)
_Logger.Debug("Synced {0} users", oSyncedUsers.Count)
End If
Next
_Logger.Info("Job {0} completed!", oJobName)
End Sub
Public Function ShouldStart(Arguments As ADSyncArgs) As Boolean Implements IJob(Of ADSyncArgs).ShouldStart
Return Arguments.Enabled
End Function
End Class