diff --git a/Connectors.Common/Modules/BaseModule.vb b/Connectors.Common/Modules/BaseModule.vb index 1bc5532..c27c71a 100644 --- a/Connectors.Common/Modules/BaseModule.vb +++ b/Connectors.Common/Modules/BaseModule.vb @@ -29,7 +29,7 @@ Public MustInherit Class BaseModule Public Event OnFileProcessed As EventHandler(Of String) Implements ISync.OnFileProcessed Public Event OnFileError As EventHandler(Of String) Implements ISync.OnFileError - Private ReadOnly DirectoryGuid As String = Guid.NewGuid.ToString() + Private DirectoryGuid As String = Guid.NewGuid.ToString() Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config) MyBase.New(pLogConfig) @@ -38,6 +38,10 @@ Public MustInherit Class BaseModule Config = pConfig End Sub + Friend Sub RefreshDirectoryGuid() + DirectoryGuid = Guid.NewGuid.ToString() + End Sub + Friend Async Function FetchDocIds() As Task(Of List(Of String)) If Config.SQLQueryFetch = "" Then Logger.Warn("Fetch Query is not configured. Exiting.") diff --git a/Connectors.Common/Modules/Sharepoint/SharepointSync.vb b/Connectors.Common/Modules/Sharepoint/SharepointSync.vb index b4c5062..20c26a5 100644 --- a/Connectors.Common/Modules/Sharepoint/SharepointSync.vb +++ b/Connectors.Common/Modules/Sharepoint/SharepointSync.vb @@ -20,6 +20,7 @@ Namespace Sharepoint AddDivider() EnsureOutputDirectoryExists() + RefreshDirectoryGuid() Dim oExtDocIds = Await FetchDocIds() If oExtDocIds Is Nothing Then diff --git a/Connectors.Common/Modules/slt/sltSync.vb b/Connectors.Common/Modules/slt/sltSync.vb index 51eb886..c911ea5 100644 --- a/Connectors.Common/Modules/slt/sltSync.vb +++ b/Connectors.Common/Modules/slt/sltSync.vb @@ -32,6 +32,7 @@ Namespace slt AddDivider() EnsureOutputDirectoryExists() + RefreshDirectoryGuid() Dim oExtDocIds = Await FetchDocIds() If oExtDocIds Is Nothing Then diff --git a/Connectors.Form/frmMain.vb b/Connectors.Form/frmMain.vb index ab276b0..b40c75b 100644 --- a/Connectors.Form/frmMain.vb +++ b/Connectors.Form/frmMain.vb @@ -1,5 +1,6 @@ Imports System.ComponentModel Imports System.Runtime.Remoting.Messaging +Imports System.Threading.Tasks Imports Connectors.Common Imports DevExpress.XtraEditors.ViewInfo Imports DigitalData.Modules.Config @@ -15,6 +16,7 @@ Partial Public Class frmMain Private FilesProcessed As Integer = 0 Private ErrorsOccurred As Integer = 0 + Private SyncRunning As Boolean = False Public Enum LogLevel Info @@ -48,7 +50,7 @@ Partial Public Class frmMain AddDivider() If ConfigManager.Config.ActiveModule = "NONE" Then - AddWarnEntry("No ActiveModule selected, check your configuration!", ConfigManager.Config.ActiveModule) + AddWarnEntry("No ActiveModule selected, check your configuration!") Exit Sub End If @@ -69,11 +71,16 @@ Partial Public Class frmMain Exit Sub End If + If Sync.TestConfigIsComplete() Then + AddWarnEntry("Configuration is incomplete, check your configuration!") + Exit Sub + End If + btnForceSync.Enabled = True - If ConfigManager.Config.Autostart And Sync.TestConfigIsComplete() Then + If ConfigManager.Config.Autostart Then btnForceSync.Enabled = False - Await Sync.Run() + Await RunSync() btnForceSync.Enabled = True End If @@ -165,9 +172,26 @@ Partial Public Class frmMain SyncTimer.Enabled = False End Sub + Private Async Function RunSync() As Task + If SyncRunning = True Then + Logger.Debug("Sync still running. Skipping.") + Exit Function + End If + + Try + SyncRunning = True + Await Sync.Run() + SyncRunning = False + Catch ex As Exception + SyncRunning = False + Logger.Warn("Error while running sync!") + Logger.Error(ex) + End Try + End Function + Private Async Function Timer_Elapsed(sender As Object, e As System.EventArgs) As Threading.Tasks.Task Handles SyncTimer.Tick btnForceSync.Enabled = False - Await Sync.Run() + Await RunSync() btnForceSync.Enabled = True End Function @@ -253,7 +277,7 @@ Partial Public Class frmMain Private Async Sub btnForceSync_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnForceSync.ItemClick btnForceSync.Enabled = False - Await Sync.Run() + Await RunSync() btnForceSync.Enabled = True End Sub