jj: folder watcher

This commit is contained in:
Jonathan Jenne 2019-02-05 16:47:32 +01:00
parent 779d2fc3d7
commit a1c96731ef
10 changed files with 365 additions and 40 deletions

View File

@ -86,6 +86,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Modules.Logging\bin\Debug\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
@ -322,7 +323,9 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Resources\iconfinder_Gowalla_324477.png" />
</ItemGroup>
<ItemGroup>

View File

@ -19,11 +19,10 @@ Partial Class frmMain
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmMain))
Dim PushTransition1 As DevExpress.Utils.Animation.PushTransition = New DevExpress.Utils.Animation.PushTransition()
Me.RibbonControl = New DevExpress.XtraBars.Ribbon.RibbonControl()
Me.MainMenu = New DevExpress.XtraBars.Ribbon.ApplicationMenu(Me.components)
Me.MainMenu = New DevExpress.XtraBars.Ribbon.ApplicationMenu()
Me.BarButtonExit = New DevExpress.XtraBars.BarButtonItem()
Me.BarButtonUserSettings = New DevExpress.XtraBars.BarButtonItem()
Me.BarButtonConnectionSettings = New DevExpress.XtraBars.BarButtonItem()
@ -38,6 +37,8 @@ Partial Class frmMain
Me.BarButtonDeleteControl = New DevExpress.XtraBars.BarButtonItem()
Me.LabelCurrentLanguage = New DevExpress.XtraBars.BarStaticItem()
Me.BarButtonItem2 = New DevExpress.XtraBars.BarButtonItem()
Me.BarWorkspaceMenuItem1 = New DevExpress.XtraBars.BarWorkspaceMenuItem()
Me.WorkspaceManager1 = New DevExpress.Utils.WorkspaceManager()
Me.RibbonPageCategoryEntityDesigner = New DevExpress.XtraBars.Ribbon.RibbonPageCategory()
Me.RibbonPageControlActions = New DevExpress.XtraBars.Ribbon.RibbonPage()
Me.RibbonPageGroup5 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup()
@ -49,9 +50,9 @@ Partial Class frmMain
Me.RibbonPageWorkflow = New DevExpress.XtraBars.Ribbon.RibbonPage()
Me.RibbonPageGroup4 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup()
Me.RibbonStatusBar = New DevExpress.XtraBars.Ribbon.RibbonStatusBar()
Me.DocumentManager = New DevExpress.XtraBars.Docking2010.DocumentManager(Me.components)
Me.TabbedView1 = New DevExpress.XtraBars.Docking2010.Views.Tabbed.TabbedView(Me.components)
Me.DockManager = New DevExpress.XtraBars.Docking.DockManager(Me.components)
Me.DocumentManager = New DevExpress.XtraBars.Docking2010.DocumentManager()
Me.TabbedView1 = New DevExpress.XtraBars.Docking2010.Views.Tabbed.TabbedView()
Me.DockManager = New DevExpress.XtraBars.Docking.DockManager()
Me.panelContainer1 = New DevExpress.XtraBars.Docking.DockPanel()
Me.DockPanelGlobix = New DevExpress.XtraBars.Docking.DockPanel()
Me.DockPanel1_Container = New DevExpress.XtraBars.Docking.ControlContainer()
@ -59,8 +60,6 @@ Partial Class frmMain
Me.DockPanelProcessManager = New DevExpress.XtraBars.Docking.DockPanel()
Me.DockPanel2_Container = New DevExpress.XtraBars.Docking.ControlContainer()
Me.ProcessManagerWidget = New EDMI_ClientSuite.ProcessManagerWidget()
Me.BarWorkspaceMenuItem1 = New DevExpress.XtraBars.BarWorkspaceMenuItem()
Me.WorkspaceManager1 = New DevExpress.Utils.WorkspaceManager()
CType(Me.RibbonControl, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.MainMenu, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DocumentManager, System.ComponentModel.ISupportInitialize).BeginInit()
@ -189,10 +188,22 @@ Partial Class frmMain
Me.BarButtonItem2.Id = 16
Me.BarButtonItem2.Name = "BarButtonItem2"
'
'BarWorkspaceMenuItem1
'
Me.BarWorkspaceMenuItem1.Caption = "BarWorkspaceMenuItem1"
Me.BarWorkspaceMenuItem1.Id = 17
Me.BarWorkspaceMenuItem1.Name = "BarWorkspaceMenuItem1"
Me.BarWorkspaceMenuItem1.WorkspaceManager = Me.WorkspaceManager1
'
'WorkspaceManager1
'
Me.WorkspaceManager1.TargetControl = Me
Me.WorkspaceManager1.TransitionType = PushTransition1
'
'RibbonPageCategoryEntityDesigner
'
Me.RibbonPageCategoryEntityDesigner.AutoStretchPageHeaders = True
Me.RibbonPageCategoryEntityDesigner.Color = System.Drawing.Color.Red
Me.RibbonPageCategoryEntityDesigner.Color = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer))
Me.RibbonPageCategoryEntityDesigner.Name = "RibbonPageCategoryEntityDesigner"
Me.RibbonPageCategoryEntityDesigner.Pages.AddRange(New DevExpress.XtraBars.Ribbon.RibbonPage() {Me.RibbonPageControlActions})
Me.RibbonPageCategoryEntityDesigner.Text = "Entitäten Designer"
@ -348,27 +359,15 @@ Partial Class frmMain
Me.DockPanel2_Container.Size = New System.Drawing.Size(337, 163)
Me.DockPanel2_Container.TabIndex = 0
'
'ProcessManagerOverview
'ProcessManagerWidget
'
Me.ProcessManagerWidget.DataSource = Nothing
Me.ProcessManagerWidget.Dock = System.Windows.Forms.DockStyle.Fill
Me.ProcessManagerWidget.Location = New System.Drawing.Point(0, 0)
Me.ProcessManagerWidget.Name = "ProcessManagerOverview"
Me.ProcessManagerWidget.Name = "ProcessManagerWidget"
Me.ProcessManagerWidget.Size = New System.Drawing.Size(337, 163)
Me.ProcessManagerWidget.TabIndex = 0
'
'BarWorkspaceMenuItem1
'
Me.BarWorkspaceMenuItem1.Caption = "BarWorkspaceMenuItem1"
Me.BarWorkspaceMenuItem1.Id = 17
Me.BarWorkspaceMenuItem1.Name = "BarWorkspaceMenuItem1"
Me.BarWorkspaceMenuItem1.WorkspaceManager = Me.WorkspaceManager1
'
'WorkspaceManager1
'
Me.WorkspaceManager1.TargetControl = Me
Me.WorkspaceManager1.TransitionType = PushTransition1
'
'frmMain
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)

