EDMIService: Automatic indexing, more consolidation of globix logic
This commit is contained in:
67
Modules.Patterns/Modules/FileInformation.vb
Normal file
67
Modules.Patterns/Modules/FileInformation.vb
Normal file
@@ -0,0 +1,67 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace Modules
|
||||
Public Class FileInformation
|
||||
Inherits BaseModule
|
||||
Implements IModule
|
||||
|
||||
Public Const FILE_VALUE_FILEINFO = "FILEINFO"
|
||||
Public Const FILE_VALUE_FILENAME = "FILENAME"
|
||||
Public Const FILE_VALUE_EXTENSION = "EXTENSION"
|
||||
Public Const FILE_VALUE_FILENAME_EXT = "FILENAME_EXT"
|
||||
Public Const FILE_VALUE_DATE_CREATED = "DATE_CREATED"
|
||||
Public Const FILE_VALUE_DATE_MODIFIED = "DATE_MODIFIED"
|
||||
|
||||
Public Property PatternIdentifier As String = "FILE" Implements IModule.PatternIdentifier
|
||||
Public Property IsComplex As Boolean = False Implements IModule.IsComplex
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function Replace(pInput As String, pReplaceMap As Dictionary(Of String, Object)) As String Implements IModule.Replace
|
||||
Dim oResult = pInput
|
||||
Dim oCounter = 0
|
||||
Dim oFileInfo As FileInfo = pReplaceMap.Item(FILE_VALUE_FILEINFO)
|
||||
|
||||
' Replace Filename without extension
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, FILE_VALUE_FILENAME)
|
||||
Dim oFilenameWithoutExtension = Path.GetFileNameWithoutExtension(oFileInfo.Name)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oFilenameWithoutExtension)
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace Filename with extension
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, FILE_VALUE_FILENAME_EXT)
|
||||
Dim oFilename As String = oFileInfo.Name
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oFilename)
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace Extension
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, FILE_VALUE_FILENAME_EXT)
|
||||
Dim oExtension As String = oFileInfo.Extension.Substring(1)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oExtension)
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace creation date
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, FILE_VALUE_DATE_CREATED)
|
||||
Dim oDateCreated = oFileInfo.CreationTime.ToString("yyyy-MM-dd")
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oDateCreated)
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace last modification date
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, FILE_VALUE_DATE_CREATED)
|
||||
Dim oDateModified = oFileInfo.LastWriteTime.ToString("yyyy-MM-dd")
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oDateModified)
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -12,6 +12,9 @@ Namespace Modules
|
||||
Public Const INT_VALUE_MACHINE = "MACHINE"
|
||||
Public Const INT_VALUE_DOMAIN = "DOMAIN"
|
||||
Public Const INT_VALUE_DATE = "DATE"
|
||||
Public Const INT_VALUE_DATE_YYYY = "DATE_YYYY"
|
||||
Public Const INT_VALUE_DATE_MM = "DATE_MM"
|
||||
Public Const INT_VALUE_DATE_DD = "DATE_DD"
|
||||
|
||||
Public Property PatternIdentifier As String = "INT" Implements IModule.PatternIdentifier
|
||||
Public Property IsComplex As Boolean = False Implements IModule.IsComplex
|
||||
@@ -23,30 +26,29 @@ Namespace Modules
|
||||
Public Function Replace(pInput As String, pReplaceMap As Dictionary(Of String, Object)) As String Implements IModule.Replace
|
||||
Dim oResult = pInput
|
||||
Dim oCounter = 0
|
||||
|
||||
' Replace Username(s)
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_USERNAME)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, pReplaceMap.Item(INT_VALUE_USERNAME))
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace Machinename(s)
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_MACHINE)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, pReplaceMap.Item(INT_VALUE_MACHINE))
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
|
||||
' Replace Domainname(s)
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DOMAIN)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, pReplaceMap.Item(INT_VALUE_DOMAIN))
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
Dim oNow As Date = Now
|
||||
|
||||
' Replace CurrentDate(s)
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, pReplaceMap.Item(INT_VALUE_DATE))
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oNow.ToString("yyyy-MM-dd"))
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace Year(s)
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE_YYYY)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oNow.ToString("yyyy"))
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace Month(s)
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE_MM)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oNow.ToString("MM"))
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace Day(s)
|
||||
While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE_DD)
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oNow.ToString("dd"))
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Constants.vb" />
|
||||
<Compile Include="Modules\FileInformation.vb" />
|
||||
<Compile Include="Modules\IDB.vb" />
|
||||
<Compile Include="Modules\Globix.vb" />
|
||||
<Compile Include="Modules\Windream.vb" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports System.IO
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports System.Windows.Forms
|
||||
Imports DigitalData.Controls.LookupGrid
|
||||
Imports DigitalData.Modules.Logging
|
||||
@@ -65,7 +66,8 @@ Public Class Patterns2
|
||||
New Modules.Internal(LogConfig),
|
||||
New Modules.Clipboard(LogConfig),
|
||||
New Modules.Controls(LogConfig),
|
||||
New Modules.User(LogConfig)
|
||||
New Modules.User(LogConfig),
|
||||
New Modules.FileInformation(LogConfig)
|
||||
})
|
||||
End Sub
|
||||
|
||||
@@ -75,12 +77,12 @@ Public Class Patterns2
|
||||
IDBActive = pIDBActive
|
||||
End Sub
|
||||
|
||||
Public Function ReplaceAllValues(pInput As String, pPanel As Panel, pUser As State.UserState) As String
|
||||
Public Function ReplaceAllValues(pInput As String, pPanel As Panel, pUser As State.UserState, pFIleinfo As FileInfo) As String
|
||||
Dim oResult = pInput
|
||||
|
||||
For Each oModule In Modules
|
||||
Try
|
||||
Dim oArgs = GetReplaceMapForModule(oModule, pPanel, pUser)
|
||||
Dim oArgs = GetReplaceMapForModule(oModule, pPanel:=pPanel, pUser:=pUser, pFileInfo:=pFIleinfo)
|
||||
oResult = oModule.Replace(oResult, oArgs)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Placeholders for String [{0}] could not be replaced completely in Module [{1}]. Skipping.", pInput, oModule.GetType.Name)
|
||||
@@ -101,6 +103,16 @@ Public Class Patterns2
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
Public Function ReplaceFileValues(pInput As String, pFileInfo As FileInfo) As String
|
||||
Dim oResult = pInput
|
||||
|
||||
Dim oModule = GetModule(Of Modules.User)()
|
||||
Dim oArgs = GetReplaceMapForModule(oModule, pFileInfo:=pFileInfo)
|
||||
oResult = DoReplaceForModule(oResult, oModule, oArgs)
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
Public Function ReplaceControlValues(pInput As String, pPanel As Panel) As String
|
||||
Dim oResult = pInput
|
||||
|
||||
@@ -135,16 +147,18 @@ Public Class Patterns2
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
Public Function ReplaceGlobixValues(pInput As String) As String
|
||||
Public Function ReplaceGlobixValues(pInput As String, pGlobixIndexes As Dictionary(Of String, List(Of String))) As String
|
||||
Dim oResult = pInput
|
||||
|
||||
Dim oGlobixModule = GetModule(Of Modules.Globix)()
|
||||
Dim oGlobixArgs = GetReplaceMapForModule(oGlobixModule)
|
||||
Dim oGlobixArgs = GetReplaceMapForModule(oGlobixModule, pGlobixIndexes:=pGlobixIndexes)
|
||||
oResult = DoReplaceForModule(oResult, oGlobixModule, oGlobixArgs)
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Private Function DoReplaceForModule(pInput As String, pModule As IModule, pArgs As Dictionary(Of String, Object)) As String
|
||||
Try
|
||||
pInput = pModule.Replace(pInput, pArgs)
|
||||
@@ -166,7 +180,8 @@ Public Class Patterns2
|
||||
Optional pPanel As Panel = Nothing,
|
||||
Optional pUser As State.UserState = Nothing,
|
||||
Optional pWMObject As WMObject = Nothing,
|
||||
Optional pGlobixIndexes As Dictionary(Of String, List(Of String)) = Nothing
|
||||
Optional pGlobixIndexes As Dictionary(Of String, List(Of String)) = Nothing,
|
||||
Optional pFileInfo As FileInfo = Nothing
|
||||
) As Dictionary(Of String, Object)
|
||||
Dim oArgs As New Dictionary(Of String, Object)
|
||||
|
||||
@@ -177,12 +192,9 @@ Public Class Patterns2
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
ElseIf TypeOf pModule Is Modules.Internal Then
|
||||
ElseIf TypeOf pModule Is Modules.FileInformation Then
|
||||
Try
|
||||
oArgs.Add(Patterns.Modules.Internal.INT_VALUE_USERNAME, System.Environment.UserName)
|
||||
oArgs.Add(Patterns.Modules.Internal.INT_VALUE_MACHINE, System.Environment.MachineName)
|
||||
oArgs.Add(Patterns.Modules.Internal.INT_VALUE_DOMAIN, System.Environment.UserDomainName)
|
||||
oArgs.Add(Patterns.Modules.Internal.INT_VALUE_DATE, Now.ToShortDateString)
|
||||
oArgs.Add(Patterns.Modules.FileInformation.FILE_VALUE_FILEINFO, pFileInfo)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Reference in New Issue
Block a user