14-08-2023

This commit is contained in:
Jonathan Jenne
2023-08-14 16:48:21 +02:00
parent d5e7ed90be
commit 3fa731fe5f
5 changed files with 28 additions and 23 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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!")

View File

@@ -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