diff --git a/sltSync.Test/AuthTest.vb b/sltSync.Test/AuthTest.vb new file mode 100644 index 0000000..70c77d0 --- /dev/null +++ b/sltSync.Test/AuthTest.vb @@ -0,0 +1,41 @@ +Imports Microsoft.VisualStudio.TestTools.UnitTesting +Imports Newtonsoft.Json +Imports sltSync + +Namespace sltSync.Test + + Public Class AuthTest + ReadOnly oAvailableSystemsResponse As String = "{""Message"":null,""State"":true,""Type"":40,""Value"":[{""Deactivated"":false,""Description"":"""",""Priority"":1,""SystemID"":""764f0168-0005-43ca-bfe7-267b5fe254f4"",""SystemName"":""Prod: e.wa riss Netze GmbH""}]}" + ReadOnly oLoginResponse As String = "{""Message"":null,""State"":true,""Type"":40,""Value"":""18487109-f789-4094-9f18-4f0ce85461ca""}" + ReadOnly oLogoutResponse As String = "{""Message"": null,""State"":true,""Type"":40}" + + + Sub AvailableSystemsTest() + Dim oResp As sltAvailableSystemResponse = JsonConvert.DeserializeObject(Of sltAvailableSystemResponse)(oAvailableSystemsResponse) + + Assert.AreEqual(True, oResp.State) + Assert.AreEqual(40, oResp.Type) + Assert.AreEqual(1, oResp.Value.Count) + End Sub + + + Sub LoginTest() + Dim oResp As sltLoginResponse = JsonConvert.DeserializeObject(Of sltLoginResponse)(oLoginResponse) + + Assert.AreEqual(Nothing, oResp.Message) + Assert.AreEqual(True, oResp.State) + Assert.AreEqual(40, oResp.Type) + Assert.AreEqual("18487109-f789-4094-9f18-4f0ce85461ca", oResp.Value) + End Sub + + + Sub Logout() + Dim oResp As sltLogoutResponse = JsonConvert.DeserializeObject(Of sltLogoutResponse)(oLogoutResponse) + + Assert.AreEqual(Nothing, oResp.Message) + Assert.AreEqual(True, oResp.State) + Assert.AreEqual(40, oResp.Type) + End Sub + End Class +End Namespace + diff --git a/sltSync.Test/sltSync.Test.vbproj b/sltSync.Test/sltSync.Test.vbproj new file mode 100644 index 0000000..5822573 --- /dev/null +++ b/sltSync.Test/sltSync.Test.vbproj @@ -0,0 +1,22 @@ + + + + sltSync.Test + net6.0 + + false + true + + + + + + + + + + + + + + diff --git a/sltSync.sln b/sltSync.sln new file mode 100644 index 0000000..a344af0 --- /dev/null +++ b/sltSync.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33516.290 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "sltSync", "sltSync\sltSync.vbproj", "{A439775B-FF9C-4C46-9395-79356A8FC601}" +EndProject +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "sltSync.Test", "sltSync.Test\sltSync.Test.vbproj", "{71398AA2-8017-4CE2-8E29-187D38324FE7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A439775B-FF9C-4C46-9395-79356A8FC601}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A439775B-FF9C-4C46-9395-79356A8FC601}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A439775B-FF9C-4C46-9395-79356A8FC601}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A439775B-FF9C-4C46-9395-79356A8FC601}.Release|Any CPU.Build.0 = Release|Any CPU + {71398AA2-8017-4CE2-8E29-187D38324FE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {71398AA2-8017-4CE2-8E29-187D38324FE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {71398AA2-8017-4CE2-8E29-187D38324FE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {71398AA2-8017-4CE2-8E29-187D38324FE7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3693DCD7-5A26-4718-B8A4-81F662966E3E} + EndGlobalSection +EndGlobal diff --git a/sltSync/Config.vb b/sltSync/Config.vb new file mode 100644 index 0000000..b824907 --- /dev/null +++ b/sltSync/Config.vb @@ -0,0 +1,26 @@ +Public Class Config + Public Property Hostname As String = "" + Public Property Port As String = "" + Public Property Username As String = "" + Public Property Password As String = "" + + Public Property ConnectionString As String = "" + ''' + ''' This query must contain two placeholders: + ''' + ''' - {0} for ExtDocId + ''' - {1} for Filename + ''' + Public Property SQLQueryExport As String = "" + ''' + ''' This query needs to return a table with exactly one column, which represents the ExtDocId + ''' + Public Property SQLQueryFetch As String = "" + + Public Property OutputDirectory As String = "" + Public Property TimerIntervalMin As Integer = 10 + + Public Property SystemId As String = "" + + Public Property Debug As Boolean = False +End Class diff --git a/sltSync/Entities/sltAvailableSystem.vb b/sltSync/Entities/sltAvailableSystem.vb new file mode 100644 index 0000000..11f79ac --- /dev/null +++ b/sltSync/Entities/sltAvailableSystem.vb @@ -0,0 +1,10 @@ +Namespace Entities + Public Class sltAvailableSystem + Public SystemId As String + Public SystemName As String + Public Description As String + Public Deactivated As Boolean + Public Priority As Integer + End Class + +End Namespace \ No newline at end of file diff --git a/sltSync/Entities/sltDocument.vb b/sltSync/Entities/sltDocument.vb new file mode 100644 index 0000000..3837095 --- /dev/null +++ b/sltSync/Entities/sltDocument.vb @@ -0,0 +1,15 @@ +Namespace Entities + Public Class sltDocument + Public Property ExtDocId As String + Public Property Name As String + Public Property Description As String + Public Property DocMimeType As String + Public Property DocModifyTimestamp As String + Public Property DocOrigin As String + Public Property DocOriginalFilename As String + Public Property DocSize As Long + Public Property StorPlaceId As String + Public Property ExternalId As String + Public Property Data As Byte() + End Class +End Namespace diff --git a/sltSync/My Project/Application.Designer.vb b/sltSync/My Project/Application.Designer.vb new file mode 100644 index 0000000..a276a48 --- /dev/null +++ b/sltSync/My Project/Application.Designer.vb @@ -0,0 +1,38 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + 'NOTE: This file is auto-generated; do not modify it directly. To make changes, + ' or if you encounter build errors in this file, go to the Project Designer + ' (go to Project Properties or double-click the My Project node in + ' Solution Explorer), and make changes on the Application tab. + ' + Partial Friend Class MyApplication + + _ + Public Sub New() + MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) + Me.IsSingleInstance = false + Me.EnableVisualStyles = true + Me.SaveMySettingsOnExit = true + Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses + End Sub + + _ + Protected Overrides Sub OnCreateMainForm() + Me.MainForm = Global.sltSync.frmMain + End Sub + End Class +End Namespace diff --git a/sltSync/My Project/Application.myapp b/sltSync/My Project/Application.myapp new file mode 100644 index 0000000..1243847 --- /dev/null +++ b/sltSync/My Project/Application.myapp @@ -0,0 +1,11 @@ + + + true + Form1 + false + 0 + true + 0 + 0 + true + diff --git a/sltSync/My Project/AssemblyInfo.vb b/sltSync/My Project/AssemblyInfo.vb new file mode 100644 index 0000000..445d76c --- /dev/null +++ b/sltSync/My Project/AssemblyInfo.vb @@ -0,0 +1,36 @@ +Imports System.Reflection +Imports System.Runtime.CompilerServices +Imports System.Runtime.InteropServices + +' General Information about an assembly is controlled through the following +' set of attributes. Change these attribute values to modify the information +' associated with an assembly. + + + + + + + + + +' Setting ComVisible to false makes the types in this assembly not visible +' to COM components. If you need to access a type in this assembly from +' COM, set the ComVisible attribute to true on that type. + + +' The following GUID is for the ID of the typelib if this project is exposed to COM + + +' Version information for an assembly consists of the following four values: +' +' Major Version +' Minor Version +' Build Number +' Revision +' +' You can specify all the values or you can default the Build and Revision Numbers +' by using the '*' as shown below: +' [assembly: AssemblyVersion("1.0.*")] + + diff --git a/sltSync/My Project/Resources.Designer.vb b/sltSync/My Project/Resources.Designer.vb new file mode 100644 index 0000000..e5336e7 --- /dev/null +++ b/sltSync/My Project/Resources.Designer.vb @@ -0,0 +1,61 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.18034 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Namespace My.Resources + + + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + ' This class was auto-generated by the StronglyTypedResourceBuilder + ' class via a tool like ResGen or Visual Studio. + ' To add or remove a member, edit your .ResX file then rerun ResGen + ' with the /str option, or rebuild your VS project. + + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ' internal Resources() + ' { + ' } + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If (resourceMan Is Nothing) Then + Dim temp As New Global.System.Resources.ResourceManager("Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set(ByVal value As System.Globalization.CultureInfo) + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/sltSync/My Project/Resources.resx b/sltSync/My Project/Resources.resx new file mode 100644 index 0000000..901f10d --- /dev/null +++ b/sltSync/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/sltSync/My Project/Settings.Designer.vb b/sltSync/My Project/Settings.Designer.vb new file mode 100644 index 0000000..9b8067d --- /dev/null +++ b/sltSync/My Project/Settings.Designer.vb @@ -0,0 +1,26 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.18034 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Namespace My + + + + Friend NotInheritable Partial Class Settings + Inherits System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As Settings = (CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()), Settings)) + + Public Shared ReadOnly Property [Default]() As Settings + Get + Return defaultInstance + End Get + End Property + End Class +End Namespace diff --git a/sltSync/My Project/Settings.settings b/sltSync/My Project/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/sltSync/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/sltSync/My Project/licenses.licx b/sltSync/My Project/licenses.licx new file mode 100644 index 0000000..773d16c --- /dev/null +++ b/sltSync/My Project/licenses.licx @@ -0,0 +1 @@ +DevExpress.XtraBars.Ribbon.RibbonControl, DevExpress.XtraBars.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a diff --git a/sltSync/Responses/sltDocumentResponse.vb b/sltSync/Responses/sltDocumentResponse.vb new file mode 100644 index 0000000..7d9c1b6 --- /dev/null +++ b/sltSync/Responses/sltDocumentResponse.vb @@ -0,0 +1,5 @@ +Public Class sltDocumentResponse + Inherits sltResponse + + Public Property Value As Entities.sltDocument +End Class diff --git a/sltSync/Responses/sltLoginResponse.vb b/sltSync/Responses/sltLoginResponse.vb new file mode 100644 index 0000000..51d2171 --- /dev/null +++ b/sltSync/Responses/sltLoginResponse.vb @@ -0,0 +1,5 @@ +Public Class sltLoginResponse + Inherits sltResponse + + Public Property Value As String +End Class diff --git a/sltSync/Responses/sltLogoutResponse.vb b/sltSync/Responses/sltLogoutResponse.vb new file mode 100644 index 0000000..39440e0 --- /dev/null +++ b/sltSync/Responses/sltLogoutResponse.vb @@ -0,0 +1,3 @@ +Public Class sltLogoutResponse + Inherits sltResponse +End Class diff --git a/sltSync/Responses/sltMandatorResponse.vb b/sltSync/Responses/sltMandatorResponse.vb new file mode 100644 index 0000000..0f09630 --- /dev/null +++ b/sltSync/Responses/sltMandatorResponse.vb @@ -0,0 +1,5 @@ +Public Class sltAvailableSystemResponse + Inherits sltResponse + + Public Property Value As List(Of Entities.sltAvailableSystem) +End Class diff --git a/sltSync/Responses/sltResponse.vb b/sltSync/Responses/sltResponse.vb new file mode 100644 index 0000000..4d14133 --- /dev/null +++ b/sltSync/Responses/sltResponse.vb @@ -0,0 +1,5 @@ +Public MustInherit Class sltResponse + Public Property Message As String + Public Property State As Boolean + Public Property Type As Integer +End Class diff --git a/sltSync/app.config b/sltSync/app.config new file mode 100644 index 0000000..917d596 --- /dev/null +++ b/sltSync/app.config @@ -0,0 +1,41 @@ + + + + +
+ + + + + + System + + + True + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sltSync/frmMain.Designer.vb b/sltSync/frmMain.Designer.vb new file mode 100644 index 0000000..ef22cbd --- /dev/null +++ b/sltSync/frmMain.Designer.vb @@ -0,0 +1,138 @@ +Partial Public Class frmMain + Inherits DevExpress.XtraBars.Ribbon.RibbonForm + + ''' + ''' Required designer variable. + ''' + Private components As System.ComponentModel.IContainer = Nothing + + ''' + ''' Clean up any resources being used. + ''' + ''' true if managed resources should be disposed; otherwise, false. + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + If disposing AndAlso (components IsNot Nothing) Then + components.Dispose() + End If + MyBase.Dispose(disposing) + End Sub + +#Region "Windows Form Designer generated code" + + ''' + ''' Required method for Designer support - do not modify + ''' the contents of this method with the code editor. + ''' + Private Sub InitializeComponent() + Me.components = New System.ComponentModel.Container() + Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmMain)) + Me.ListBoxControl1 = New DevExpress.XtraEditors.ListBoxControl() + Me.RibbonControl1 = New DevExpress.XtraBars.Ribbon.RibbonControl() + Me.RibbonPage1 = New DevExpress.XtraBars.Ribbon.RibbonPage() + Me.RibbonPageGroup1 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup() + Me.btnSyncStart = New DevExpress.XtraBars.BarButtonItem() + Me.btnStopSync = New DevExpress.XtraBars.BarButtonItem() + Me.RibbonPageGroup2 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup() + Me.BarButtonItem1 = New DevExpress.XtraBars.BarButtonItem() + Me.SyncTimer = New System.Windows.Forms.Timer(Me.components) + CType(Me.ListBoxControl1, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.RibbonControl1, System.ComponentModel.ISupportInitialize).BeginInit() + Me.SuspendLayout() + ' + 'ListBoxControl1 + ' + Me.ListBoxControl1.Dock = System.Windows.Forms.DockStyle.Fill + Me.ListBoxControl1.Location = New System.Drawing.Point(0, 63) + Me.ListBoxControl1.Name = "ListBoxControl1" + Me.ListBoxControl1.Size = New System.Drawing.Size(632, 215) + Me.ListBoxControl1.TabIndex = 0 + ' + 'RibbonControl1 + ' + 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.RibbonControl1.Location = New System.Drawing.Point(0, 0) + Me.RibbonControl1.MaxItemId = 4 + Me.RibbonControl1.Name = "RibbonControl1" + Me.RibbonControl1.Pages.AddRange(New DevExpress.XtraBars.Ribbon.RibbonPage() {Me.RibbonPage1}) + Me.RibbonControl1.ShowApplicationButton = DevExpress.Utils.DefaultBoolean.[False] + Me.RibbonControl1.ShowDisplayOptionsMenuButton = DevExpress.Utils.DefaultBoolean.[False] + Me.RibbonControl1.ShowPageHeadersMode = DevExpress.XtraBars.Ribbon.ShowPageHeadersMode.Hide + Me.RibbonControl1.ShowToolbarCustomizeItem = False + Me.RibbonControl1.Size = New System.Drawing.Size(632, 63) + Me.RibbonControl1.Toolbar.ShowCustomizeItem = False + ' + 'RibbonPage1 + ' + Me.RibbonPage1.Groups.AddRange(New DevExpress.XtraBars.Ribbon.RibbonPageGroup() {Me.RibbonPageGroup1, Me.RibbonPageGroup2}) + Me.RibbonPage1.Name = "RibbonPage1" + Me.RibbonPage1.Text = "RibbonPage1" + ' + 'RibbonPageGroup1 + ' + Me.RibbonPageGroup1.ItemLinks.Add(Me.btnSyncStart) + Me.RibbonPageGroup1.ItemLinks.Add(Me.btnStopSync) + Me.RibbonPageGroup1.Name = "RibbonPageGroup1" + Me.RibbonPageGroup1.Text = "RibbonPageGroup1" + ' + 'btnSyncStart + ' + Me.btnSyncStart.Caption = "Sync starten" + Me.btnSyncStart.Id = 1 + Me.btnSyncStart.ImageOptions.SvgImage = CType(resources.GetObject("btnSyncStart.ImageOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage) + Me.btnSyncStart.Name = "btnSyncStart" + ' + 'btnStopSync + ' + Me.btnStopSync.Caption = "Sync stoppen" + Me.btnStopSync.Enabled = False + Me.btnStopSync.Id = 2 + Me.btnStopSync.ImageOptions.SvgImage = CType(resources.GetObject("btnStopSync.ImageOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage) + Me.btnStopSync.Name = "btnStopSync" + ' + 'RibbonPageGroup2 + ' + Me.RibbonPageGroup2.Alignment = DevExpress.XtraBars.Ribbon.RibbonPageGroupAlignment.Far + Me.RibbonPageGroup2.ItemLinks.Add(Me.BarButtonItem1) + Me.RibbonPageGroup2.Name = "RibbonPageGroup2" + Me.RibbonPageGroup2.Text = "RibbonPageGroup2" + ' + 'BarButtonItem1 + ' + Me.BarButtonItem1.Caption = "Log öffnen" + Me.BarButtonItem1.Id = 3 + Me.BarButtonItem1.ImageOptions.SvgImage = CType(resources.GetObject("BarButtonItem1.ImageOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage) + Me.BarButtonItem1.Name = "BarButtonItem1" + ' + '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.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.Text = "sltSync" + CType(Me.ListBoxControl1, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.RibbonControl1, System.ComponentModel.ISupportInitialize).EndInit() + Me.ResumeLayout(False) + Me.PerformLayout() + + End Sub + + Friend WithEvents ListBoxControl1 As DevExpress.XtraEditors.ListBoxControl + Friend WithEvents RibbonControl1 As DevExpress.XtraBars.Ribbon.RibbonControl + Friend WithEvents RibbonPage1 As DevExpress.XtraBars.Ribbon.RibbonPage + Friend WithEvents btnSyncStart As DevExpress.XtraBars.BarButtonItem + Friend WithEvents btnStopSync As DevExpress.XtraBars.BarButtonItem + Friend WithEvents RibbonPageGroup1 As DevExpress.XtraBars.Ribbon.RibbonPageGroup + Friend WithEvents BarButtonItem1 As DevExpress.XtraBars.BarButtonItem + Friend WithEvents RibbonPageGroup2 As DevExpress.XtraBars.Ribbon.RibbonPageGroup + Friend WithEvents SyncTimer As Timer + +#End Region + +End Class diff --git a/sltSync/frmMain.resx b/sltSync/frmMain.resx new file mode 100644 index 0000000..b06c11d --- /dev/null +++ b/sltSync/frmMain.resx @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjIxLjIsIFZlcnNpb249MjEuMi40 + LjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjg4ZDE3NTRkNzAwZTQ5YQUBAAAAHURl + dkV4cHJlc3MuVXRpbHMuU3ZnLlN2Z0ltYWdlAQAAAAREYXRhBwICAAAACQMAAAAPAwAAANoCAAAC77u/ + PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz4NCjxzdmcgeD0iMHB4IiB5PSIwcHgi + IHZpZXdCb3g9IjAgMCAzMiAzMiIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv + MjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4bWw6c3Bh + Y2U9InByZXNlcnZlIiBpZD0iTGF5ZXJfMSIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAg + MzIgMzIiPg0KICA8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLlllbGxvd3tmaWxsOiNGRkIxMTU7fQoJ + LlJlZHtmaWxsOiNEMTFDMUM7fQoJLkJsdWV7ZmlsbDojMTE3N0Q3O30KCS5HcmVlbntmaWxsOiMwMzlD + MjM7fQoJLkJsYWNre2ZpbGw6IzcyNzI3Mjt9CgkuV2hpdGV7ZmlsbDojRkZGRkZGO30KCS5zdDB7b3Bh + Y2l0eTowLjU7fQoJLnN0MXtkaXNwbGF5Om5vbmU7fQoJLnN0MntkaXNwbGF5OmlubGluZTtmaWxsOiMw + MzlDMjM7fQoJLnN0M3tkaXNwbGF5OmlubGluZTtmaWxsOiNEMTFDMUM7fQoJLnN0NHtkaXNwbGF5Omlu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diff --git a/sltSync/frmMain.vb b/sltSync/frmMain.vb new file mode 100644 index 0000000..130b22a --- /dev/null +++ b/sltSync/frmMain.vb @@ -0,0 +1,247 @@ +Imports System.ComponentModel +Imports System.Configuration +Imports System.Data.SqlClient +Imports System.IO +Imports System.Text +Imports DigitalData.Modules.Base +Imports DigitalData.Modules.Base.IDB +Imports DigitalData.Modules.Config +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Logging +Imports Microsoft.Win32 + +Partial Public Class frmMain + Private LogConfig As LogConfig + Private Logger As Logger + Private ConfigManager As ConfigManager(Of Config) + Private Database As MSSQLServer + Private Sync As sltSync + + Public Sub New() + InitializeComponent() + End Sub + + Private 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) + LogConfig.Debug = ConfigManager.Config.Debug + + SyncTimer.Interval = ConfigManager.Config.TimerIntervalMin * 60 * 1_000 + + 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) + Sync = New sltSync(LogConfig, ConfigManager.Config) + + If Database.DBInitialized = False Then + AddWarnEntry("Database could not be initialized. Please check connection string.") + Else + StartTimer() + End If + + Catch ex As Exception + Logger.Error(ex) + AddWarnEntry($"Error while loading the application: {ex.Message}") + End Try + End Sub + + Private Async Function frmMain_Closing(sender As Object, e As CancelEventArgs) As Threading.Tasks.Task Handles Me.Closing + Try + If Sync IsNot Nothing AndAlso Sync.IsLoggedIn Then + AddInfoEntry("Logging out..") + Await Sync.Logout() + End If + Catch ex As Exception + Logger.Error(ex) + AddWarnEntry($"Error while closing the application: {ex.Message}") + End Try + End Function + + Private Sub StartTimer() + If TestConfigurationIsComplete() = False Then + AddInfoEntry("Configuration is incomplete. Stopping.") + AddDivider() + Else + AddInfoEntry("Starting timer..") + btnStopSync.Enabled = True + btnSyncStart.Enabled = False + SyncTimer.Enabled = True + End If + End Sub + + Private Sub StopTimer() + AddInfoEntry("Stopping timer..") + btnStopSync.Enabled = False + btnSyncStart.Enabled = True + SyncTimer.Enabled = False + End Sub + + Private Async Function Timer_Elapsed(sender As Object, e As System.EventArgs) As Threading.Tasks.Task Handles SyncTimer.Tick + Try + AddInfoEntry("Starting Sync.") + AddDivider() + + Dim oOutputDirectory As String = ConfigManager.Config.OutputDirectory + + If Directory.Exists(oOutputDirectory) = False Then + Throw New DirectoryNotFoundException($"Directory '{oOutputDirectory}' does not exist.") + End If + + Dim oTable As DataTable = Await Database.GetDatatableAsync(ConfigManager.Config.SQLQueryFetch) + Dim oExtDocIds = oTable.Rows.Cast(Of DataRow).Select(Function(r) r.Item(0).ToString()).ToList() + + AddInfoEntry("Found [{0}] files.", oExtDocIds.Count.ToString) + + AddInfoEntry("Logging in..") + Await Sync.GetAvailableSystems() + Await Sync.Login(ConfigManager.Config.SystemId) + + For Each oDocId As String In oExtDocIds + Try + Logger.Debug("Fetching document from API..") + Dim oDocument = Await Sync.GetDocumentContent(oDocId) + Logger.Debug("Document fetched!") + + 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) + + Using oStream As New MemoryStream(oDocument.Data) + Using oWriter As New FileStream(oFilePath, FileMode.Create) + oStream.CopyTo(oWriter) + End Using + End Using + + Dim oSQL = String.Format(ConfigManager.Config.SQLQueryExport, oDocument.ExtDocId, oDocument.Name) + 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) + End Try + Next + + Catch ex As Exception + Logger.Error(ex) + AddWarnEntry("Error while running Sync: " & ex.Message) + + End Try + + AddInfoEntry("Finished Sync.") + AddInfoEntry("Logging Out..") + AddDivider() + Await Sync.Logout() + 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 + End If + + Return pFilename & oExtension + + Catch ex As Exception + AddWarnEntry("File [{0}] does not have a valid mimetype [{1}]. Returning original filename.", pFilename, pMimetype) + + Return pFilename + End Try + End Function + + + Private Sub AddInfoEntry(pMessage As String, ParamArray pArgs As Object()) + Logger.Info(pMessage, pArgs) + ListBoxControl1.Items.Add(Now & " " & String.Format(pMessage, pArgs)) + End Sub + + Private Sub AddWarnEntry(pMessage As String, ParamArray pArgs As Object()) + Logger.Info(pMessage, pArgs) + ListBoxControl1.Items.Add(String.Format(pMessage, pArgs)) + End Sub + + Private Sub AddDivider() + ListBoxControl1.Items.Add("=====================================") + End Sub + + Private Function TestConfigurationIsComplete() As Boolean + Dim oComplete = True + + If ConfigManager.Config.Hostname = String.Empty Then + AddWarnEntry("Configuration for 'Hostname' is empty.") + oComplete = False + End If + + If ConfigManager.Config.Port = String.Empty Then + AddWarnEntry("Configuration for 'Port' is empty.") + oComplete = False + End If + + If ConfigManager.Config.Username = String.Empty Then + AddWarnEntry("Configuration for 'Username' is empty.") + oComplete = False + End If + + If ConfigManager.Config.Password = String.Empty Then + AddWarnEntry("Configuration for 'Password' is empty.") + oComplete = False + End If + + If ConfigManager.Config.ConnectionString = String.Empty Then + AddWarnEntry("Configuration for 'ConnectionString' is empty.") + oComplete = False + End If + + If ConfigManager.Config.SQLQueryFetch = String.Empty Then + AddWarnEntry("Configuration for 'SQLQueryFetch' is empty.") + oComplete = False + End If + + If ConfigManager.Config.SQLQueryExport = String.Empty Then + AddWarnEntry("Configuration for 'SQLQueryExport' is empty.") + oComplete = False + End If + + If ConfigManager.Config.OutputDirectory = String.Empty Then + AddWarnEntry("Configuration for 'OutputDirectory' is empty.") + oComplete = False + End If + + Return oComplete + End Function + + Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick + Try + Dim oPath = LogConfig.LogDirectory + Process.Start("explorer.exe", oPath) + Catch ex As Exception + Logger.Error(ex) + End Try + End Sub + + Private Sub btnSyncStart_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSyncStart.ItemClick + StartTimer() + End Sub + + Private Sub btnStopSync_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnStopSync.ItemClick + StopTimer() + End Sub + + +End Class diff --git a/sltSync/packages.config b/sltSync/packages.config new file mode 100644 index 0000000..a8846bc --- /dev/null +++ b/sltSync/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sltSync/sltException.vb b/sltSync/sltException.vb new file mode 100644 index 0000000..75b537b --- /dev/null +++ b/sltSync/sltException.vb @@ -0,0 +1,10 @@ +Public Class sltException + Inherits ApplicationException + + Public ReadOnly ErrorType As sltSync.ErrorType + + Public Sub New(pErrorType As sltSync.ErrorType, pMessage As String) + MyBase.New(pMessage) + ErrorType = pErrorType + End Sub +End Class \ No newline at end of file diff --git a/sltSync/sltSync.vb b/sltSync/sltSync.vb new file mode 100644 index 0000000..e883719 --- /dev/null +++ b/sltSync/sltSync.vb @@ -0,0 +1,184 @@ +Imports System.Net.Http +Imports DevExpress.XtraPrinting.Export.Pdf.PdfImageCache +Imports DigitalData.Modules.Base +Imports DigitalData.Modules.Base.ModuleExtensions +Imports DigitalData.Modules.Logging +Imports Newtonsoft.Json +Imports sltSync.Entities + +Partial Public Class sltSync + Inherits BaseClass + + Private ReadOnly Config As Config + + Public IsLoggedIn As Boolean = False + Public SessionId As String = Nothing + Public AvailableSystems As New List(Of sltAvailableSystem) + + Public Enum ErrorType + LoginError + LogoutError + AvailableSystemError + NotLoggedInError + GetDocumentError + End Enum + + Public Sub New(pLogConfig As LogConfig, pConfig As Config) + MyBase.New(pLogConfig) + + Config = pConfig + End Sub + + Public Async Function GetAvailableSystems() As Threading.Tasks.Task + Try + Logger.Debug("Fetching available systems..") + + Dim oUrl = "/slt/External/System/Authentication/Json/AvailableSystems" + Dim oJson As String = Await SendRequest(oUrl) + Dim oResponse = JsonConvert.DeserializeObject(Of sltAvailableSystemResponse)(oJson) + + TestRequestSuccessful(oUrl, oResponse, ErrorType.AvailableSystemError) + + AvailableSystems = oResponse.Value + + Logger.Debug("Fetched [{0}] available systems!", oResponse.Value.Count) + + Catch ex As Exception + Logger.Error(ex) + Throw New sltException(ErrorType.AvailableSystemError, ex.Message) + End Try + End Function + + Public Async Function Login(pSystemId As String) As Threading.Tasks.Task + Try + Logger.Debug("Logging in..") + + If AvailableSystems.Any(Function(s) s.SystemId = pSystemId) = False Then + Dim oMessage = String.Format("SystemId [{0}] does not match any System returned from API.", pSystemId) + Logger.Warn(oMessage) + Throw New sltException(ErrorType.LoginError, oMessage) + End If + + Dim oUrl = "/slt/External/System/Authentication/Json/Login" + Dim oParams = New Dictionary(Of String, String) From { + {"systemid", pSystemId}, + {"user", Config.Username}, + {"password", Config.Password} + } + + Logger.Debug("Username: [{0}]", Config.Username) + Logger.Debug("SystemId: [{0}]", pSystemId) + + Dim oJson As String = Await SendRequest(oUrl, oParams) + Dim oResponse = JsonConvert.DeserializeObject(Of sltLoginResponse)(oJson) + + TestRequestSuccessful(oUrl, oResponse, ErrorType.LoginError) + + SessionId = oResponse.Value + IsLoggedIn = True + + Logger.Debug("Login successful!") + + Catch ex As Exception + Logger.Error(ex) + Throw New sltException(ErrorType.LoginError, ex.Message) + End Try + End Function + + Public Async Function Logout() As Threading.Tasks.Task + If Not IsLoggedIn Then + Throw New sltException(ErrorType.NotLoggedInError, "No session found") + End If + + Logger.Debug("Logging out..") + + Try + Dim oUrl = "/slt/External/System/Authentication/Json/Logout" + Dim oParams = New Dictionary(Of String, String) From { + {"SessionId", SessionId} + } + Dim oJson As String = Await SendRequest(oUrl, oParams) + Dim oResponse = JsonConvert.DeserializeObject(Of sltLogoutResponse)(oJson) + + TestRequestSuccessful(oUrl, oResponse, ErrorType.LogoutError) + + SessionId = Nothing + IsLoggedIn = False + + Logger.Debug("Login successful!") + + Catch ex As Exception + Logger.Error(ex) + Throw New sltException(ErrorType.LogoutError, ex.Message) + End Try + End Function + + Public Async Function GetDocumentContent(pExternalDocumentId As String) As Threading.Tasks.Task(Of sltDocument) + If Not IsLoggedIn Then + Throw New sltException(ErrorType.NotLoggedInError, "No session found") + End If + + Try + Logger.Debug("Fetching document with ExtDocId [{0}]", pExternalDocumentId) + + Dim oUrl = "/slt/External/Services/Allgemein/ExtDocs/JSon/GetDocument" + Dim oParams As New Dictionary(Of String, String) From { + {"extdocid", pExternalDocumentId}, + {"sessionid", SessionId} + } + + Dim oJson = Await SendRequest(oUrl, oParams) + Dim oResponse = JsonConvert.DeserializeObject(Of sltDocumentResponse)(oJson) + + Logger.Debug("Document Fetched!") + + Return oResponse.Value + + Catch ex As Exception + Logger.Error(ex) + Throw New sltException(ErrorType.GetDocumentError, ex.Message) + End Try + End Function + + Private Async Function SendRequest(pUrl As String) As Threading.Tasks.Task(Of String) + Return Await SendRequest(pUrl, New Dictionary(Of String, String)) + End Function + + Private Async Function SendRequest(pUrl As String, pQueryParams As Dictionary(Of String, String)) As Threading.Tasks.Task(Of String) + Try + Dim oUrl = GetUrl(pUrl, pQueryParams) + Logger.Debug("Preparing request to: [{0}]", oUrl) + + Using oClient As New HttpClient() + oClient.DefaultRequestHeaders.Accept.Clear() + oClient.DefaultRequestHeaders.Accept.Add(New Headers.MediaTypeWithQualityHeaderValue("application/json")) + oClient.DefaultRequestHeaders.Add("User-Agent", "Digital Data sltSync") + + Logger.Debug("Sending request.") + Return Await oClient.GetStringAsync(oUrl) + End Using + Catch ex As Exception + Logger.Error(ex) + Return Nothing + End Try + End Function + + Private Function GetUrl(pPath As String, pQueryParams As Dictionary(Of String, String)) As String + Dim oUrl As String = $"http://{Config.Hostname}:{Config.Port}" + If Not pPath.StartsWith("/") Then pPath &= "/" + + Dim queryString = pQueryParams.ToURLQueryString() + + Return $"{oUrl}{pPath}?{queryString}" + End Function + + Private Sub TestRequestSuccessful(pUrl As String, pResponse As sltResponse, pErrorType As ErrorType) + If pResponse.State = False Then + Logger.Warn("Request to Url [{0}] returned error.", pUrl) + Logger.Error(pResponse.Message) + Throw New sltException(pErrorType, pResponse.Message) + End If + End Sub + + +End Class diff --git a/sltSync/sltSync.vbproj b/sltSync/sltSync.vbproj new file mode 100644 index 0000000..8d99519 --- /dev/null +++ b/sltSync/sltSync.vbproj @@ -0,0 +1,161 @@ + + + Debug + x86 + 8.0.30703 + 2.0 + {A439775B-FF9C-4C46-9395-79356A8FC601} + WinExe + sltSync + sltSync + v4.6.2 + 512 + On + Binary + Off + On + + + AnyCPU + true + full + false + bin\Debug\ + true + true + prompt + + + AnyCPU + pdbonly + true + bin\Release\ + false + true + prompt + + + WindowsForms + + + sltSync.My.MyApplication + + + + + + + + + + + + ..\..\DDModules\Base\bin\Debug\DigitalData.Modules.Base.dll + + + ..\..\DDModules\Config\bin\Debug\DigitalData.Modules.Config.dll + + + ..\..\DDModules\Database\bin\Debug\DigitalData.Modules.Database.dll + + + ..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll + + + ..\packages\MediaTypeMap.2.1.0.0\lib\net40\MimeTypeMap.dll + + + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\NLog.5.0.5\lib\net46\NLog.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Form + + + frmMain.vb + + + + True + Application.myapp + + + + + + + + + + + frmMain.vb + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.vb + + + + True + Settings.settings + True + + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + + + \ No newline at end of file