Compare commits
2 Commits
d5e7ed90be
...
775418fb7a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
775418fb7a | ||
|
|
3fa731fe5f |
@ -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
|
||||
|
||||
@ -19,6 +19,7 @@ Public MustInherit Class BaseModule
|
||||
Public MustOverride Function TestConfigIsComplete() As Boolean Implements ISync.TestConfigIsComplete
|
||||
|
||||
Public Event OnLogEntry As EventHandler(Of String) Implements ISync.OnLogEntry
|
||||
Public Event OnFileProcessed As EventHandler(Of String) Implements ISync.OnFileProcessed
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
|
||||
MyBase.New(pLogConfig)
|
||||
@ -64,6 +65,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)
|
||||
@ -118,4 +137,8 @@ Public MustInherit Class BaseModule
|
||||
Friend Sub AddDivider()
|
||||
RaiseEvent OnLogEntry(Me, "---")
|
||||
End Sub
|
||||
|
||||
Friend Sub RaiseFileProcessed(pFilePath As String)
|
||||
RaiseEvent OnFileProcessed(Me, pFilePath)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
@ -8,4 +8,5 @@ Public Interface ISync
|
||||
Function TestConfigIsComplete() As Boolean
|
||||
|
||||
Event OnLogEntry As EventHandler(Of String)
|
||||
Event OnFileProcessed As EventHandler(Of String)
|
||||
End Interface
|
||||
|
||||
@ -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,33 +43,24 @@ 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)
|
||||
|
||||
RaiseFileProcessed(oFilePath)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
AddWarnEntry("Error while running Sync: " & ex.Message)
|
||||
End Try
|
||||
Next
|
||||
|
||||
'TODO
|
||||
|
||||
AddInfoEntry("Finished Sync.")
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
|
||||
@ -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!")
|
||||
@ -69,6 +65,8 @@ Namespace slt
|
||||
Dim oSQL = String.Format(Config.SQLQueryExport, oDocument.ExtDocId, oFileName)
|
||||
Await Database.ExecuteNonQueryAsync(oSQL)
|
||||
|
||||
RaiseFileProcessed(oFilePath)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
AddWarnEntry("Error while running Sync: " & ex.Message)
|
||||
|
||||
50
Connectors.Form/frmMain.Designer.vb
generated
50
Connectors.Form/frmMain.Designer.vb
generated
@ -31,6 +31,7 @@
|
||||
Me.btnSyncStart = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.btnStopSync = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.BarButtonItem1 = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.btnForceSync = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.RibbonPage1 = New DevExpress.XtraBars.Ribbon.RibbonPage()
|
||||
Me.RibbonPageGroup1 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup()
|
||||
Me.RibbonPageGroup2 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup()
|
||||
@ -39,7 +40,9 @@
|
||||
Me.TrayMenu = New System.Windows.Forms.ContextMenuStrip(Me.components)
|
||||
Me.btnToggleWindow = New System.Windows.Forms.ToolStripMenuItem()
|
||||
Me.btnExit = New System.Windows.Forms.ToolStripMenuItem()
|
||||
Me.btnForceSync = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.RibbonStatusBar1 = New DevExpress.XtraBars.Ribbon.RibbonStatusBar()
|
||||
Me.txtFilesProcessed = New DevExpress.XtraBars.BarStaticItem()
|
||||
Me.txtErrorsOccurred = New DevExpress.XtraBars.BarStaticItem()
|
||||
CType(Me.ListBoxControl1, System.ComponentModel.ISupportInitialize).BeginInit()
|
||||
CType(Me.RibbonControl1, System.ComponentModel.ISupportInitialize).BeginInit()
|
||||
Me.TrayMenu.SuspendLayout()
|
||||
@ -57,9 +60,9 @@
|
||||
'
|
||||
Me.RibbonControl1.CommandLayout = DevExpress.XtraBars.Ribbon.CommandLayout.Simplified
|
||||
Me.RibbonControl1.ExpandCollapseItem.Id = 0
|
||||
Me.RibbonControl1.Items.AddRange(New DevExpress.XtraBars.BarItem() {Me.RibbonControl1.ExpandCollapseItem, Me.RibbonControl1.SearchEditItem, Me.btnSyncStart, Me.btnStopSync, Me.BarButtonItem1, Me.btnForceSync})
|
||||
Me.RibbonControl1.Items.AddRange(New DevExpress.XtraBars.BarItem() {Me.RibbonControl1.ExpandCollapseItem, Me.RibbonControl1.SearchEditItem, Me.btnSyncStart, Me.btnStopSync, Me.BarButtonItem1, Me.btnForceSync, Me.txtFilesProcessed, Me.txtErrorsOccurred})
|
||||
Me.RibbonControl1.Location = New System.Drawing.Point(0, 0)
|
||||
Me.RibbonControl1.MaxItemId = 5
|
||||
Me.RibbonControl1.MaxItemId = 7
|
||||
Me.RibbonControl1.Name = "RibbonControl1"
|
||||
Me.RibbonControl1.Pages.AddRange(New DevExpress.XtraBars.Ribbon.RibbonPage() {Me.RibbonPage1})
|
||||
Me.RibbonControl1.ShowApplicationButton = DevExpress.Utils.DefaultBoolean.[False]
|
||||
@ -68,6 +71,7 @@
|
||||
Me.RibbonControl1.ShowPageHeadersMode = DevExpress.XtraBars.Ribbon.ShowPageHeadersMode.Hide
|
||||
Me.RibbonControl1.ShowToolbarCustomizeItem = False
|
||||
Me.RibbonControl1.Size = New System.Drawing.Size(632, 63)
|
||||
Me.RibbonControl1.StatusBar = Me.RibbonStatusBar1
|
||||
Me.RibbonControl1.Toolbar.ShowCustomizeItem = False
|
||||
'
|
||||
'btnSyncStart
|
||||
@ -92,6 +96,14 @@
|
||||
Me.BarButtonItem1.ImageOptions.SvgImage = CType(resources.GetObject("BarButtonItem1.ImageOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage)
|
||||
Me.BarButtonItem1.Name = "BarButtonItem1"
|
||||
'
|
||||
'btnForceSync
|
||||
'
|
||||
Me.btnForceSync.Caption = "Sync Auslösen"
|
||||
Me.btnForceSync.Enabled = False
|
||||
Me.btnForceSync.Id = 4
|
||||
Me.btnForceSync.ImageOptions.SvgImage = CType(resources.GetObject("btnForceSync.ImageOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage)
|
||||
Me.btnForceSync.Name = "btnForceSync"
|
||||
'
|
||||
'RibbonPage1
|
||||
'
|
||||
Me.RibbonPage1.Groups.AddRange(New DevExpress.XtraBars.Ribbon.RibbonPageGroup() {Me.RibbonPageGroup1, Me.RibbonPageGroup2})
|
||||
@ -120,7 +132,7 @@
|
||||
'
|
||||
Me.TrayIcon.ContextMenuStrip = Me.TrayMenu
|
||||
Me.TrayIcon.Icon = CType(resources.GetObject("TrayIcon.Icon"), System.Drawing.Icon)
|
||||
Me.TrayIcon.Text = "sltSync"
|
||||
Me.TrayIcon.Text = "Connector"
|
||||
Me.TrayIcon.Visible = True
|
||||
'
|
||||
'TrayMenu
|
||||
@ -141,24 +153,39 @@
|
||||
Me.btnExit.Size = New System.Drawing.Size(184, 22)
|
||||
Me.btnExit.Text = "Beenden"
|
||||
'
|
||||
'btnForceSync
|
||||
'RibbonStatusBar1
|
||||
'
|
||||
Me.btnForceSync.Caption = "Sync Auslösen"
|
||||
Me.btnForceSync.Enabled = False
|
||||
Me.btnForceSync.Id = 4
|
||||
Me.btnForceSync.ImageOptions.SvgImage = CType(resources.GetObject("btnForceSync.ImageOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage)
|
||||
Me.btnForceSync.Name = "btnForceSync"
|
||||
Me.RibbonStatusBar1.ItemLinks.Add(Me.txtFilesProcessed)
|
||||
Me.RibbonStatusBar1.ItemLinks.Add(Me.txtErrorsOccurred)
|
||||
Me.RibbonStatusBar1.Location = New System.Drawing.Point(0, 254)
|
||||
Me.RibbonStatusBar1.Name = "RibbonStatusBar1"
|
||||
Me.RibbonStatusBar1.Ribbon = Me.RibbonControl1
|
||||
Me.RibbonStatusBar1.Size = New System.Drawing.Size(632, 24)
|
||||
'
|
||||
'txtFilesProcessed
|
||||
'
|
||||
Me.txtFilesProcessed.Caption = "Keine Dateien"
|
||||
Me.txtFilesProcessed.Id = 5
|
||||
Me.txtFilesProcessed.Name = "txtFilesProcessed"
|
||||
'
|
||||
'txtErrorsOccurred
|
||||
'
|
||||
Me.txtErrorsOccurred.Caption = "Keine Dateien"
|
||||
Me.txtErrorsOccurred.Id = 6
|
||||
Me.txtErrorsOccurred.Name = "txtErrorsOccurred"
|
||||
'
|
||||
'frmMain
|
||||
'
|
||||
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
|
||||
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
||||
Me.ClientSize = New System.Drawing.Size(632, 278)
|
||||
Me.Controls.Add(Me.RibbonStatusBar1)
|
||||
Me.Controls.Add(Me.ListBoxControl1)
|
||||
Me.Controls.Add(Me.RibbonControl1)
|
||||
Me.IconOptions.SvgImage = CType(resources.GetObject("frmMain.IconOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage)
|
||||
Me.Name = "frmMain"
|
||||
Me.Ribbon = Me.RibbonControl1
|
||||
Me.StatusBar = Me.RibbonStatusBar1
|
||||
Me.Text = "Sync"
|
||||
CType(Me.ListBoxControl1, System.ComponentModel.ISupportInitialize).EndInit()
|
||||
CType(Me.RibbonControl1, System.ComponentModel.ISupportInitialize).EndInit()
|
||||
@ -182,6 +209,9 @@
|
||||
Friend WithEvents btnToggleWindow As ToolStripMenuItem
|
||||
Friend WithEvents btnExit As ToolStripMenuItem
|
||||
Friend WithEvents btnForceSync As DevExpress.XtraBars.BarButtonItem
|
||||
Friend WithEvents txtFilesProcessed As DevExpress.XtraBars.BarStaticItem
|
||||
Friend WithEvents txtErrorsOccurred As DevExpress.XtraBars.BarStaticItem
|
||||
Friend WithEvents RibbonStatusBar1 As DevExpress.XtraBars.Ribbon.RibbonStatusBar
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
Imports System.ComponentModel
|
||||
Imports System.Runtime.Remoting.Messaging
|
||||
Imports DevExpress.XtraEditors.ViewInfo
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Modules.Database
|
||||
@ -11,6 +12,25 @@ Partial Public Class frmMain
|
||||
Private Database As MSSQLServer
|
||||
Private Sync As ISync
|
||||
|
||||
Private FilesProcessed As Integer = 0
|
||||
Private ErrorsOccurred As Integer = 0
|
||||
|
||||
Public Enum LogLevel
|
||||
Info
|
||||
Warning
|
||||
[Error]
|
||||
End Enum
|
||||
|
||||
Private Class LogLine
|
||||
Public Message As String
|
||||
Public Level As LogLevel
|
||||
Public CreatedWhen As Date = Now
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return $"{CreatedWhen.ToShortDateString} {CreatedWhen.ToShortTimeString} {Message}"
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
End Sub
|
||||
@ -24,7 +44,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)
|
||||
@ -32,6 +51,7 @@ Partial Public Class frmMain
|
||||
|
||||
' Load Form Title from Module
|
||||
Text = Sync.Name
|
||||
TrayIcon.Text = Sync.Name
|
||||
|
||||
If Sync Is Nothing Then
|
||||
AddWarnEntry("ActiveModule '{0}' is not implemented!", ConfigManager.Config.ActiveModule)
|
||||
@ -52,13 +72,16 @@ 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
|
||||
Logger.Error(ex)
|
||||
AddWarnEntry($"Error while loading the application: {ex.Message}")
|
||||
AddErrorEntry($"Error while loading the application: {ex.Message}")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
@ -126,17 +149,43 @@ Partial Public Class frmMain
|
||||
|
||||
Private Sub AddInfoEntry(pMessage As String, ParamArray pArgs As Object())
|
||||
Logger.Info(pMessage, pArgs)
|
||||
ListBoxControl1.Items.Add(Now & " " & String.Format(pMessage, pArgs))
|
||||
|
||||
Dim oItem = New LogLine With {
|
||||
.Message = String.Format(pMessage, pArgs),
|
||||
.Level = LogLevel.Info
|
||||
}
|
||||
|
||||
ListBoxControl1.Items.Add(oItem)
|
||||
ListBoxControl1.MakeItemVisible(ListBoxControl1.Items.Count - 1)
|
||||
End Sub
|
||||
|
||||
Private Sub AddWarnEntry(pMessage As String, ParamArray pArgs As Object())
|
||||
Logger.Info(pMessage, pArgs)
|
||||
ListBoxControl1.Items.Add(String.Format(pMessage, pArgs))
|
||||
|
||||
Dim oItem = New LogLine With {
|
||||
.Message = String.Format(pMessage, pArgs),
|
||||
.Level = LogLevel.Warning
|
||||
}
|
||||
|
||||
ListBoxControl1.Items.Add(oItem)
|
||||
End Sub
|
||||
|
||||
Private Sub AddErrorEntry(pMessage As String, ParamArray pArgs As Object())
|
||||
Logger.Info(pMessage, pArgs)
|
||||
|
||||
Dim oItem = New LogLine With {
|
||||
.Message = String.Format(pMessage, pArgs),
|
||||
.Level = LogLevel.Error
|
||||
}
|
||||
|
||||
ListBoxControl1.Items.Add(oItem)
|
||||
End Sub
|
||||
|
||||
Private Sub AddDivider()
|
||||
ListBoxControl1.Items.Add("=====================================")
|
||||
ListBoxControl1.Items.Add(New LogLine With {
|
||||
.Message = "-------------------------------------",
|
||||
.Level = LogLevel.Info
|
||||
})
|
||||
End Sub
|
||||
|
||||
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
|
||||
@ -183,4 +232,17 @@ Partial Public Class frmMain
|
||||
Await Sync.Run()
|
||||
btnForceSync.Enabled = True
|
||||
End Sub
|
||||
|
||||
Private Sub ListBoxControl1_DrawItem(sender As Object, e As DevExpress.XtraEditors.ListBoxDrawItemEventArgs) Handles ListBoxControl1.DrawItem
|
||||
Dim oItem As LogLine = DirectCast(e.Item, LogLine)
|
||||
|
||||
Select Case oItem.Level
|
||||
Case LogLevel.Warning
|
||||
e.Appearance.ForeColor = Color.DarkOrange
|
||||
e.Appearance.FontStyleDelta = FontStyle.Bold
|
||||
Case LogLevel.Error
|
||||
e.Appearance.ForeColor = Color.DarkRed
|
||||
e.Appearance.FontStyleDelta = FontStyle.Bold
|
||||
End Select
|
||||
End Sub
|
||||
End Class
|
||||
Loading…
x
Reference in New Issue
Block a user