From 3fa731fe5fe1f073c9d54f91e978ee97f20c5216 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 14 Aug 2023 16:48:21 +0200 Subject: [PATCH] 14-08-2023 --- Connectors.Form/Config.vb | 2 ++ Connectors.Form/Modules/BaseModule.vb | 18 ++++++++++++++++++ .../Modules/Sharepoint/SharepointSync.vb | 17 ++--------------- Connectors.Form/Modules/slt/sltSync.vb | 10 +++------- Connectors.Form/frmMain.vb | 4 +++- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Connectors.Form/Config.vb b/Connectors.Form/Config.vb index ae75eb2..3ee3852 100644 --- a/Connectors.Form/Config.vb +++ b/Connectors.Form/Config.vb @@ -24,6 +24,8 @@ Public Property SQLQueryFetch As String = "" Public Property OutputDirectory As String = "" + Public Property AddDateSubDirectory As Boolean = False + Public Property TimerIntervalMin As Integer = 0 Public Property Debug As Boolean = False diff --git a/Connectors.Form/Modules/BaseModule.vb b/Connectors.Form/Modules/BaseModule.vb index 234ecb4..1b22ceb 100644 --- a/Connectors.Form/Modules/BaseModule.vb +++ b/Connectors.Form/Modules/BaseModule.vb @@ -64,6 +64,24 @@ Public MustInherit Class BaseModule Return StringEx.ConvertTextToSlug(oName) & oExtension End Function + Friend Function GetFinalFileName(pFileName As String, pId As String) As String + Dim oExtension = Path.GetExtension(pFileName) + Return pId & oExtension + End Function + + Friend Function GetFinalFilePath(pFileName As String) As String + If Config.AddDateSubDirectory Then + Dim oSubPath = FileEx.CreateDateDirectory(Config.OutputDirectory) + If oSubPath Is Nothing Then + Throw New ApplicationException("Output sub path could not be created!") + End If + Logger.Debug("Subdirectory [{0}] created.", oSubPath) + Return Path.Combine(oSubPath, pFileName) + Else + Return Path.Combine(Config.OutputDirectory, pFileName) + End If + End Function + Friend Function CopyFileToOutputPath(pFileContents As Byte(), pFilePath As String) As Boolean Try Using oStream As New MemoryStream(pFileContents) diff --git a/Connectors.Form/Modules/Sharepoint/SharepointSync.vb b/Connectors.Form/Modules/Sharepoint/SharepointSync.vb index cd669d8..ec49b3e 100644 --- a/Connectors.Form/Modules/Sharepoint/SharepointSync.vb +++ b/Connectors.Form/Modules/Sharepoint/SharepointSync.vb @@ -10,8 +10,6 @@ Namespace Sharepoint Inherits BaseModule Implements ISync - Private Const STRING1_PLACEHOLDER = "[String1]" - Public Overrides Property Name As String = "Sharepoint Sync" Public Overrides Property IsLoggedIn As Boolean @@ -45,23 +43,14 @@ Namespace Sharepoint Logger.Info("ExtDocId: [{0}]", oDocument.Id) Dim oFileName = ConvertFilenameToSlug(oDocument.Name) - Dim oSubPath = FileEx.CreateDateDirectory(Config.OutputDirectory) - If oSubPath Is Nothing Then - Throw New ApplicationException("Output sub path could not be created!") - End If - Dim oFilePath = Path.Combine(oSubPath, oFileName) - Logger.Debug("Subdirectory [{0}] created.", oSubPath) + Dim oTempFileName = GetFinalFileName(oDocument.Name, oDocument.Id) + Dim oFilePath = GetFinalFilePath(oTempFileName) If CopyFileToOutputPath(oDocument.Data, oFilePath) = False Then Throw New ApplicationException("File could not be created in output path!") End If Dim oSQL = String.Format(Config.SQLQueryExport, oDocument.Id, oFileName) - - If oSQL.Contains(STRING1_PLACEHOLDER) Then - oSQL.Replace(STRING1_PLACEHOLDER, oDocument.Path) - End If - Await Database.ExecuteNonQueryAsync(oSQL) Catch ex As Exception @@ -70,8 +59,6 @@ Namespace Sharepoint End Try Next - 'TODO - AddInfoEntry("Finished Sync.") Catch ex As Exception Logger.Error(ex) diff --git a/Connectors.Form/Modules/slt/sltSync.vb b/Connectors.Form/Modules/slt/sltSync.vb index f65ff96..fb0026b 100644 --- a/Connectors.Form/Modules/slt/sltSync.vb +++ b/Connectors.Form/Modules/slt/sltSync.vb @@ -53,14 +53,10 @@ Namespace slt AddInfoEntry("Document: [{0}]", oDocument.Name) Logger.Info("ExtDocId: [{0}]", oDocument.ExtDocId) - Dim oDocumentName = GetFilenameWithExtension(oDocument.Name, oDocument.DocMimeType) + Dim oDocumentName = GetFilenameWithExtension(oDocument.ExtDocId, oDocument.DocMimeType) Dim oFileName = ConvertFilenameToSlug(oDocumentName) - Dim oSubPath = FileEx.CreateDateDirectory(Config.OutputDirectory) - If oSubPath Is Nothing Then - Throw New ApplicationException("Output sub path could not be created!") - End If - Dim oFilePath = Path.Combine(oSubPath, oFileName) - Logger.Debug("Subdirectory [{0}] created.", oSubPath) + Dim oTempFileName = GetFinalFileName(oFileName, oDocument.ExtDocId) + Dim oFilePath = GetFinalFilePath(oFileName) If CopyFileToOutputPath(oDocument.Data, oFilePath) = False Then Throw New ApplicationException("File could not be created in output path!") diff --git a/Connectors.Form/frmMain.vb b/Connectors.Form/frmMain.vb index 9c1ee55..c32b4f7 100644 --- a/Connectors.Form/frmMain.vb +++ b/Connectors.Form/frmMain.vb @@ -24,7 +24,6 @@ Partial Public Class frmMain AddInfoEntry("Application started.") AddInfoEntry("Version: {0}", Application.ProductVersion) - AddInfoEntry("Timer Interval: {0} min", ConfigManager.Config.TimerIntervalMin.ToString) AddDivider() Database = New MSSQLServer(LogConfig, ConfigManager.Config.ConnectionString) @@ -52,8 +51,11 @@ Partial Public Class frmMain End If If ConfigManager.Config.TimerIntervalMin > 0 Then + AddInfoEntry("Timer Interval: {0} min", ConfigManager.Config.TimerIntervalMin.ToString) SyncTimer.Interval = ConfigManager.Config.TimerIntervalMin * 60 * 1_000 StartTimer() + Else + AddInfoEntry("Timer Interval: Off", ConfigManager.Config.TimerIntervalMin.ToString) End If Catch ex As Exception