110
Filesystem/FileWatcher.vb Normal file
View File

@ -0,0 +1,110 @@
Imports System.IO
Imports DigitalData.Modules.Logging
Public Class FileWatcher
Private ReadOnly _Logger As Logger
Private ReadOnly _Watchers As List(Of FileSystemWatcher)
Private ReadOnly _Files As Dictionary(Of String, FileProperties)
Private _Path As String
Public OfficeFilters As New List(Of String) From {"docx", "xlsx", "pptx"}
Public Sub New(LogConfig As LogConfig, Path As String)
_Logger = LogConfig.GetLogger()
_Files = New Dictionary(Of String, FileProperties)
_Watchers = New List(Of FileSystemWatcher)
_Path = Path
For Each oFilePath As String In Directory.EnumerateFiles(_Path)
Try
If IO.File.Exists(oFilePath) Then
_Files.Add(oFilePath, New FileProperties With {
.CreatedAt = DateTime.Now,
.ChangedAt = Nothing
})
End If
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("File {0} cannot be watched!")
End Try
Next
End Sub
Public Sub Add(Filter As String, Optional SpecialTreatmentFilters As List(Of String) = Nothing)
_Watchers.Add(CreateWatcher(Filter))
End Sub
Public Sub Add(Filters As List(Of String), Optional SpecialTreatmentFilters As List(Of String) = Nothing)
For Each oFilter In Filters
_Watchers.Add(CreateWatcher(oFilter))
Next
End Sub
Private Function CreateWatcher(Filter As String)
Dim oWatcher = New FileSystemWatcher() With {
.Path = _Path,
.Filter = Filter,
.NotifyFilter = NotifyFilters.CreationTime _
Or NotifyFilters.LastAccess _
Or NotifyFilters.LastWrite _
Or NotifyFilters.Size _
Or NotifyFilters.FileName _
Or NotifyFilters.Attributes
}
AddHandler oWatcher.Created, AddressOf HandleFileCreated
AddHandler oWatcher.Changed, AddressOf HandleFileChanged
AddHandler oWatcher.Deleted, AddressOf HandleFileDeleted
AddHandler oWatcher.Renamed, AddressOf HandleFileRenamed
Return oWatcher
End Function
Private Sub HandleFileCreated(sender As Object, e As FileSystemEventArgs)
_Files.Add(e.FullPath, New FileProperties())
_Logger.Info("[Created] " & e.FullPath)
End Sub
Private Sub HandleFileChanged(sender As Object, e As FileSystemEventArgs)
_Files.Item(e.FullPath).ChangedAt = DateTime.Now
_Logger.Info("[Changed] " & e.FullPath)
End Sub
Private Sub HandleFileDeleted(sender As Object, e As FileSystemEventArgs)
_Files.Remove(e.FullPath)
_Logger.Info("[Removed] " & e.FullPath)
End Sub
Private Sub HandleFileRenamed(sender As Object, e As RenamedEventArgs)
Dim oProperties = _Files.Item(e.OldFullPath)
_Files.Remove(e.OldFullPath)
_Files.Add(e.FullPath, oProperties)
' Soll eine umbenannte datei als NEU gelten?
_Logger.Info("[Renamed] {0} --> {1}", e.OldFullPath, e.FullPath)
End Sub
Public Sub Start()
For Each oWatcher In _Watchers
oWatcher.EnableRaisingEvents = True
Next
End Sub
Public Sub [Stop]()
For Each oWatcher In _Watchers
If Not IsNothing(oWatcher) Then
oWatcher.EnableRaisingEvents = False
oWatcher.Dispose()
End If
Next
End Sub
Public Class FileProperties
Public CreatedAt As DateTime
Public ChangedAt As DateTime
Public Sub New()
CreatedAt = DateTime.Now
ChangedAt = Nothing
End Sub
End Class
End Class

