add autostart
This commit is contained in:
parent
69da011eb3
commit
c7f4885078
@ -23,4 +23,5 @@
|
||||
Public Property SystemId As String = ""
|
||||
|
||||
Public Property Debug As Boolean = False
|
||||
Public Property Autostart As Boolean = True
|
||||
End Class
|
||||
|
||||
@ -16,16 +16,18 @@ Partial Public Class frmMain
|
||||
Private ConfigManager As ConfigManager(Of Config)
|
||||
Private Database As MSSQLServer
|
||||
Private Sync As sltSync
|
||||
Private FileEx As FileEx
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
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
|
||||
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.LocalUserAppDataPath, CompanyName:="Digital Data", ProductName:="sltSync")
|
||||
Logger = LogConfig.GetLogger()
|
||||
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath)
|
||||
FileEx = New FileEx()
|
||||
LogConfig.Debug = ConfigManager.Config.Debug
|
||||
|
||||
SyncTimer.Interval = ConfigManager.Config.TimerIntervalMin * 60 * 1_000
|
||||
@ -41,6 +43,10 @@ Partial Public Class frmMain
|
||||
If Database.DBInitialized = False Then
|
||||
AddWarnEntry("Database could not be initialized. Please check connection string.")
|
||||
Else
|
||||
If ConfigManager.Config.Autostart Then
|
||||
Await RunSync()
|
||||
End If
|
||||
|
||||
StartTimer()
|
||||
End If
|
||||
|
||||
@ -82,6 +88,10 @@ Partial Public Class frmMain
|
||||
End Sub
|
||||
|
||||
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
|
||||
AddInfoEntry("Starting Sync.")
|
||||
AddDivider()
|
||||
@ -110,7 +120,6 @@ Partial Public Class frmMain
|
||||
AddInfoEntry("Document: [{0}]", oDocument.Name)
|
||||
Logger.Info("ExtDocId: [{0}]", oDocument.ExtDocId)
|
||||
|
||||
'Dim oCleanFilename = StringEx.ConvertTextToSlug(oDocument.Name)
|
||||
Dim oFileName = GetFilenameWithExtension(oDocument.Name, oDocument.DocMimeType)
|
||||
Dim oFilePath = Path.Combine(oOutputDirectory, oFileName)
|
||||
|
||||
@ -120,17 +129,9 @@ Partial Public Class frmMain
|
||||
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)
|
||||
|
||||
Catch ex As IOException
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
|
||||
Catch ex As SqlException
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
AddWarnEntry("Error while running Sync: " & ex.Message)
|
||||
@ -143,20 +144,25 @@ Partial Public Class frmMain
|
||||
|
||||
End Try
|
||||
|
||||
AddInfoEntry("Finished Sync.")
|
||||
AddInfoEntry("Logging Out..")
|
||||
AddDivider()
|
||||
Await Sync.Logout()
|
||||
Try
|
||||
AddInfoEntry("Finished Sync.")
|
||||
AddInfoEntry("Logging Out..")
|
||||
AddDivider()
|
||||
Await Sync.Logout()
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
AddWarnEntry("Error while logging out: " & ex.Message)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetFilenameWithExtension(pFilename As String, pMimetype As String) As String
|
||||
Try
|
||||
Dim oExtension = MimeTypes.MimeTypeMap.GetExtension(pMimetype)
|
||||
If pFilename.EndsWith(oExtension) Then
|
||||
Return pFilename
|
||||
If pMimetype = "application/outlook" Then
|
||||
pMimetype = "application/vnd.ms-outlook"
|
||||
End If
|
||||
|
||||
Return pFilename & oExtension
|
||||
Dim oExtension = FileEx.GetExtension(pMimetype)
|
||||
Return StringEx.ConvertTextToSlug(pFilename) & oExtension
|
||||
|
||||
Catch ex As Exception
|
||||
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"?>
|
||||
<packages>
|
||||
<package id="MediaTypeMap" version="2.1.0.0" targetFramework="net462" />
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net462" />
|
||||
<package id="NLog" version="5.0.5" targetFramework="net462" />
|
||||
</packages>
|
||||
@ -61,9 +61,6 @@
|
||||
<Reference Include="DigitalData.Modules.Logging">
|
||||
<HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
|
||||
</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">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user