Monorepo/Jobs/EDMI/ADSync/ADSyncJob.vb
2019-04-18 16:33:40 +02:00

55 lines
1.8 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, MSSQL As MSSQLServer)
MyBase.New(LogConfig, Firebird, MSSQL)
End Sub
Public Sub Start(Arguments As ADSyncArgs) Implements IJob(Of ADSyncArgs).Start
Dim oJobName As String = [GetType]().Name
Try
Dim oSync = New ActiveDirectoryInterface(_LogConfig, _Firebird, _MSSQL, Arguments.RootPath)
_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("Synced {0} users for group {1}", oSyncedUsers.Count, oGroup)
End If
Next
_Logger.Info("Job {0} completed!", oJobName)
Catch ex As Exception
_Logger.Warn("Job {0} failed!", oJobName)
_Logger.Error(ex)
End Try
End Sub
Public Function ShouldStart(Arguments As ADSyncArgs) As Boolean Implements IJob(Of ADSyncArgs).ShouldStart
Return Arguments.Enabled
End Function
End Class