6 Commits

Author SHA1 Message Date
Jonathan Jenne
2f4b8afd67 clean up config 2020-12-17 13:39:52 +01:00
Jonathan Jenne
4a081ed65e Config: Add config migration 2020-12-17 13:38:40 +01:00
Jonathan Jenne
f8ea2c755b DocumentPropertyMenu: Select file when opening from context menu 2020-12-17 13:38:14 +01:00
Jonathan Jenne
7e05938ba8 LookupGrid: Improve Buttons, Change icon to search, increase size 2020-12-17 13:37:25 +01:00
Jonathan Jenne
99e5675d51 Filesystem: Clean up 2020-12-17 13:36:40 +01:00
Jonathan Jenne
ebf53ea108 File: Add CopyDirectory method 2020-12-17 13:36:29 +01:00
18 changed files with 167 additions and 48 deletions

View File

@@ -62,8 +62,6 @@ Public Class LookupControl2
Friend WithEvents GridView1 As DevExpress.XtraGrid.Views.Grid.GridView Friend WithEvents GridView1 As DevExpress.XtraGrid.Views.Grid.GridView
Friend WithEvents GridView2 As DevExpress.XtraGrid.Views.Grid.GridView Friend WithEvents GridView2 As DevExpress.XtraGrid.Views.Grid.GridView
Friend WithEvents fProperties As RepositoryItemGridLookUpEdit
Friend WithEvents fPropertiesView As DevExpress.XtraGrid.Views.Grid.GridView
Private _ReadOnly As Boolean = False Private _ReadOnly As Boolean = False
Shared Sub New() Shared Sub New()
@@ -76,8 +74,9 @@ Public Class LookupControl2
Public Sub New(MultiSelect As Boolean) Public Sub New(MultiSelect As Boolean)
_LookupFormButton = New EditorButton() With { _LookupFormButton = New EditorButton() With {
.Kind = ButtonPredefines.Ellipsis, .Kind = ButtonPredefines.Search,
.Tag = TAG_BUTTON_LOOKUP_FORM .Tag = TAG_BUTTON_LOOKUP_FORM,
.Width = 20
} }
Properties.Buttons.Item(0).Tag = TAG_DROPDOWN Properties.Buttons.Item(0).Tag = TAG_DROPDOWN
@@ -199,31 +198,6 @@ Public Class LookupControl2
Return RepositoryItemLookupControl2.CustomEditName Return RepositoryItemLookupControl2.CustomEditName
End Get End Get
End Property End Property
Private Sub InitializeComponent()
Me.fProperties = New DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEdit()
Me.fPropertiesView = New DevExpress.XtraGrid.Views.Grid.GridView()
CType(Me.fProperties, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.fPropertiesView, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'fProperties
'
Me.fProperties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
Me.fProperties.Name = "fProperties"
Me.fProperties.PopupView = Me.fPropertiesView
'
'fPropertiesView
'
Me.fPropertiesView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus
Me.fPropertiesView.Name = "fPropertiesView"
Me.fPropertiesView.OptionsSelection.EnableAppearanceFocusedCell = False
Me.fPropertiesView.OptionsView.ShowGroupPanel = False
CType(Me.fProperties, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.fPropertiesView, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
End Class End Class
<UserRepositoryItem("RegisterLookupControl2")> <UserRepositoryItem("RegisterLookupControl2")>
@@ -244,7 +218,18 @@ Public Class RepositoryItemLookupControl2
Public Shared Sub RegisterLookupControl2() Public Shared Sub RegisterLookupControl2()
Dim img As Image = Nothing Dim img As Image = Nothing
EditorRegistrationInfo.Default.Editors.Add(New EditorClassInfo(CustomEditName, GetType(LookupControl2), GetType(RepositoryItemLookupControl2), GetType(GridLookUpEditBaseViewInfo), New ButtonEditPainter(), True, img, GetType(ButtonEditAccessible))) EditorRegistrationInfo.Default.Editors.Add(
New EditorClassInfo(
CustomEditName,
GetType(LookupControl2),
GetType(RepositoryItemLookupControl2),
GetType(GridLookUpEditBaseViewInfo),
New ButtonEditPainter(),
True,
img,
GetType(ButtonEditAccessible)
)
)
End Sub End Sub
Public Overrides Sub Assign(item As RepositoryItem) Public Overrides Sub Assign(item As RepositoryItem)

View File

@@ -99,8 +99,13 @@ Public Class DocumentPropertyMenu
Exit Sub Exit Sub
End If End If
Dim oDirectory = IO.Path.GetDirectoryName(_FilePath) Dim oArgs As String = $"/e, /select, ""{_FilePath}"""
Process.Start(oDirectory) Dim oInfo As New ProcessStartInfo() With {
.Arguments = oArgs,
.FileName = "explorer"
}
Process.Start(oInfo)
End Sub End Sub
Private Function TestPathExists(Title As String) As Boolean Private Function TestPathExists(Title As String) As Boolean

View File

@@ -76,6 +76,7 @@
<Compile Include="ConfigAttributes.vb" /> <Compile Include="ConfigAttributes.vb" />
<Compile Include="ConfigManager.vb" /> <Compile Include="ConfigManager.vb" />
<Compile Include="ConfigSample.vb" /> <Compile Include="ConfigSample.vb" />
<Compile Include="ConfigUtils.vb" />
<Compile Include="My Project\AssemblyInfo.vb" /> <Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb"> <Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>

View File

@@ -12,10 +12,11 @@
Public Class ConnectionStringTestAttribute Public Class ConnectionStringTestAttribute
Inherits Attribute Inherits Attribute
End Class End Class
Public Class ConnectionStringAppServer
Inherits Attribute ''' <summary>
End Class ''' The app server connection string. Will not be saved to userconfig.
Public Class AppServerConfig ''' </summary>
Public Class ConnectionStringAppServerAttribute
Inherits Attribute Inherits Attribute
End Class End Class
''' <summary> ''' <summary>

View File

@@ -20,7 +20,6 @@ Public Class ConfigManager(Of T)
Private ReadOnly _AppConfigDirectory As String Private ReadOnly _AppConfigDirectory As String
Private ReadOnly _AppConfigPath As String Private ReadOnly _AppConfigPath As String
Private ReadOnly _TestMode As Boolean = False Private ReadOnly _TestMode As Boolean = False
Private ReadOnly _Blueprint As T Private ReadOnly _Blueprint As T
@@ -29,7 +28,7 @@ Public Class ConfigManager(Of T)
Private ReadOnly _ExcludedAttributes = New List(Of Type) From { Private ReadOnly _ExcludedAttributes = New List(Of Type) From {
GetType(ConnectionStringAttribute), GetType(ConnectionStringAttribute),
GetType(ConnectionStringAppServer), GetType(ConnectionStringAppServerAttribute),
GetType(ConnectionStringTestAttribute), GetType(ConnectionStringTestAttribute),
GetType(GlobalSettingAttribute) GetType(GlobalSettingAttribute)
} }
@@ -66,7 +65,7 @@ Public Class ConfigManager(Of T)
End Property End Property
''' <summary> ''' <summary>
''' Path to the current computer config. Maybe the same as `UserConfigPath` ''' Path to the current computer config.
''' </summary> ''' </summary>
''' <returns></returns> ''' <returns></returns>
Public ReadOnly Property ComputerConfigPath As String Public ReadOnly Property ComputerConfigPath As String
@@ -74,6 +73,11 @@ Public Class ConfigManager(Of T)
Return _ComputerConfigPath Return _ComputerConfigPath
End Get End Get
End Property End Property
''' <summary>
''' Path to the current Application config.
''' </summary>
''' <returns></returns>
Public ReadOnly Property AppConfigPath As String Public ReadOnly Property AppConfigPath As String
Get Get
Return _AppConfigPath Return _AppConfigPath

View File

@@ -7,6 +7,7 @@ Public Class ConfigSample
<ConnectionStringTest> <ConnectionStringTest>
Public Property ConnectionStringTest As String Public Property ConnectionStringTest As String
<ConnectionStringAppServer> <ConnectionStringAppServer>
Public Property ConnectionStringAppServer As String Public Property ConnectionStringAppServer As String

View File

@@ -0,0 +1,92 @@
Imports DigitalData.Modules.Logging
Public Class ConfigUtils
Private _Logger As Logger
Private _File As Filesystem.File
Private Const MIGRATE_DIRECTORY As String = "Migrate"
Public Sub New(LogConfig As LogConfig)
_Logger = LogConfig.GetLogger()
_File = New Filesystem.File(LogConfig)
End Sub
Public Sub MigrateConfig(SourceDirectory As String, TargetDirectory As String, Optional FilePattern As String = "*.*")
If IO.Directory.Exists(TargetDirectory) Then
_Logger.Warn("Config Migration aborted because new config directory [{0}] already exists!", TargetDirectory)
Exit Sub
End If
' Create target directory
Try
IO.Directory.CreateDirectory(TargetDirectory)
Catch ex As Exception
_Logger.Warn("Config Migration aborted because new config directory [{0}] could not be created!", TargetDirectory)
_Logger.Error(ex)
Exit Sub
End Try
' Create Migration directory
Dim oMigrationDirectory = IO.Path.Combine(SourceDirectory, MIGRATE_DIRECTORY)
Try
IO.Directory.CreateDirectory(oMigrationDirectory)
Catch ex As Exception
_Logger.Warn("Config Migration aborted because migration directory [{0}] could not be created!", oMigrationDirectory)
_Logger.Error(ex)
Exit Sub
End Try
For Each oPath In IO.Directory.EnumerateFiles(SourceDirectory, FilePattern)
Dim oFileInfo = New IO.FileInfo(oPath)
Try
IO.File.Copy(oPath, IO.Path.Combine(TargetDirectory, oFileInfo.Name))
Catch ex As Exception
_Logger.Warn("Could not move old config file {0} to new config location {1}", oFileInfo.Name, TargetDirectory)
_Logger.Error(ex)
End Try
Next
For Each oPath In IO.Directory.EnumerateFiles(SourceDirectory, FilePattern)
Dim oFileInfo = New IO.FileInfo(oPath)
Try
IO.File.Move(oPath, IO.Path.Combine(oMigrationDirectory, oFileInfo.Name))
Catch ex As Exception
_Logger.Warn("Could not move old config file {0} to migration directory {1}", oFileInfo.Name, oMigrationDirectory)
_Logger.Error(ex)
End Try
Next
For Each oDirectoryPath In IO.Directory.EnumerateDirectories(SourceDirectory, "*", IO.SearchOption.TopDirectoryOnly)
Dim oDirInfo As New IO.DirectoryInfo(oDirectoryPath)
If oDirInfo.FullName = TargetDirectory Or oDirInfo.FullName = oMigrationDirectory Then
Continue For
End If
Dim oNewDirectoryPath = IO.Path.Combine(TargetDirectory, oDirInfo.Name)
Try
_File.CopyDirectory(oDirInfo.FullName, oNewDirectoryPath, True)
Catch ex As Exception
_Logger.Warn("Could not move directory [{0}] to new path [{1}]", oDirInfo.FullName, oNewDirectoryPath)
_Logger.Error(ex)
End Try
Next
For Each oDirectoryPath In IO.Directory.EnumerateDirectories(SourceDirectory, "*", IO.SearchOption.TopDirectoryOnly)
Dim oDirInfo As New IO.DirectoryInfo(oDirectoryPath)
If oDirInfo.FullName = TargetDirectory Or oDirInfo.FullName = oMigrationDirectory Then
Continue For
End If
Dim oNewDirectoryPath = IO.Path.Combine(oMigrationDirectory, oDirInfo.Name)
Try
_File.CopyDirectory(oDirInfo.FullName, oNewDirectoryPath, True)
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("Could not move directory [{0}] to migration directory [{1}]", oDirInfo.FullName, oNewDirectoryPath)
End Try
Next
End Sub
End Class

View File

@@ -206,6 +206,36 @@ Public Class File
IO.File.Move(FilePath, Path.Combine(Directory, NewFileName)) IO.File.Move(FilePath, Path.Combine(Directory, NewFileName))
End Sub End Sub
''' <summary>
''' Copied from https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories
''' </summary>
''' <param name="SourceDirName"></param>
''' <param name="DestDirName"></param>
''' <param name="CopySubDirs"></param>
Public Sub CopyDirectory(ByVal SourceDirName As String, ByVal DestDirName As String, ByVal CopySubDirs As Boolean)
Dim oDirectory As DirectoryInfo = New DirectoryInfo(SourceDirName)
If Not oDirectory.Exists Then
Throw New DirectoryNotFoundException("Source directory does not exist or could not be found: " & SourceDirName)
End If
Dim oDirectories As DirectoryInfo() = oDirectory.GetDirectories()
Directory.CreateDirectory(DestDirName)
Dim oFiles As FileInfo() = oDirectory.GetFiles()
For Each oFile As FileInfo In oFiles
Dim tempPath As String = Path.Combine(DestDirName, oFile.Name)
oFile.CopyTo(tempPath, False)
Next
If CopySubDirs Then
For Each oSubDirectory As DirectoryInfo In oDirectories
Dim oTempPath As String = Path.Combine(DestDirName, oSubDirectory.Name)
CopyDirectory(oSubDirectory.FullName, oTempPath, CopySubDirs)
Next
End If
End Sub
''' <summary> ''' <summary>
''' Tries to create a directory and returns its path. ''' Tries to create a directory and returns its path.
''' Returns a temp path if `DirectoryPath` can not be created or written to. ''' Returns a temp path if `DirectoryPath` can not be created or written to.

View File

@@ -75,16 +75,16 @@
<Import Include="System.Threading.Tasks" /> <Import Include="System.Threading.Tasks" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Compression.vb" /> <Compile Include="Encryption\Compression.vb" />
<Compile Include="DocumentObject.vb" /> <Compile Include="FileContainer\DocumentObject.vb" />
<Compile Include="EncryptionLegacy.vb" /> <Compile Include="Encryption\EncryptionLegacy.vb" />
<Compile Include="FileContainer.vb" /> <Compile Include="FileContainer\FileContainer.vb" />
<Compile Include="Encryption.vb" /> <Compile Include="Encryption\Encryption.vb" />
<Compile Include="File.vb" /> <Compile Include="File.vb" />
<Compile Include="FileContainerInner.vb" /> <Compile Include="FileContainer\FileContainerInner.vb" />
<Compile Include="FileWatcher.vb" /> <Compile Include="FileWatcher\FileWatcher.vb" />
<Compile Include="FileWatcherFilters.vb" /> <Compile Include="FileWatcher\FileWatcherFilters.vb" />
<Compile Include="FileWatcherProperties.vb" /> <Compile Include="FileWatcher\FileWatcherProperties.vb" />
<Compile Include="My Project\AssemblyInfo.vb" /> <Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb"> <Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>