11-08-2023
This commit is contained in:
parent
3e41e5b469
commit
2579d7abdd
@ -11,6 +11,11 @@
|
|||||||
'''
|
'''
|
||||||
''' - {0} for ExtDocId
|
''' - {0} for ExtDocId
|
||||||
''' - {1} for Filename
|
''' - {1} for Filename
|
||||||
|
'''
|
||||||
|
''' These placeholders are optional and will be replaced if they are found in the query
|
||||||
|
''' - [String1]
|
||||||
|
''' - for Sharepoint Path when Sharepoint Module is used
|
||||||
|
''' - not used in slt Module
|
||||||
''' </summary>
|
''' </summary>
|
||||||
Public Property SQLQueryExport As String = ""
|
Public Property SQLQueryExport As String = ""
|
||||||
''' <summary>
|
''' <summary>
|
||||||
@ -31,7 +36,7 @@
|
|||||||
''' <summary>
|
''' <summary>
|
||||||
''' The connection string of the sharepoint database. Should contain the tables AllDocs and AllDocStreams
|
''' The connection string of the sharepoint database. Should contain the tables AllDocs and AllDocStreams
|
||||||
''' </summary>
|
''' </summary>
|
||||||
Public Property SharepointConnectionString As String = ""
|
Public Property SharepointDatabase As String = ""
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
Public Class sltConfig
|
Public Class sltConfig
|
||||||
|
|||||||
@ -97,7 +97,9 @@
|
|||||||
<Compile Include="Config.vb" />
|
<Compile Include="Config.vb" />
|
||||||
<Compile Include="Modules\BaseModule.vb" />
|
<Compile Include="Modules\BaseModule.vb" />
|
||||||
<Compile Include="Modules\ISync.vb" />
|
<Compile Include="Modules\ISync.vb" />
|
||||||
|
<Compile Include="Modules\Sharepoint\Constants.vb" />
|
||||||
<Compile Include="Modules\Sharepoint\Entities\SharepointDocument.vb" />
|
<Compile Include="Modules\Sharepoint\Entities\SharepointDocument.vb" />
|
||||||
|
<Compile Include="Modules\Sharepoint\SharepointException.vb" />
|
||||||
<Compile Include="Modules\Sharepoint\SharepointSync.vb" />
|
<Compile Include="Modules\Sharepoint\SharepointSync.vb" />
|
||||||
<Compile Include="Modules\slt\Constants.vb" />
|
<Compile Include="Modules\slt\Constants.vb" />
|
||||||
<Compile Include="Modules\slt\Entities\sltDocument.vb" />
|
<Compile Include="Modules\slt\Entities\sltDocument.vb" />
|
||||||
|
|||||||
@ -57,6 +57,13 @@ Public MustInherit Class BaseModule
|
|||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Friend Function ConvertFilenameToSlug(pFileName As String) As String
|
||||||
|
Dim oName = Path.GetFileNameWithoutExtension(pFileName)
|
||||||
|
Dim oExtension = Path.GetExtension(pFileName)
|
||||||
|
|
||||||
|
Return StringEx.ConvertTextToSlug(oName) & oExtension
|
||||||
|
End Function
|
||||||
|
|
||||||
Friend Function CopyFileToOutputPath(pFileContents As Byte(), pFilePath As String) As Boolean
|
Friend Function CopyFileToOutputPath(pFileContents As Byte(), pFilePath As String) As Boolean
|
||||||
Try
|
Try
|
||||||
Using oStream As New MemoryStream(pFileContents)
|
Using oStream As New MemoryStream(pFileContents)
|
||||||
|
|||||||
7
Connectors.Form/Modules/Sharepoint/Constants.vb
Normal file
7
Connectors.Form/Modules/Sharepoint/Constants.vb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Namespace Sharepoint
|
||||||
|
Public Class Constants
|
||||||
|
Public Enum ErrorType
|
||||||
|
GetDocumentError
|
||||||
|
End Enum
|
||||||
|
End Class
|
||||||
|
End Namespace
|
||||||
12
Connectors.Form/Modules/Sharepoint/SharepointException.vb
Normal file
12
Connectors.Form/Modules/Sharepoint/SharepointException.vb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Namespace Sharepoint
|
||||||
|
Public Class SharepointException
|
||||||
|
Inherits ApplicationException
|
||||||
|
|
||||||
|
Public ReadOnly ErrorType As Constants.ErrorType
|
||||||
|
|
||||||
|
Public Sub New(pErrorType As Constants.ErrorType, pMessage As String)
|
||||||
|
MyBase.New(pMessage)
|
||||||
|
ErrorType = pErrorType
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
|
End Namespace
|
||||||
@ -10,13 +10,11 @@ Namespace Sharepoint
|
|||||||
Inherits BaseModule
|
Inherits BaseModule
|
||||||
Implements ISync
|
Implements ISync
|
||||||
|
|
||||||
|
Private Const STRING1_PLACEHOLDER = "[String1]"
|
||||||
|
|
||||||
Public Overrides Property Name As String = "Sharepoint Sync"
|
Public Overrides Property Name As String = "Sharepoint Sync"
|
||||||
Public Overrides Property IsLoggedIn As Boolean
|
Public Overrides Property IsLoggedIn As Boolean
|
||||||
|
|
||||||
Private ReadOnly AllowedExtensions As New List(Of String) From {
|
|
||||||
"xls", "xlsx", "pdf", "dxf", "dwg", "doc", "docx", "ppt", "pptx", "jpg", "bmp", "msg", "eml", "png"
|
|
||||||
}
|
|
||||||
|
|
||||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
|
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
|
||||||
MyBase.New(pLogConfig, pDatabase, pConfig)
|
MyBase.New(pLogConfig, pDatabase, pConfig)
|
||||||
End Sub
|
End Sub
|
||||||
@ -37,31 +35,33 @@ Namespace Sharepoint
|
|||||||
Try
|
Try
|
||||||
Logger.Debug("Fetching document from Database..")
|
Logger.Debug("Fetching document from Database..")
|
||||||
Dim oDocument = Await GetDocumentContent(oDocId)
|
Dim oDocument = Await GetDocumentContent(oDocId)
|
||||||
|
|
||||||
|
If oDocument Is Nothing Then
|
||||||
|
Throw New SharepointException(Constants.ErrorType.GetDocumentError, "Document was not found!")
|
||||||
|
End If
|
||||||
Logger.Debug("Document fetched!")
|
Logger.Debug("Document fetched!")
|
||||||
|
|
||||||
AddInfoEntry("Document: [{0}]", oDocument.Name)
|
AddInfoEntry("Document: [{0}]", oDocument.Name)
|
||||||
Logger.Info("ExtDocId: [{0}]", oDocument.Id)
|
Logger.Info("ExtDocId: [{0}]", oDocument.Id)
|
||||||
|
|
||||||
' TODO: split path and build final sub path
|
Dim oFileName = ConvertFilenameToSlug(oDocument.Name)
|
||||||
' Beispiel Pfad:
|
Dim oSubPath = FileEx.CreateDateDirectory(Config.OutputDirectory)
|
||||||
' Netze/Betrieb/Baumassnahmen/Zählerwechsel 2012/Wasserzähler und Ausbauscheine/2012-06-25
|
If oSubPath Is Nothing Then
|
||||||
|
Throw New ApplicationException("Output sub path could not be created!")
|
||||||
Logger.Debug("Original Document Path: [{0}]", oDocument.Path)
|
End If
|
||||||
Dim oSplitPaths = oDocument.Path.Split("/"c).
|
Dim oFilePath = Path.Combine(oSubPath, oFileName)
|
||||||
Select(Function(folder) StringEx.ConvertTextToSlug(folder)).
|
Logger.Debug("Subdirectory [{0}] created.", oSubPath)
|
||||||
ToArray()
|
|
||||||
Dim oDocumentPath = String.Join("\", oSplitPaths)
|
|
||||||
Logger.Debug("Normalized Document Path: [{0}]", oDocument.Path)
|
|
||||||
|
|
||||||
Dim oDirectoryPath = Path.Combine(Config.OutputDirectory, oDocument.Path.Replace("/", "\"))
|
|
||||||
Dim oFilePath = Path.Combine(oDirectoryPath, oDocument.Name)
|
|
||||||
Logger.Debug("Final Document Path: [{0}]", oFilePath)
|
|
||||||
|
|
||||||
If CopyFileToOutputPath(oDocument.Data, oFilePath) = False Then
|
If CopyFileToOutputPath(oDocument.Data, oFilePath) = False Then
|
||||||
Throw New ApplicationException("File could not be created in output path!")
|
Throw New ApplicationException("File could not be created in output path!")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Dim oSQL = String.Format(Config.SQLQueryExport, oDocument.Id, oDocument.Name)
|
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)
|
Await Database.ExecuteNonQueryAsync(oSQL)
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
@ -79,6 +79,8 @@ Namespace Sharepoint
|
|||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Public Overrides Function Cleanup() As Task
|
Public Overrides Function Cleanup() As Task
|
||||||
Return Task.CompletedTask
|
Return Task.CompletedTask
|
||||||
End Function
|
End Function
|
||||||
@ -86,21 +88,24 @@ Namespace Sharepoint
|
|||||||
Public Overrides Function TestConfigIsComplete() As Boolean
|
Public Overrides Function TestConfigIsComplete() As Boolean
|
||||||
Dim oComplete = TestConfigIsCompleteBase()
|
Dim oComplete = TestConfigIsCompleteBase()
|
||||||
|
|
||||||
|
If Config.SharepointConfiguration.SharepointDatabase = String.Empty Then
|
||||||
|
AddWarnEntry("Configuration for 'SharepointDatabase' is empty.")
|
||||||
|
oComplete = False
|
||||||
|
End If
|
||||||
|
|
||||||
Return oComplete
|
Return oComplete
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Private Async Function GetDocumentContent(pDocumentId As String) As Task(Of Entities.SharepointDocument)
|
Private Async Function GetDocumentContent(pDocumentId As String) As Task(Of Entities.SharepointDocument)
|
||||||
Try
|
Try
|
||||||
Dim oExtensionList = AllowedExtensions.
|
Dim oSql As String = $"SELECT T.LeafName, T.DirName, T2.Content
|
||||||
Select(Function(ext) $"'{ext}'").
|
FROM {Config.SharepointConfiguration.SharepointDatabase}.[AllDocs] T
|
||||||
ToList()
|
INNER JOIN {Config.SharepointConfiguration.SharepointDatabase}.[AllDocStreams] T2
|
||||||
Dim oSql As String = $"SELECT T.*, T2.Content, T2.InternalVersion
|
|
||||||
FROM [AllDocs] T
|
|
||||||
INNER JOIN [AllDocStreams] T2
|
|
||||||
ON T.Id = T2.Id AND T.InternalVersion = T2.InternalVersion AND T.SiteId = T2.SiteId
|
ON T.Id = T2.Id AND T.InternalVersion = T2.InternalVersion AND T.SiteId = T2.SiteId
|
||||||
WHERE T.Extension in ({String.Join(",", oExtensionList)})
|
WHERE T.Id = '{pDocumentId}'"
|
||||||
T.Id = '{pDocumentId}'"
|
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||||
Dim oTable As DataTable = Database.GetDatatableWithConnection(oSql, Config.SharepointConfiguration.SharepointConnectionString)
|
|
||||||
|
|
||||||
If oTable Is Nothing OrElse oTable.Rows.Count = 0 Then
|
If oTable Is Nothing OrElse oTable.Rows.Count = 0 Then
|
||||||
Logger.Warn("Document with Id [{0}] was not found in SharePoint Database!", pDocumentId)
|
Logger.Warn("Document with Id [{0}] was not found in SharePoint Database!", pDocumentId)
|
||||||
@ -126,7 +131,5 @@ Namespace Sharepoint
|
|||||||
Return Nothing
|
Return Nothing
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
End Namespace
|
End Namespace
|
||||||
@ -16,7 +16,7 @@ Namespace slt
|
|||||||
Inherits BaseModule
|
Inherits BaseModule
|
||||||
Implements ISync
|
Implements ISync
|
||||||
|
|
||||||
Private ReadOnly FileEx As FileEx
|
Private ReadOnly MimeEx As MimeEx
|
||||||
|
|
||||||
Public Overrides Property Name As String = "slt Sync"
|
Public Overrides Property Name As String = "slt Sync"
|
||||||
Public Overrides Property IsLoggedIn As Boolean = False
|
Public Overrides Property IsLoggedIn As Boolean = False
|
||||||
@ -25,7 +25,7 @@ Namespace slt
|
|||||||
|
|
||||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
|
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
|
||||||
MyBase.New(pLogConfig, pDatabase, pConfig)
|
MyBase.New(pLogConfig, pDatabase, pConfig)
|
||||||
FileEx = New FileEx()
|
MimeEx = New MimeEx(pLogConfig)
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Overrides Async Function Run() As Threading.Tasks.Task Implements ISync.Run
|
Public Overrides Async Function Run() As Threading.Tasks.Task Implements ISync.Run
|
||||||
@ -123,7 +123,7 @@ Namespace slt
|
|||||||
pMimetype = "application/vnd.ms-outlook"
|
pMimetype = "application/vnd.ms-outlook"
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Dim oExtension = FileEx.GetExtension(pMimetype)
|
Dim oExtension = MimeEx.GetExtension(pMimetype)
|
||||||
Return StringEx.ConvertTextToSlug(pFilename) & oExtension
|
Return StringEx.ConvertTextToSlug(pFilename) & oExtension
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
@ -166,10 +166,10 @@ Namespace slt
|
|||||||
|
|
||||||
Dim oUrl = "/slt/External/System/Authentication/Json/Login"
|
Dim oUrl = "/slt/External/System/Authentication/Json/Login"
|
||||||
Dim oParams = New Dictionary(Of String, String) From {
|
Dim oParams = New Dictionary(Of String, String) From {
|
||||||
{"systemid", pSystemId},
|
{"systemid", pSystemId},
|
||||||
{"user", Config.sltConfiguration.Username},
|
{"user", Config.sltConfiguration.Username},
|
||||||
{"password", Config.sltConfiguration.Password}
|
{"password", Config.sltConfiguration.Password}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Debug("Username: [{0}]", Config.sltConfiguration.Username)
|
Logger.Debug("Username: [{0}]", Config.sltConfiguration.Username)
|
||||||
Logger.Debug("SystemId: [{0}]", pSystemId)
|
Logger.Debug("SystemId: [{0}]", pSystemId)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user