View File

@ -80,6 +80,7 @@
<Compile Include="Encryption.vb" />
<Compile Include="File.vb" />
<Compile Include="FileContainerInner.vb" />
<Compile Include="FileWatcher.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>

49
TestGUI/FolderWatcher.Designer.vb generated Normal file
View File

@ -0,0 +1,49 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class FolderWatcher
Inherits System.Windows.Forms.Form
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Wird vom Windows Form-Designer benötigt.
Private components As System.ComponentModel.IContainer
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.FormattingEnabled = True
Me.ListBox1.Location = New System.Drawing.Point(12, 12)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(388, 420)
Me.ListBox1.TabIndex = 0
'
'FolderWatcher
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(413, 450)
Me.Controls.Add(Me.ListBox1)
Me.Name = "FolderWatcher"
Me.Text = "FolderWatcher"
Me.ResumeLayout(False)
End Sub
Friend WithEvents ListBox1 As ListBox
End Class

120
TestGUI/FolderWatcher.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

31
TestGUI/FolderWatcher.vb Normal file
View File

@ -0,0 +1,31 @@
Imports System.ComponentModel
Imports System.IO
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules.Logging
Public Class FolderWatcher
Private _LogConfig As LogConfig
Private _Watcher As FileWatcher
Public Sub FileCreated(_sender As Object, _e As FileSystemEventArgs)
ListBox1.Items.Add($"File created: {_e.FullPath}")
End Sub
Public Sub FileChanged(_sender As Object, _e As FileSystemEventArgs)
ListBox1.Items.Add($"File changed: {_e.FullPath}")
End Sub
Private Sub FolderWatcher_Load(sender As Object, e As EventArgs) Handles Me.Load
_LogConfig = New LogConfig(LogConfig.PathType.CurrentDirectory, Nothing, "MAIN")
_Watcher = New FileWatcher(_LogConfig, "E:\Watcher")
_Watcher.Add("*.*")
_Watcher.Start()
End Sub
Private Sub FolderWatcher_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
_Watcher.Stop()
End Sub
End Class

View File

@ -1,10 +1,10 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
' Dieser Code wurde von einem Tool generiert.
' Laufzeitversion:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
' der Code erneut generiert wird.
' </auto-generated>
'------------------------------------------------------------------------------
@ -13,15 +13,15 @@ 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.
'HINWEIS: Diese Datei wird automatisch generiert und darf nicht direkt bearbeitet werden. Wenn Sie Änderungen vornehmen möchten
' oder in dieser Datei Buildfehler auftreten, wechseln Sie zum Projekt-Designer.
' (Wechseln Sie dazu zu den Projekteigenschaften, oder doppelklicken Sie auf den Knoten "Mein Projekt" im
' Projektmappen-Explorer). Nehmen Sie auf der Registerkarte "Anwendung" entsprechende Änderungen vor.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = false
@ -29,10 +29,10 @@ Namespace My
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.TestGUI.Form1
Me.MainForm = Global.TestGUI.FolderWatcher
End Sub
End Class
End Namespace

View File

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>true</MySubMain>
<MainForm>Form1</MainForm>
<MainForm>FolderWatcher</MainForm>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<ApplicationType>0</ApplicationType>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>
</MyApplicationData>

View File

@ -93,6 +93,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationEvents.vb" />
<Compile Include="FolderWatcher.Designer.vb">
<DependentUpon>FolderWatcher.vb</DependentUpon>
</Compile>
<Compile Include="FolderWatcher.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.vb">
<SubType>Form</SubType>
</Compile>
@ -117,6 +123,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FolderWatcher.resx">
<DependentUpon>FolderWatcher.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.vb</DependentUpon>
</EmbeddedResource>
@ -145,6 +154,10 @@
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Filesystem\Filesystem.vbproj">
<Project>{991d0231-4623-496d-8bd0-9ca906029cbc}</Project>
<Name>Filesystem</Name>
</ProjectReference>
<ProjectReference Include="..\LookupGrid\LookupControl.vbproj">
<Project>{3dcd6d1a-c830-4241-b7e4-27430e7ea483}</Project>
<Name>LookupControl</Name>