diff --git a/GUIs.ZooFlow/Globix/ClassValidator.vb b/GUIs.ZooFlow/Globix/ClassValidator.vb index f4eccc27..5b8248d9 100644 --- a/GUIs.ZooFlow/Globix/ClassValidator.vb +++ b/GUIs.ZooFlow/Globix/ClassValidator.vb @@ -2,6 +2,7 @@ Imports DigitalData.GUIs.ZooFlow.Base Imports DigitalData.GUIs.ZooFlow.frmGlobix_Index Imports DigitalData.Modules.EDMI.API +Imports DigitalData.Modules.EDMI.API.EDMIServiceReference Imports DigitalData.Modules.Logging Public Class ClassValidator @@ -14,30 +15,18 @@ Public Class ClassValidator Client = pClient End Sub - Private Function TestIsIndexOptional(pDocType As DocType, pIndexName As String) As Boolean - Dim oIsOptional As Boolean = My.Helpers.GetValueFromDatatable( - My.Application.Globix.CURR_DT_MAN_INDEXE, - $"DOK_ID = {pDocType.Guid} AND INDEXNAME = '{pIndexName}'", "OPTIONAL", "") - - Return oIsOptional - End Function - - Private Sub ShowValidationMessage() - MsgBox(ClassStrings.TEXT_MISSING_INPUT, MsgBoxStyle.Exclamation, ClassStrings.TITLE_MISSING_INPUT) - End Sub - - Function ValidateControls(pControls As ControlCollection, pDocType As DocType) As Boolean + Function ValidateControls(pPanel As Panel, pDocType As DocType) As Boolean Try Logger.Debug("Starting [ValidateControls]") Dim result As Boolean = True - For Each oControl As Control In pControls + For Each oControl As Control In pPanel.Controls ' ========================= TEXT BOX ========================= If oControl.Name.StartsWith("txt") Then Dim oTextBox As DevExpress.XtraEditors.TextEdit = oControl If oTextBox.Text = "" Then - Dim oIndexName = Replace(oTextBox.Name, "txt", "") + Dim oIndexName = GetIndexName(oTextBox, "txt") Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) If oOptional = False Then @@ -54,7 +43,7 @@ Public Class ClassValidator Dim oValues As List(Of String) = oLookup.Properties.SelectedValues If oValues.Count = 0 Then - Dim oIndexName = Replace(oLookup.Name, "cmbMulti", "") + Dim oIndexName = GetIndexName(oLookup, "cmbMulti") Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) If oOptional = False Then @@ -70,7 +59,7 @@ Public Class ClassValidator Dim cmbSingle As TextBox = oControl If cmbSingle.Text = "" Then - Dim oIndexName = Replace(cmbSingle.Name, "cmbSingle", "") + Dim oIndexName = GetIndexName(cmbSingle, "cmbSingle") Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) If oOptional = False Then @@ -84,7 +73,7 @@ Public Class ClassValidator If oControl.Name.StartsWith("cmb") Then Dim cmb As ComboBox = oControl If cmb.Text = "" Then - Dim oIndexName = Replace(cmb.Name, "cmb", "") + Dim oIndexName = GetIndexName(cmb, "cmb") Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) If oOptional = False Then @@ -98,7 +87,7 @@ Public Class ClassValidator ' ========================= DATE PICKER ========================= If oControl.Name.StartsWith("dtp") Then Dim dtp As DevExpress.XtraEditors.DateEdit = oControl - Dim oIndexName As String = Replace(dtp.Name, "dtp", "") + Dim oIndexName As String = GetIndexName(dtp, "dtp") If dtp.Text = String.Empty Then Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) @@ -134,4 +123,124 @@ Public Class ClassValidator Return False End Try End Function + + Function GetControlValues(pPanel As Panel) + Dim oAttributeValues As New List(Of UserAttributeValue) + + For Each oControl As Control In pPanel.Controls + + ' ========================= TEXTBOX ========================= + If oControl.Name.StartsWith("txt") Then + Dim oTextBox As DevExpress.XtraEditors.TextEdit = oControl + Dim oIndexName = GetIndexName(oTextBox, "txt") + + ' TODO: What to do when value is emmpty? send an empty value or skip the control? + 'If oTextBox.Text = "" Then + 'End If + + oAttributeValues.Add(New UserAttributeValue With { + .AttributeName = oIndexName, + .AttributeValues = WrapIndexValue(oTextBox.Text), + .ControlName = oTextBox.Name + }) + End If + + ' ========================= LOOKUP ========================= + If oControl.Name.StartsWith("cmbMulti") Then + Dim oLookup = DirectCast(oControl, LookupControl3) + Dim oValues As List(Of String) = oLookup.Properties.SelectedValues + Dim oIndexName = GetIndexName(oLookup, "cmbMulti") + + If oValues.Count = 0 Then + End If + + oAttributeValues.Add(New UserAttributeValue With { + .AttributeName = oIndexName, + .AttributeValues = WrapIndexValue(oValues), + .ControlName = oLookup.Name + }) + End If + + ' ========================= COMBO BOX ========================= + If oControl.Name.StartsWith("cmbSingle") Then + Dim cmbSingle As TextBox = oControl + Dim oIndexName = GetIndexName(cmbSingle, "cmbSingle") + + If cmbSingle.Text = "" Then + End If + + oAttributeValues.Add(New UserAttributeValue With { + .AttributeName = oIndexName, + .AttributeValues = WrapIndexValue(cmbSingle.Text), + .ControlName = cmbSingle.Name + }) + End If + + If oControl.Name.StartsWith("cmb") Then + Dim cmb As ComboBox = oControl + Dim oIndexName = GetIndexName(cmb, "cmb") + + If cmb.Text = "" Then + End If + + oAttributeValues.Add(New UserAttributeValue With { + .AttributeName = oIndexName, + .AttributeValues = WrapIndexValue(cmb.Text), + .ControlName = cmb.Name + }) + End If + + ' ========================= DATE PICKER ========================= + If oControl.Name.StartsWith("dtp") Then + Dim dtp As DevExpress.XtraEditors.DateEdit = oControl + Dim oIndexName As String = GetIndexName(dtp, "dtp") + + oAttributeValues.Add(New UserAttributeValue With { + .AttributeName = oIndexName, + .AttributeValues = WrapIndexValue(dtp.EditValue.ToString), + .ControlName = dtp.Name + }) + End If + + ' ========================= CHECK BOX ========================= + If oControl.Name.StartsWith("chk") Then + Dim chk As CheckBox = oControl + Dim oIndexName As String = GetIndexName(chk, "chk") + + + oAttributeValues.Add(New UserAttributeValue With { + .AttributeName = oIndexName, + .AttributeValues = WrapIndexValue(chk.Checked.ToString), + .ControlName = chk.Name + }) + End If + Next + + Return oAttributeValues + End Function + + Private Function GetIndexName(pControl As Control, pPrefix As String) As String + Dim oIndexName = Replace(pControl.Name, pPrefix, "") + Return oIndexName + End Function + + Private Function WrapIndexValue(pValue As String) As String() + Return New List(Of String) From {pValue}.ToArray + End Function + + Private Function WrapIndexValue(pValues As List(Of String)) As String() + Return pValues.ToArray + End Function + + Private Function TestIsIndexOptional(pDocType As DocType, pIndexName As String) As Boolean + Dim oIsOptional As Boolean = My.Helpers.GetValueFromDatatable( + My.Application.Globix.CURR_DT_MAN_INDEXE, + $"DOK_ID = {pDocType.Guid} AND INDEXNAME = '{pIndexName}'", "OPTIONAL", "") + + Return oIsOptional + End Function + + Private Sub ShowValidationMessage() + MsgBox(ClassStrings.TEXT_MISSING_INPUT, MsgBoxStyle.Exclamation, ClassStrings.TITLE_MISSING_INPUT) + End Sub End Class diff --git a/GUIs.ZooFlow/Globix/frmGlobix_Index.vb b/GUIs.ZooFlow/Globix/frmGlobix_Index.vb index 411f61c0..0352f2d2 100644 --- a/GUIs.ZooFlow/Globix/frmGlobix_Index.vb +++ b/GUIs.ZooFlow/Globix/frmGlobix_Index.vb @@ -305,9 +305,9 @@ Public Class frmGlobix_Index End Sub Sub Refresh_Dokart() Try - Dim oSql = String.Format("select * from VWGI_DOCTYPE where UPPER(USERNAME) = UPPER('{0}') ORDER BY SEQUENCE", My.Application.User.UserName) - Dim oFilter = $"USERNAME = '{My.Application.User.UserName}'" - DT_VWGI_DOCTYPE = _DataASorDB.GetDatatable("DD_ECM", oSql, "VWGI_DOCTYPE", oFilter, "SEQUENCE") + Dim oSql = String.Format("select * from VWGI_DOCTYPE_IDB where UPPER(USERNAME) = UPPER('{0}') ORDER BY SEQUENCE", My.Application.User.UserName) + 'Dim oFilter = $"USERNAME = '{My.Application.User.UserName}'" + DT_VWGI_DOCTYPE = _DataASorDB.GetDatatable("DD_ECM", oSql, "VWGI_DOCTYPE_IDB", "", "SEQUENCE") For Each oRow As DataRow In DT_VWGI_DOCTYPE.Rows cmbDocType.Properties.Items.Add(New DocType With { @@ -2415,7 +2415,11 @@ Public Class frmGlobix_Index Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim oDokart As DocType = cmbDocType.SelectedItem - Await GlobixFlowNew(oDokart) + Dim oResult = Await GlobixFlowNew(oDokart) + If oResult = True Then + CancelAttempts = MaxCancelAttempts + Close() + End If End Sub Private Async Function GlobixFlowNew(pDocType As DocType) As Threading.Tasks.Task(Of Boolean) @@ -2425,26 +2429,29 @@ Public Class frmGlobix_Index Cursor = Cursors.WaitCursor Dim oValidator As New ClassValidator(My.LogConfig, My.Application.Service.Client) - If oValidator.ValidateControls(pnlIndex.Controls, pDocType) = False Then + If oValidator.ValidateControls(pnlIndex, pDocType) = False Then Return False End If - 'TODO: Globix File Import + Dim oValues = oValidator.GetControlValues(pnlIndex) - Dim oFileName As String - Dim oObjectStore As String - Dim oObjectKind As String - Dim oBusinessENtity As String - Dim oProfileId As Integer - Dim oAttributes As List(Of UserAttributeValue) + Dim oFileName As String = My.Application.Globix.CURRENT_WORKFILE + Dim oObjectStore As String = "WORK" + Dim oObjectKind As String = "DOC" + Dim oBusinessEntity As String = "DEFAULT" + Dim oProfileId As Integer = My.Application.Globix.CURRENT_DOCTYPE_ID + Dim oAttributes As List(Of UserAttributeValue) = oValues Dim oOptions As New Modules.EDMI.API.Options.ImportFileOptions - Await My.Application.Service.Client.ImportFileAsync(oFileName, oProfileId, oAttributes, oObjectStore, oObjectKind, oBusinessENtity, oOptions) + Await My.Application.Service.Client.ImportFileAsync(oFileName, oProfileId, oAttributes, oObjectStore, oObjectKind, oBusinessEntity, oOptions) + + MsgBox("Die Datei wurde erfolgreich verarbeitet!", MsgBoxStyle.Information, Text) Return True Catch ex As Exception _Logger.Error(ex) MsgBox("Indexierung fehlgeschlagen!", MsgBoxStyle.Critical, Text) + Return False Finally Cursor = Cursors.Default diff --git a/Modules.EDMIAPI/Connected Services/EDMIServiceReference/Reference.vb b/Modules.EDMIAPI/Connected Services/EDMIServiceReference/Reference.vb index f7595dbe..8ec03ba6 100644 --- a/Modules.EDMIAPI/Connected Services/EDMIServiceReference/Reference.vb +++ b/Modules.EDMIAPI/Connected Services/EDMIServiceReference/Reference.vb @@ -933,7 +933,7 @@ Namespace EDMIServiceReference End Property Public Event PropertyChanged As System.ComponentModel.PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged - + Protected Sub RaisePropertyChanged(ByVal propertyName As String) Dim propertyChanged As System.ComponentModel.PropertyChangedEventHandler = Me.PropertyChangedEvent If (Not (propertyChanged) Is Nothing) Then diff --git a/Modules.Patterns/Patterns2.vb b/Modules.Patterns/Patterns2.vb index 47784676..cc9b07d9 100644 --- a/Modules.Patterns/Patterns2.vb +++ b/Modules.Patterns/Patterns2.vb @@ -108,7 +108,7 @@ Public Class Patterns2 End Try End Function - Public Function ReplaceGlobixValues(pInput As String, pAutomaticIndexes As Dictionary(Of String, List(Of String)), pManualIndexes As Dictionary(Of String, List(Of String))) As String + Public Function ReplaceGlobixValues(pInput As String, pManualIndexes As Dictionary(Of String, List(Of String)), pAutomaticIndexes As Dictionary(Of String, List(Of String))) As String Logger.Debug("Replacing Globix Values") Dim oResult = pInput diff --git a/Service.EDMIService/BaseClass.vb b/Service.EDMIService/BaseClass.vb index 13bd6f41..6823af2d 100644 --- a/Service.EDMIService/BaseClass.vb +++ b/Service.EDMIService/BaseClass.vb @@ -1,4 +1,5 @@ Imports DigitalData.Modules.Logging +Imports DigitalData.Services.EDMIService.IDB Public Class BaseClass Friend LogConfig As LogConfig diff --git a/Service.EDMIService/IDB/Helpers.vb b/Service.EDMIService/IDB/Helpers.vb index 5186b2a9..af19315a 100644 --- a/Service.EDMIService/IDB/Helpers.vb +++ b/Service.EDMIService/IDB/Helpers.vb @@ -3,18 +3,45 @@ Imports DigitalData.Modules.Language Imports DigitalData.Modules.Logging Imports DigitalData.Modules.EDMI.API.Client Imports System.Data.SqlClient +Imports System.IO +Imports DigitalData.Modules.ZooFlow.State +Imports DigitalData.Modules.Patterns +Imports DigitalData.Services.EDMIService.Methods Namespace IDB Public Class Helpers Inherits BaseClass - Private Database As MSSQLServer + Private ReadOnly Patterns As Patterns2 + Private ReadOnly Database As MSSQLServer Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer) MyBase.New(pLogConfig) + Patterns = New Patterns2(pLogConfig) Database = pMSSQLServer End Sub + Public Function GetPlaceholderValue(pValue As String, + pFileInfo As FileInfo, + pUserState As UserState, + pUserAttributes As Dictionary(Of String, List(Of String)), + pAutoAttributes As Dictionary(Of String, List(Of String))) As String + Dim oResult As String = pValue + + oResult = Patterns.ReplaceInternalValues(oResult) + oResult = Patterns.ReplaceFileValues(oResult, pFileInfo) + oResult = Patterns.ReplaceUserValues(oResult, pUserState) + oResult = Patterns.ReplaceGlobixValues(oResult, pUserAttributes, pAutoAttributes) + + Return oResult + End Function + + Public Function UserAttributesToDictionary(pUserAttributes As List(Of UserAttributeValue)) As Dictionary(Of String, List(Of String)) + Return pUserAttributes.ToDictionary( + Function(attr) attr.AttributeName, + Function(attr) attr.AttributeValues) + End Function + Public Function TestObjectIdExists(pObjectId As Long, Optional ByRef IsDeleted As Boolean = False, Optional ByRef IsActive As Boolean = False) As Boolean Try Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}" diff --git a/Service.EDMIService/Methods/GlobalIndexer/ImportFile/ImportFileMethod.vb b/Service.EDMIService/Methods/GlobalIndexer/ImportFile/ImportFileMethod.vb index 22603ddb..423c5dce 100644 --- a/Service.EDMIService/Methods/GlobalIndexer/ImportFile/ImportFileMethod.vb +++ b/Service.EDMIService/Methods/GlobalIndexer/ImportFile/ImportFileMethod.vb @@ -3,6 +3,8 @@ Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Patterns Imports DigitalData.Modules.Language Imports DigitalData.Services.EDMIService.Methods.GetDatatableFromCache +Imports System.IO +Imports DigitalData.Modules.ZooFlow.State Namespace Methods.GlobalIndexer.ImportFile Public Class ImportFileMethod @@ -12,6 +14,8 @@ Namespace Methods.GlobalIndexer.ImportFile Private ReadOnly GetDatatable As GetDatatableFromCacheMethod Private ReadOnly Connection As SqlClient.SqlConnection Private ReadOnly Transaction As SqlClient.SqlTransaction + + Private User As UserState Private Profile As DataRow Private Const VIEW_PROFILE = "VWGI_DOCTYPE_IDB" @@ -38,6 +42,8 @@ Namespace Methods.GlobalIndexer.ImportFile ''' Public Function Run(pData As ImportFileRequest) Try + User = pData.User + ' TODO: Add missing user properties in UserState from TBDD_USER 'pData.User = ResolveUserFromUserName(pData.User.UserName) @@ -46,17 +52,16 @@ Namespace Methods.GlobalIndexer.ImportFile Dim oPostProcessingSteps As DataTable = LoadPostProcessingSteps(oManualIndexes) LoadProfile(pData.ProfileId) - - Dim oFinalAttributes = pData.AttributeValues - Dim oFileName As String = GetFilenameByNameconvention(pData.File.FileName, Profile.Item("NAMENKONVENTION")) + Dim oUserAttributes = pData.AttributeValues + Dim oAutoAttributes As List(Of UserAttributeValue) = Nothing ' Apply post processing Dim oPostProcessing = New Steps.PostProcessing(LogConfig, oPostProcessingSteps) - oFinalAttributes = oPostProcessing.ApplyManualPostprocessing(oFinalAttributes) + oUserAttributes = oPostProcessing.ApplyManualPostprocessing(oUserAttributes) ' Apply automatic attributes Dim oAutomaticIndexing = New Steps.AutomaticIndexing(LogConfig, Database, oAutomaticIndexes, GlobalState) - oFinalAttributes = oAutomaticIndexing.ApplyAutomaticeAttributes(oFinalAttributes, pData.File.FileInfoRaw, pData.User) + oAutoAttributes = oAutomaticIndexing.ApplyAutomaticeAttributes(oUserAttributes, pData.File.FileInfoRaw, User) ' Import the file Dim oNewFile As New NewFileMethod(LogConfig, Database, GlobalState) @@ -65,7 +70,7 @@ Namespace Methods.GlobalIndexer.ImportFile .BusinessEntity = pData.BusinessEntity, .KindType = pData.KindType, .StoreName = pData.StoreName, - .User = pData.User + .User = User }) If oResponse.OK Then @@ -74,35 +79,23 @@ Namespace Methods.GlobalIndexer.ImportFile Throw New ApplicationException(oResponse.ErrorMessage) End If - Logger.Info("Writing Attributes for ObjectId [{0}]", oResponse.ObjectId) + Logger.Info("Generating display filename for file [{0}]", pData.File.FileName) - Dim oAttributes As New Dictionary(Of String, Object) - For Each oFinalAttribute In oFinalAttributes - If oFinalAttribute.AttributeValues Is Nothing OrElse oFinalAttribute.AttributeValues.Count = 0 Then - Logger.Warn("Values for Attribute [{0}] are empty. Skipping.", oFinalAttribute.AttributeName) - Continue For - End If + Dim oNameconvention As String = Profile.ItemEx(Of String)("NAMENKONVENTION") + Dim oDisplayFilename = GetFilenameByNameconvention(pData.File.FileInfoRaw, oNameconvention, User, oUserAttributes, oAutoAttributes) - oAttributes.Add(oFinalAttribute.AttributeName, oFinalAttribute.AttributeValues.First) - Next + Logger.Info("Collecting Attributes for ObjectId [{0}]", oResponse.ObjectId) - For Each oAttribute As KeyValuePair(Of String, Object) In oAttributes - Try - ' Dont write empty attributes - If oAttribute.Value Is Nothing Then - Continue For - End If + Dim oFinalAttributes As New Dictionary(Of String, List(Of String)) From { + {"DisplayFileName", New List(Of String) From {oDisplayFilename}} + } + oFinalAttributes = oFinalAttributes. + Concat(Helpers.UserAttributesToDictionary(oUserAttributes)). + Concat(Helpers.UserAttributesToDictionary(oAutoAttributes)). + ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value) - Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, oResponse.ObjectId, oAttribute.Key, oAttribute.Value, pData.User.Language, pData.User.UserName) - If oSuccess Then - Logger.Info("Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value) - Else - Logger.Warn("Attribute value could not be written") - End If - Catch ex As Exception - LogAndThrow(ex, $"Attribute [{oAttribute.Key}] could not be written!") - End Try - Next + Logger.Info("Writing [{0}] Attributes for ObjectId [{0}] ", oResponse.ObjectId) + WriteAttributeValues(oResponse.ObjectId, oFinalAttributes) ' Finally, commit the transaction Transaction?.Commit() @@ -120,14 +113,44 @@ Namespace Methods.GlobalIndexer.ImportFile End Try End Function + Private Function GetFilenameByNameconvention(pFileInfo As FileInfo, pNameconvention As String, pUser As UserState, pAttributes As List(Of UserAttributeValue), pAutoAttributes As List(Of UserAttributeValue)) As String + Dim oAttributeDict = Helpers.UserAttributesToDictionary(pAttributes) + Dim oAutoAttributeDict = Helpers.UserAttributesToDictionary(pAutoAttributes) + If pNameconvention Is Nothing OrElse pNameconvention = String.Empty Then + Logger.Warn("Nameconvention for File [{0}] was empty. Returning original filename.", pFileInfo.Name) + Return pFileInfo.Name + End If - - Private Function GetFilenameByNameconvention(pFileName As String, pNameconvention As String) As String - Return pFileName + Dim oFileName As String = Helpers.GetPlaceholderValue(pNameconvention, pFileInfo, pUser, oAttributeDict, oAutoAttributeDict) + Return oFileName & pFileInfo.Extension End Function + Private Sub WriteAttributeValues(pObjectId As Long, pAttributes As Dictionary(Of String, List(Of String))) + For Each oAttribute As KeyValuePair(Of String, List(Of String)) In pAttributes + Try + ' TODO: This works only for simple attributes for now!!! + Dim oValue = oAttribute.Value.FirstOrDefault() + + ' Dont write empty attributes + If oValue Is Nothing Then + Continue For + End If + + ' Now make the call to the database + Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, pObjectId, oAttribute.Key, oValue, User.Language, User.UserName) + If oSuccess Then + Logger.Info("Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value) + Else + Logger.Warn("Attribute value could not be written") + End If + Catch ex As Exception + LogAndThrow(ex, $"Attribute [{oAttribute.Key}] could not be written!") + End Try + Next + End Sub + ''' ''' Load Profiles for this Import ''' diff --git a/Service.EDMIService/Methods/GlobalIndexer/ImportFile/Steps/AutomaticIndexing.vb b/Service.EDMIService/Methods/GlobalIndexer/ImportFile/Steps/AutomaticIndexing.vb index 53ef6a7d..2143a26a 100644 --- a/Service.EDMIService/Methods/GlobalIndexer/ImportFile/Steps/AutomaticIndexing.vb +++ b/Service.EDMIService/Methods/GlobalIndexer/ImportFile/Steps/AutomaticIndexing.vb @@ -3,7 +3,7 @@ Imports DigitalData.Modules.Database Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Patterns Imports DigitalData.Modules.ZooFlow.State -Imports DigitalData.Services.EDMIService.GlobalState +Imports DigitalData.Services.EDMIService.IDB Namespace Methods.GlobalIndexer.ImportFile.Steps Public Class AutomaticIndexing @@ -12,6 +12,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps Private ReadOnly GlobalState As GlobalState Private ReadOnly AutomaticIndexes As List(Of AutomaticIndex) Private ReadOnly Patterns As Patterns2 + Private ReadOnly Helpers As Helpers Private ReadOnly Database As MSSQLServer Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pAutomaticIndexes As List(Of AutomaticIndex), pGlobalState As GlobalState) @@ -20,16 +21,21 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps GlobalState = pGlobalState AutomaticIndexes = pAutomaticIndexes Patterns = New Patterns2(pLogConfig) + Helpers = New Helpers(pLogConfig, pDatabase) Logger.Info("Starting Automatic Indexing") End Sub + ''' + ''' Generates a new list of Auto Attributes from the Auto Index configuration and External Data (like User, FileInfo and UserAttributes) + ''' + ''' A new list of Automatic Attributes. This list may be empty. Public Function ApplyAutomaticeAttributes(pUserAttributes As List(Of UserAttributeValue), pFileInfo As FileInfo, pUserState As UserState) As List(Of UserAttributeValue) Logger.Debug("Start of Method [ApplyAutomaticAttributes]") If AutomaticIndexes Is Nothing OrElse AutomaticIndexes.Count = 0 Then Logger.Warn("No Automatix Indexes supplied. Exiting.") - Return pUserAttributes + Return New List(Of UserAttributeValue) End If Logger.Info("Processing [{0}] automatic indexes", AutomaticIndexes.Count) @@ -47,8 +53,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps End If Next - oUserAttributes.AddRange(oAutoAttributes) - Return oUserAttributes + Return oAutoAttributes End Function Private Function ApplyAutomaticIndex(pAutomaticIndex As AutomaticIndex, @@ -57,9 +62,8 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps pAttributes As List(Of UserAttributeValue), pAutoAttributes As List(Of UserAttributeValue)) As UserAttributeValue Try - Dim oAttributeDict = pAttributes.ToDictionary( - Function(attr) attr.AttributeName, - Function(attr) attr.AttributeValues) + Dim oAttributeDict = Helpers.UserAttributesToDictionary(pAttributes) + Dim oAutoAttributeDict = Helpers.UserAttributesToDictionary(pAutoAttributes) Logger.Info("Applying Automatic Index [{0}]", pAutomaticIndex.Name) @@ -69,7 +73,8 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps ' If there is no SQL command, we use the Value property and replace all placeholders in it. If oHasSqlCommand = False Then - Dim oResult As String = GetPlaceholderValue(pAutomaticIndex.Value, pFileInfo, pUserState, oAttributeDict) + Dim oResult As String = Helpers.GetPlaceholderValue( + pAutomaticIndex.Value, pFileInfo, pUserState, oAttributeDict, oAutoAttributeDict) Return New UserAttributeValue With { .AttributeValues = New List(Of String) From {oResult}, @@ -86,7 +91,8 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps Logger.Debug("SQL Connection String is: [{0}]", oConnectionString) Logger.Debug("SQL Command is: [{0}]", oFinalSQLCommand) - oFinalSQLCommand = GetPlaceholderValue(oFinalSQLCommand, pFileInfo, pUserState, oAttributeDict) + oFinalSQLCommand = Helpers.GetPlaceholderValue( + oFinalSQLCommand, pFileInfo, pUserState, oAttributeDict, oAutoAttributeDict) ' Now we have a SQL command which only contains vector placeholders ' Next, we execute the command to get our result @@ -113,18 +119,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps End Try End Function - Private Function GetPlaceholderValue(pValue As String, pFileInfo As FileInfo, pUserState As UserState, pAttributes As Dictionary(Of String, List(Of String))) As String - Dim oResult As String = pValue - oResult = Patterns.ReplaceInternalValues(oResult) - oResult = Patterns.ReplaceFileValues(oResult, pFileInfo) - oResult = Patterns.ReplaceUserValues(oResult, pUserState) - - ' TODO: Get the automatic indexes in here too - oResult = Patterns.ReplaceGlobixValues(oResult, New Dictionary(Of String, List(Of String)), pAttributes) - - Return oResult - End Function End Class End Namespace \ No newline at end of file