add autostart
This commit is contained in:
@@ -23,4 +23,5 @@
|
|||||||
Public Property SystemId As String = ""
|
Public Property SystemId As String = ""
|
||||||
|
|
||||||
Public Property Debug As Boolean = False
|
Public Property Debug As Boolean = False
|
||||||
|
Public Property Autostart As Boolean = True
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@@ -16,16 +16,18 @@ Partial Public Class frmMain
|
|||||||
Private ConfigManager As ConfigManager(Of Config)
|
Private ConfigManager As ConfigManager(Of Config)
|
||||||
Private Database As MSSQLServer
|
Private Database As MSSQLServer
|
||||||
Private Sync As sltSync
|
Private Sync As sltSync
|
||||||
|
Private FileEx As FileEx
|
||||||
|
|
||||||
Public Sub New()
|
Public Sub New()
|
||||||
InitializeComponent()
|
InitializeComponent()
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
Private Async Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||||
Try
|
Try
|
||||||
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.LocalUserAppDataPath, CompanyName:="Digital Data", ProductName:="sltSync")
|
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.LocalUserAppDataPath, CompanyName:="Digital Data", ProductName:="sltSync")
|
||||||
Logger = LogConfig.GetLogger()
|
Logger = LogConfig.GetLogger()
|
||||||
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath)
|
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath)
|
||||||
|
FileEx = New FileEx()
|
||||||
LogConfig.Debug = ConfigManager.Config.Debug
|
LogConfig.Debug = ConfigManager.Config.Debug
|
||||||
|
|
||||||
SyncTimer.Interval = ConfigManager.Config.TimerIntervalMin * 60 * 1_000
|
SyncTimer.Interval = ConfigManager.Config.TimerIntervalMin * 60 * 1_000
|
||||||
@@ -41,6 +43,10 @@ Partial Public Class frmMain
|
|||||||
If Database.DBInitialized = False Then
|
If Database.DBInitialized = False Then
|
||||||
AddWarnEntry("Database could not be initialized. Please check connection string.")
|
AddWarnEntry("Database could not be initialized. Please check connection string.")
|
||||||
Else
|
Else
|
||||||
|
If ConfigManager.Config.Autostart Then
|
||||||
|
Await RunSync()
|
||||||
|
End If
|
||||||
|
|
||||||
StartTimer()
|
StartTimer()
|
||||||
End If
|
End If
|
||||||
|
|
||||||
@@ -82,6 +88,10 @@ Partial Public Class frmMain
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Async Function Timer_Elapsed(sender As Object, e As System.EventArgs) As Threading.Tasks.Task Handles SyncTimer.Tick
|
Private Async Function Timer_Elapsed(sender As Object, e As System.EventArgs) As Threading.Tasks.Task Handles SyncTimer.Tick
|
||||||
|
Await RunSync()
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Async Function RunSync() As Threading.Tasks.Task
|
||||||
Try
|
Try
|
||||||
AddInfoEntry("Starting Sync.")
|
AddInfoEntry("Starting Sync.")
|
||||||
AddDivider()
|
AddDivider()
|
||||||
@@ -110,7 +120,6 @@ Partial Public Class frmMain
|
|||||||
AddInfoEntry("Document: [{0}]", oDocument.Name)
|
AddInfoEntry("Document: [{0}]", oDocument.Name)
|
||||||
Logger.Info("ExtDocId: [{0}]", oDocument.ExtDocId)
|
Logger.Info("ExtDocId: [{0}]", oDocument.ExtDocId)
|
||||||
|
|
||||||
'Dim oCleanFilename = StringEx.ConvertTextToSlug(oDocument.Name)
|
|
||||||
Dim oFileName = GetFilenameWithExtension(oDocument.Name, oDocument.DocMimeType)
|
Dim oFileName = GetFilenameWithExtension(oDocument.Name, oDocument.DocMimeType)
|
||||||
Dim oFilePath = Path.Combine(oOutputDirectory, oFileName)
|
Dim oFilePath = Path.Combine(oOutputDirectory, oFileName)
|
||||||
|
|
||||||
@@ -120,17 +129,9 @@ Partial Public Class frmMain
|
|||||||
End Using
|
End Using
|
||||||
End Using
|
End Using
|
||||||
|
|
||||||
Dim oSQL = String.Format(ConfigManager.Config.SQLQueryExport, oDocument.ExtDocId, oDocument.Name)
|
Dim oSQL = String.Format(ConfigManager.Config.SQLQueryExport, oDocument.ExtDocId, oFileName)
|
||||||
Await Database.ExecuteNonQueryAsync(oSQL)
|
Await Database.ExecuteNonQueryAsync(oSQL)
|
||||||
|
|
||||||
Catch ex As IOException
|
|
||||||
Logger.Error(ex)
|
|
||||||
Throw ex
|
|
||||||
|
|
||||||
Catch ex As SqlException
|
|
||||||
Logger.Error(ex)
|
|
||||||
Throw ex
|
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
AddWarnEntry("Error while running Sync: " & ex.Message)
|
AddWarnEntry("Error while running Sync: " & ex.Message)
|
||||||
@@ -143,20 +144,25 @@ Partial Public Class frmMain
|
|||||||
|
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
AddInfoEntry("Finished Sync.")
|
Try
|
||||||
AddInfoEntry("Logging Out..")
|
AddInfoEntry("Finished Sync.")
|
||||||
AddDivider()
|
AddInfoEntry("Logging Out..")
|
||||||
Await Sync.Logout()
|
AddDivider()
|
||||||
|
Await Sync.Logout()
|
||||||
|
Catch ex As Exception
|
||||||
|
Logger.Error(ex)
|
||||||
|
AddWarnEntry("Error while logging out: " & ex.Message)
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function GetFilenameWithExtension(pFilename As String, pMimetype As String) As String
|
Private Function GetFilenameWithExtension(pFilename As String, pMimetype As String) As String
|
||||||
Try
|
Try
|
||||||
Dim oExtension = MimeTypes.MimeTypeMap.GetExtension(pMimetype)
|
If pMimetype = "application/outlook" Then
|
||||||
If pFilename.EndsWith(oExtension) Then
|
pMimetype = "application/vnd.ms-outlook"
|
||||||
Return pFilename
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Return pFilename & oExtension
|
Dim oExtension = FileEx.GetExtension(pMimetype)
|
||||||
|
Return StringEx.ConvertTextToSlug(pFilename) & oExtension
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
AddWarnEntry("File [{0}] does not have a valid mimetype [{1}]. Returning original filename.", pFilename, pMimetype)
|
AddWarnEntry("File [{0}] does not have a valid mimetype [{1}]. Returning original filename.", pFilename, pMimetype)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="MediaTypeMap" version="2.1.0.0" targetFramework="net462" />
|
|
||||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net462" />
|
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net462" />
|
||||||
<package id="NLog" version="5.0.5" targetFramework="net462" />
|
<package id="NLog" version="5.0.5" targetFramework="net462" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -61,9 +61,6 @@
|
|||||||
<Reference Include="DigitalData.Modules.Logging">
|
<Reference Include="DigitalData.Modules.Logging">
|
||||||
<HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
|
<HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="MimeTypeMap, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\packages\MediaTypeMap.2.1.0.0\lib\net40\MimeTypeMap.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
Reference in New Issue
Block a user