2 Commits

Author SHA1 Message Date
Jonathan Jenne
a8f3828ad3 EDMI: Add VersionFileMethod WIP 2022-01-14 16:27:01 +01:00
Jonathan Jenne
6f417bb24e ZooFlow: Include more databasewithfallback calls in zooflow 2022-01-14 14:15:34 +01:00
13 changed files with 376 additions and 60 deletions

View File

@@ -3,12 +3,9 @@ Imports System.Threading
Imports System.Globalization
Imports DevExpress.XtraSplashScreen
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules.Language.Utils
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.EDMI.API
Imports DigitalData.Modules.EDMI.API.Constants
Imports DigitalData.Modules.Encryption
Imports DigitalData.GUIs.ZooFlow.ClassConstants
Imports DigitalData.GUIs.ZooFlow.ClassInitLoader
Imports DigitalData.Controls.SQLConfig
@@ -83,7 +80,7 @@ Public Class ClassInit
Throw New InitException("Fehler beim Laden der IDB Verbindungsdaten!")
End If
oDatatable = My.DatabaseECM.GetDatatable(oSQl)
oDatatable = My.Database.GetDatatableECM(oSQl)
End If
End If
@@ -147,7 +144,7 @@ Public Class ClassInit
Private Sub InitializeUser(MyApplication As My.MyApplication)
Try
Dim oSql As String = My.Queries.Common.FNDD_MODULE_INIT(Environment.UserName)
Dim oDatatable As DataTable = My.DatabaseECM.GetDatatable(oSql)
Dim oDatatable As DataTable = My.Database.GetDatatableECM(oSql)
If oDatatable Is Nothing Then
Throw New InitException("Benutzer konnte nicht geladen werden!")
@@ -195,7 +192,7 @@ Public Class ClassInit
Private Sub Initialize3rdParty(MyApplication As My.MyApplication)
Try
Dim oSql = "Select LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'"
Dim oDatatable As DataTable = My.DatabaseECM.GetDatatable(oSql)
Dim oDatatable As DataTable = My.Database.GetDatatableECM(oSql)
If oDatatable.Rows.Count = 0 Then
Throw New InitException("Konfiguration konnte nicht geladen werden!")
@@ -211,7 +208,7 @@ Public Class ClassInit
End Sub
Private Sub InitBasicConfig(MyApplication As My.MyApplication)
Try
My.Tables.DTIDB_COMMON_SQL = My.DatabaseIDB.GetDatatable("SELECT * FROM TBIDB_COMMON_SQL WHERE ACTIVE = 1")
My.Tables.DTIDB_COMMON_SQL = My.Database.GetDatatableIDB("SELECT * FROM TBIDB_COMMON_SQL WHERE ACTIVE = 1")
@@ -252,7 +249,7 @@ Public Class ClassInit
(BEZEICHNUNG, SQL_PROVIDER, SERVER, DATENBANK, USERNAME, PASSWORD, BEMERKUNG, AKTIV, ERSTELLTWER)
VALUES ('IDB', 'MS-SQLServer', '{oBuilder.DataSource}', '{oBuilder.InitialCatalog}', '{oBuilder.UserID}', '{oBuilder.Password}', 'Created by Zooflow', 1, '{Environment.UserName}')"
Return My.DatabaseECM.ExecuteNonQuery(oSql)
Return My.Database.ExecuteNonQueryECM(oSql)
Catch ex As Exception
Logger.Error(ex)
Return False

View File

@@ -80,21 +80,25 @@ Public Class frmGlobix_Index
BringToFront()
Focus()
Try
DocumentViewer1.Init(LogConfig, My.Application.Settings.GdPictureKey)
Catch ex As Exception
Logger.Error(ex)
End Try
Try
Refresh_Dokart()
pnlIndex.Controls.Clear()
My.Application.Globix.CURRENT_ISATTACHMENT = False
Dim oSql = $"SELECT HANDLE_TYPE FROM TBGI_FILES_USER WHERE GUID = {My.Application.Globix.CurrentWorkfile.Id}"
DropType = Await My.DatabaseECM.GetScalarValueAsync(oSql)
DropType = Await My.Database.GetScalarValueECMAsync(oSql)
My.Application.Globix.DeleteOriginalFile = My.UIConfig.Globix.DeleteOriginalFile
SplitContainerControl1.SplitterPosition = My.UIConfig.Globix.SplitterDistanceViewer
SourceDeleteItem.Enabled = True
SourceDeleteItem.Checked = My.UIConfig.Globix.DeleteOriginalFile
DocumentViewer1.Init(LogConfig, My.Application.Settings.GdPictureKey)
If DropType Is Nothing Then
Logger.Debug("File with Id [{0}] was not found in TBGI_FILES_USER. Exiting.", My.Application.Globix.CurrentWorkfile.Id)
CancelAttempts = MAX_CANCEL_ATTEMPTS
@@ -112,7 +116,7 @@ Public Class frmGlobix_Index
SetFilePreview(My.UIConfig.Globix.FilePreview)
MultifileCount = Await My.DatabaseECM.GetScalarValueAsync("SELECT COUNT(*) FROM TBGI_FILES_USER WHERE WORKED = 0 AND GUID <> " & My.Application.Globix.CurrentWorkfile.Id & " AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')")
MultifileCount = Await My.Database.GetScalarValueECMAsync("SELECT COUNT(*) FROM TBGI_FILES_USER WHERE WORKED = 0 AND GUID <> " & My.Application.Globix.CurrentWorkfile.Id & " AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')")
My.Application.Globix.MULTIINDEXING_ACTIVE = False
If MultifileCount > 0 Then
@@ -273,7 +277,7 @@ Public Class frmGlobix_Index
End Sub
Private Sub SkipItem_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles SkipItem.ItemClick
My.DatabaseECM.ExecuteNonQuery($"DELETE FROM TBGI_FILES_USER WHERE GUID = {My.Application.Globix.CurrentWorkfile.Id}")
My.Database.ExecuteNonQueryECM($"DELETE FROM TBGI_FILES_USER WHERE GUID = {My.Application.Globix.CurrentWorkfile.Id}")
CancelAttempts = MAX_CANCEL_ATTEMPTS
Close()
End Sub
@@ -492,7 +496,7 @@ Public Class frmGlobix_Index
Dim oMeta = DirectCast(pControl.Tag, ControlCreator.ControlMeta)
Dim oIndexName As String = oMeta.IndexName
Dim oSQL = $"SELECT * FROM TBDD_INDEX_MAN WHERE SQL_RESULT LIKE '%{oIndexName}%' AND DOK_ID = {SelectedDocType.Guid}"
Dim oDatatable As DataTable = My.DatabaseECM.GetDatatable(oSQL)
Dim oDatatable As DataTable = My.Database.GetDatatableECM(oSQL)
If Not IsNothing(oDatatable) Then
Logger.Debug("Found [{0}] depending controls for [{1}]", oDatatable.Rows.Count, pControl.Name)
@@ -526,10 +530,7 @@ Public Class frmGlobix_Index
Exit Sub
End If
Dim oConnectionString = GetConnectionString(SqlConnectionId)
Dim oDatatable As DataTable = My.DatabaseECM.GetDatatableWithConnection(pSqlCommand, oConnectionString)
Dim oDatatable As DataTable = My.Database.GetDatatable(pSqlCommand, SqlConnectionId)
Dim oFoundControl As Control = Nothing
For Each oControl As Control In pnlIndex.Controls
@@ -593,7 +594,7 @@ Public Class frmGlobix_Index
pSQLCommand = Patterns2.ReplaceInternalValues(pSQLCommand)
pSQLCommand = Patterns2.ReplaceUserValues(pSQLCommand, My.Application.User)
Dim oDatatable = My.DatabaseECM.GetDatatableWithConnection(pSQLCommand, oConnectionString)
Dim oDatatable = My.Database.GetDatatable(pSQLCommand, pConnectionId)
Return oDatatable
End If
Else
@@ -603,9 +604,9 @@ Public Class frmGlobix_Index
End Function
Function GetPlaceholderValue(InputValue As String, FileName As String) As String
Dim oResult As String = InputValue
Dim oPatterns As New Modules.Patterns.Patterns2(My.LogConfig)
Dim oFileInfo As New FileInfo(FileName)
Dim oPatterns As New Modules.Patterns.Patterns2(My.LogConfig)
oResult = oPatterns.ReplaceInternalValues(oResult)
oResult = oPatterns.ReplaceFileValues(oResult, oFileInfo)
oResult = oPatterns.ReplaceUserValues(oResult, My.Application.User)
@@ -657,7 +658,7 @@ Public Class frmGlobix_Index
Try
My.Application.Globix.ABORT_INDEXING = True
Dim sql As String = $"SELECT * FROM TBGI_FILES_USER WHERE WORKED = 0 AND UPPER(USER@WORK) = UPPER('{My.Application.User.UserName}')"
Dim DT As DataTable = My.DatabaseECM.GetDatatable(sql)
Dim DT As DataTable = My.Database.GetDatatableECM(sql)
Dim anz = DT.Rows.Count
For Each Filerow As DataRow In DT.Rows
@@ -676,7 +677,7 @@ Public Class frmGlobix_Index
End If
Next
'Zuerst die Daten des Ablaufs löschen
If My.DatabaseECM.ExecuteNonQuery($"DELETE FROM TBGI_FILES_USER WHERE UPPER(USER@WORK) = UPPER('{My.Application.User.UserName}')") = True Then
If My.Database.ExecuteNonQueryECM($"DELETE FROM TBGI_FILES_USER WHERE UPPER(USER@WORK) = UPPER('{My.Application.User.UserName}')") = True Then
If containsfw_file = True Then
If My.Application.User.Language = "de-DE" Then
MsgBox("Der Indexierungsprozess beinhaltete (auch) Dateien per Folderwatch!" & vbNewLine & "Diese Dateien wurden nicht gelöscht und verbleiben im Folderwatch-Verzeichnis!" & vbNewLine & "Bitte verschieben Sie die Dateien ggfls.", MsgBoxStyle.Information, "Achtung - Hinweis:")

View File

@@ -159,7 +159,7 @@ Public Class frmFlowForm
AddHandler Watcher.ClipboardChanged, AddressOf Watcher_ClipboardChanged
Dim oSQL = My.Queries.Common.FNIDB_GET_SEARCH_PROFILES(My.Application.User.UserId, My.Application.User.Language)
Dim oDatatable As DataTable = My.DatabaseIDB.GetDatatable(oSQL)
Dim oDatatable As DataTable = My.Database.GetDatatableIDB(oSQL)
PictureBoxSearch1.Visible = False
If Not IsNothing(oDatatable) OrElse oDatatable.Rows.Count > 0 Then
IDBSearchActive = True
@@ -275,7 +275,7 @@ Public Class frmFlowForm
Try
Dim oSql As String = "SELECT FOLDER_PATH FROM TBGI_FOLDERWATCH_USER WHERE FOLDER_TYPE = 'SCAN' AND USER_ID = " & My.Application.User.UserId
Dim oFolderwatchScanPath = My.DatabaseECM.GetScalarValue(oSql)
Dim oFolderwatchScanPath = My.Database.GetScalarValueECM(oSql)
oFolderwatchScanPath = IIf(IsDBNull(oFolderwatchScanPath), "", oFolderwatchScanPath)
@@ -308,21 +308,6 @@ Public Class frmFlowForm
'TODO: Refresh Data
End Sub
'Private Sub frmFlowForm_MouseLeave(sender As Object, e As EventArgs) Handles MyBase.MouseLeave
' Opacity = OPACITY_HIDDEN
'End Sub
'Private Sub frmFlowForm_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter
' Opacity = OPACITY_SHOWN
'End Sub
'Private Sub frmFlowForm_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove, PictureBoxDragDrop.MouseMove
' If e.Button = MouseButtons.Left Then
' NativeMethods.ReleaseCapture()
' NativeMethods.SendMessage(Handle, NativeMethods.WM_NCLBUTTONDOWN, NativeMethods.HTCAPTION, 0)
' End If
'End Sub
Private Sub frmFlowForm_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.KeyCode = Keys.Escape Then
If ESCHitCount > 0 Then
@@ -338,7 +323,7 @@ Public Class frmFlowForm
End Sub
Sub ExitZooflow()
Dim oResult As DialogResult = MessageBox.Show("Exit Zooflow", "Are you sure you want to close ZooFlow?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Dim oResult As DialogResult = MessageBox.Show("Are you sure you want to close ZooFlow?", "Exit Zooflow", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If oResult = DialogResult.Yes Then
Close()
Else
@@ -506,7 +491,7 @@ Public Class frmFlowForm
End If
'Erstmal alles löschen
My.DatabaseECM.ExecuteNonQuery("DELETE FROM TBGI_FILES_USER WHERE UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')")
My.Database.ExecuteNonQueryECM("DELETE FROM TBGI_FILES_USER WHERE UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')")
If FileDrop.Drop_File(e) = True Then
TimerCheckDroppedFiles.Start()
@@ -529,7 +514,7 @@ Public Class frmFlowForm
End Sub
Private Async Function Globix_Check_Dropped_Files() As Threading.Tasks.Task
Try
Await My.DatabaseECM.ExecuteNonQueryAsync($"DELETE FROM TBGI_FILES_USER WHERE WORKED = 1 AND UPPER(USER@WORK) = UPPER('{Environment.UserName}')")
Await My.Database.ExecuteNonQueryECMAsync($"DELETE FROM TBGI_FILES_USER WHERE WORKED = 1 AND UPPER(USER@WORK) = UPPER('{Environment.UserName}')")
Dim i As Integer
For Each pFile As String In FileDrop.files_dropped
@@ -546,7 +531,7 @@ Public Class frmFlowForm
Dim sql As String = "SELECT * FROM TBGI_FILES_USER WHERE WORKED = 0 AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')"
My.Application.Globix.DTACTUAL_FILES = Nothing
My.Application.Globix.DTACTUAL_FILES = Await My.DatabaseECM.GetDatatableAsync(sql)
My.Application.Globix.DTACTUAL_FILES = Await My.Database.GetDatatableECMAsync(sql)
My.Application.Globix.ABORT_INDEXING = False
Dim oOnlyFilesFromFilesystem = True
@@ -560,7 +545,7 @@ Public Class frmFlowForm
If My.Application.Globix.DTACTUAL_FILES.Rows.Count > 1 And oOnlyFilesFromFilesystem = False Then
frmGlobix_IndexFileList.ShowDialog()
My.Application.Globix.DTACTUAL_FILES = Nothing
My.Application.Globix.DTACTUAL_FILES = My.DatabaseECM.GetDatatable(sql)
My.Application.Globix.DTACTUAL_FILES = My.Database.GetDatatableECM(sql)
End If
For Each oRow As DataRow In My.Application.Globix.DTACTUAL_FILES.Rows
@@ -733,7 +718,7 @@ Public Class frmFlowForm
If My.Application.Globix.Folderwatchstarted = True Or My.UIConfig.Globix.FolderWatchScanStarted = True Then
'Prüfen ob alle Files abgearbeitet wurden
Dim sql = "SELECT * FROM TBGI_FILES_USER WHERE WORKED = 0 AND HANDLE_TYPE like '%|FW%' AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')"
My.Application.Globix.DTACTUAL_FILES = My.DatabaseECM.GetDatatable(sql)
My.Application.Globix.DTACTUAL_FILES = My.Database.GetDatatableECM(sql)
If My.Application.Globix.DTACTUAL_FILES.Rows.Count > 0 Then
My.Application.Globix.ABORT_INDEXING = False
@@ -759,7 +744,7 @@ Public Class frmFlowForm
Else
Logger.Info(" File not existing - Row will be deleted!")
Dim oDel = String.Format("DELETE FROM TBGI_FILES_USER WHERE GUID = {0}", FILEGUID)
My.DatabaseECM.ExecuteNonQuery(oDel)
My.Database.ExecuteNonQueryECM(oDel)
End If
Else
Logger.Info(" file '" & row.Item(1).ToString & "' could not be opened exclusively - fileInUse!")

View File

@@ -1,6 +1,5 @@
Imports System.IO
Imports System.ServiceModel
Imports System.Timers
Imports DigitalData.Modules.EDMI.API.Constants
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.EDMI.API.Rights
@@ -162,13 +161,14 @@ Public Class Client
Return ClientConfig
End Function
Private Async Function UpdateTimer_Elapsed(sender As Object, e As ElapsedEventArgs) As Task Handles UpdateTimer.Elapsed
Private Async Function UpdateTimer_Elapsed(sender As Object, e As Timers.ElapsedEventArgs) As Task Handles UpdateTimer.Elapsed
Try
Dim oTables As String() = Await Channel.GetCachedTablesAsync()
CachedTables = oTables.
Select(Function(table) table.ToUpper).
ToList()
Catch ex As Exception
Logger.Warn("Update of CachedTable was not successful!")
Logger.Error(ex)
CachedTables = New List(Of String)
End Try

View File

@@ -63,28 +63,52 @@ Public Class DatabaseWithFallback
})
End Function
Public Async Function GetDatatableECMAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of DataTable)
Return Await Task.Run(Function() GetDatatableECM(pSQL, pConnectionId))
End Function
Public Function GetDatatableIDB(pSQL As String, Optional pConnectionId As Integer = 0) As DataTable
Return GetDatatable(New GetDatatableOptions(pSQL, Constants.DatabaseType.IDB) With {
.ConnectionId = pConnectionId
})
End Function
Public Async Function GetDatatableIDBAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of DataTable)
Return Await Task.Run(Function() GetDatatableIDB(pSQL, pConnectionId))
End Function
Public Function GetScalarValueECM(pSQL As String, Optional pConnectionId As Integer = 0) As Object
Return GetScalarValue(pSQL, Constants.DatabaseType.ECM, pForceFallback:=False, pConnectionId)
End Function
Public Async Function GetScalarValueECMAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of Object)
Return Await Task.Run(Function() GetScalarValueECM(pSQL, pConnectionId))
End Function
Public Function GetScalarValueIDB(pSQL As String, Optional pConnectionId As Integer = 0) As Object
Return GetScalarValue(pSQL, Constants.DatabaseType.IDB, pForceFallback:=False, pConnectionId)
End Function
Public Async Function GetScalarValueIDBAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of Object)
Return Await Task.Run(Function() GetScalarValueIDB(pSQL, pConnectionId))
End Function
Public Function ExecuteNonQueryECM(pSQL As String, Optional pConnectionId As Integer = 0) As Boolean
Return ExecuteNonQuery(pSQL, Constants.DatabaseType.ECM, pForceFallback:=False, pConnectionId)
End Function
Public Async Function ExecuteNonQueryECMAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of Boolean)
Return Await Task.Run(Function() ExecuteNonQueryECM(pSQL, pConnectionId))
End Function
Public Function ExecuteNonQueryIDB(pSQL As String, Optional pConnectionId As Integer = 0) As Boolean
Return ExecuteNonQuery(pSQL, Constants.DatabaseType.IDB, pForceFallback:=False, pConnectionId)
End Function
Public Async Function ExecuteNonQueryIDBAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of Boolean)
Return Await Task.Run(Function() ExecuteNonQueryIDB(pSQL, pConnectionId))
End Function
''' <summary>
''' Returns a Datatable by trying to fetch a cached version from the service, then querying the database through the service and querying the database directly as fallback.
''' </summary>
@@ -94,6 +118,10 @@ Public Class DatabaseWithFallback
Return GetDatatable(pDataTableName, pOptions.FallbackSQL, pOptions.FallbackType, pOptions.FilterExpression, pOptions.SortByColumn, pOptions.ForceFallback, pOptions.ConnectionId)
End Function
Public Function GetDatatable(pSQL As String, pConnectionId As Integer) As DataTable
Return GetDatatable("FORCE_FALLBACK", pSQL, Constants.DatabaseType.ECM, pSortByColumn:=Nothing, pForceFallback:=False, pConnectionId:=pConnectionId)
End Function
''' <summary>
''' Returns a datatable directly from the database.
''' </summary>
@@ -166,11 +194,8 @@ Public Class DatabaseWithFallback
''' <param name="pDatabaseType">Named Database to use for the fallback SQL Command</param>
''' <param name="pForceFallback">Force the fallback, skipping the service completely</param>
''' <param name="pConnectionId">Connection Id to use, references TBDD_CONNECTION</param>
Public Function GetScalarValue(pSQL As String, pDatabaseType As Constants.DatabaseType, Optional pForceFallback As Boolean = False, Optional pConnectionId As Integer = 0) As DataTable
Public Function GetScalarValue(pSQL As String, pDatabaseType As Constants.DatabaseType, Optional pForceFallback As Boolean = False, Optional pConnectionId As Integer = 0) As Object
Try
Dim oResult As DataTable = Nothing
Dim oTableResult As TableResult = Nothing
' If there is no client, we assume there is no service (configured)
If _Client Is Nothing Then
Return GetScalarValueFromDatabase(pSQL, pDatabaseType, pConnectionId)
@@ -313,7 +338,7 @@ Public Class DatabaseWithFallback
Catch ex As Exception
_Logger.Warn("GetScalarValueFromService failed. Falling back to direct database access.")
_Logger.Error(ex)
Return GetDatatableFromDatabase(pSQLCommand, DatabaseType, pConnectionId)
Return GetScalarValueFromDatabase(pSQLCommand, DatabaseType, pConnectionId)
End Try
End Function

View File

@@ -74,12 +74,18 @@ Public Class EDMIService
End Function
#End Region
Public Function NewFile(Data As NewFile.NewFileRequest) As NewFile.NewFileResponse Implements IEDMIService.NewFile
Public Function NewFile(Data As NewFile.VersionFileRequest) As NewFile.VersionFileResponse Implements IEDMIService.NewFile
_Logger.Debug("Start of Method [NewFile]")
Dim oNewFile As New NewFile.NewFileMethod(LogConfig, MSSQL_IDB, MSSQL_ECM, GlobalState)
Return oNewFile.Run(Data)
End Function
Public Function VersionFile(Data As VersionFile.VersionFileRequest) As VersionFile.VersionFileResponse Implements IEDMIService.VersionFile
_Logger.Debug("Start of Method [VersionFile]")
Dim oVersionFile As New VersionFile.VersionFileMethod(LogConfig, MSSQL_IDB, MSSQL_ECM, GlobalState)
Return oVersionFile.Run(Data)
End Function
Public Function SetAttributeValue(Data As SetAttributeValue.SetAttributeValueRequest) As SetAttributeValue.SetAttributeValueResponse Implements IEDMIService.SetAttributeValue
_Logger.Debug("Start of Method [SetAttributeValue]")
Dim oSetAttributeValue As New SetAttributeValue.SetAttributeValueMethod(LogConfig, MSSQL_IDB, MSSQL_ECM, GlobalState)

View File

@@ -181,6 +181,9 @@
<Compile Include="Messages\DatabaseResult.vb" />
<Compile Include="EDMIService.vb" />
<Compile Include="Methods\IDB\AttributeValue.vb" />
<Compile Include="Methods\IDB\VersionFile\VersionFileMethod.vb" />
<Compile Include="Methods\IDB\VersionFile\VersionFileRequest.vb" />
<Compile Include="Methods\IDB\VersionFile\VersionFileResponse.vb" />
<Compile Include="Scheduler\Scheduler.vb" />
<Compile Include="Scheduler\DatatableJob.vb" />
<Compile Include="Scheduler\JobListener.vb" />
@@ -287,5 +290,6 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>

View File

@@ -81,7 +81,10 @@ Interface IEDMIService
#Region "Document (New)"
<OperationContract>
Function NewFile(Data As NewFile.NewFileRequest) As NewFile.NewFileResponse
Function NewFile(Data As NewFile.VersionFileRequest) As NewFile.VersionFileResponse
<OperationContract>
Function VersionFile(Data As VersionFile.VersionFileRequest) As VersionFile.VersionFileResponse
<OperationContract>
Function SetAttributeValue(Data As SetAttributeValue.SetAttributeValueRequest) As SetAttributeValue.SetAttributeValueResponse

View File

@@ -61,7 +61,7 @@ Namespace Methods.GlobalIndexer.ImportFile
' Import the file
Dim oNewFile As New NewFile.NewFileMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState)
Dim oResponse = oNewFile.Run(New NewFile.NewFileRequest With {
Dim oResponse = oNewFile.Run(New NewFile.VersionFileRequest With {
.File = pData.File,
.BusinessEntity = pData.BusinessEntity,
.KindType = pData.KindType,

View File

@@ -19,12 +19,12 @@ Namespace Methods.IDB.NewFile
Transaction = Connection.BeginTransaction()
End Sub
Public Function Run(pData As NewFile.NewFileRequest) As Methods.IDB.NewFile.NewFileResponse
Public Function Run(pData As NewFile.VersionFileRequest) As Methods.IDB.NewFile.VersionFileResponse
Dim oFilePath As String = Nothing
Dim oExistingObjectId = TestFileChecksumExists(pData.File.FileChecksum)
If oExistingObjectId > 0 Then
Return New NewFile.NewFileResponse(oExistingObjectId)
Return New NewFile.VersionFileResponse(oExistingObjectId)
End If
Try
@@ -157,7 +157,7 @@ Namespace Methods.IDB.NewFile
' Finally, commit the transaction
Transaction?.Commit()
Return New NewFile.NewFileResponse(oObjectId)
Return New NewFile.VersionFileResponse(oObjectId)
Catch ex As Exception
Logger.Warn("Error occurred while creating file!")
Logger.Error(ex)
@@ -175,7 +175,7 @@ Namespace Methods.IDB.NewFile
Logger.Info("Rolling back transaction.")
Transaction?.Rollback()
Return New NewFile.NewFileResponse(ex)
Return New NewFile.VersionFileResponse(ex)
End Try
End Function

View File

@@ -0,0 +1,235 @@
Imports System.Data.SqlClient
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Database.MSSQLServer.TransactionMode
Imports DigitalData.Modules.Logging
Imports DigitalData.Services.EDMIService.Methods
Imports DigitalData.Services.EDMIService.GlobalState
Namespace Methods.IDB.VersionFile
Public Class VersionFileMethod
Inherits BaseMethod
Private ReadOnly Connection As SqlConnection
Private ReadOnly Transaction As SqlTransaction
Public Sub New(pLogConfig As LogConfig, pDatabaseIDB As MSSQLServer, pDatabaseECM As MSSQLServer, pGlobalState As GlobalState)
MyBase.New(pLogConfig, pDatabaseIDB, pDatabaseECM, pGlobalState)
Connection = DatabaseIDB.GetConnection()
Transaction = Connection.BeginTransaction()
End Sub
Public Function Run(pData As VersionFileRequest) As VersionFileResponse
Dim oFilePath As String = Nothing
Dim oExistingObjectId = TestFileChecksumExists(pData.File.FileChecksum)
If oExistingObjectId > 0 Then
Return New VersionFileResponse(oExistingObjectId)
End If
Try
Dim oObjectId = NewObjectId(pData.KindType, pData.BusinessEntity, pData.User.UserName)
If oObjectId = 0 Then
LogAndThrow("Could not create new ObjectId!")
End If
' Find ObjectStore by Title
Logger.Debug("Checking for DataStore [{0}].", pData.StoreName)
Dim oStore = GlobalState.ObjectStores.
Where(Function(store) store.Title.Equals(pData.StoreName, StringComparison.OrdinalIgnoreCase)).
SingleOrDefault()
If oStore Is Nothing Then
LogAndThrow($"DataStore [{pData.StoreName}] does not exist. Exiting.")
End If
' Get Store base path
Dim oBasePath As String = oStore.Path
Logger.Debug("Store BasePath is [{0}]", oBasePath)
' Get directory by DateImported or, if not supplied, by current date
Dim oSubDirectory As String
If IsNothing(pData.File.FileImportedAt) Then
oSubDirectory = GetDateSubDirectory(Now)
Else
oSubDirectory = GetDateSubDirectory(pData.File.FileImportedAt)
End If
Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
' Check and create final path, if necessary
Dim oFinalPath = IO.Path.Combine(oBasePath, oSubDirectory)
If Not IO.Directory.Exists(oFinalPath) Then
Try
Logger.Debug("Path does not exist, creating: [{0}]", oFinalPath)
IO.Directory.CreateDirectory(oFinalPath)
Logger.Debug("Created folder [{0}]", oFinalPath)
Catch ex As Exception
LogAndThrow(ex, $"Store Directory [{oFinalPath}] could not be created!")
End Try
End If
Logger.Debug("Final Directory is [{0}]", oFinalPath)
' Get filename
Dim oKeepFileName As Boolean = False
If oStore.IsArchive Then
Logger.Debug("Object Store is an archive: [{0}]", oStore.IsArchive)
oKeepFileName = True
End If
Dim oFileName As String = GetFileObjectFileName(oObjectId, pData.File.FileName, oKeepFileName)
Logger.Debug("Filename is [{0}]", oFileName)
oFilePath = IO.Path.Combine(oFinalPath, oFileName)
Dim oFileObjectInfo As IO.FileInfo = New IO.FileInfo(oFilePath)
Dim oFileObjectSize As Long = pData.File.FileContents.Length
Dim oFileObjectName As String = oFileObjectInfo.Name
Dim oOriginalExtension As String = pData.File.FileInfoRaw.Extension.Substring(1)
Logger.Debug("File Information for [{0}]:", oFileObjectName)
Logger.Debug("Size: [{0}]", oFileObjectSize)
Logger.Debug("Original Extension: [{0}]", oOriginalExtension)
Logger.Debug("Checksum: [{0}]", pData.File.FileChecksum)
Try
Using oStream = New IO.FileStream(oFilePath, IO.FileMode.Create, IO.FileAccess.Write)
Logger.Info("Saving file to path [{0}]", oFilePath)
oStream.Write(pData.File.FileContents, 0, oFileObjectSize)
oStream.Flush(True)
oStream.Close()
End Using
Catch ex As Exception
LogAndThrow(ex, $"Could not write file [{oFilePath}] to disk!")
End Try
'---------------------------------------------------------------------------
Logger.Info("Creating IDB FileObject for ObjectId [{0}].", oObjectId)
' Insert into DB
Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO
'{oFinalPath}',
'{oFileObjectName}',
'{oOriginalExtension}',
{oFileObjectSize},
'{pData.File.FileChecksum}' ,
'{pData.User.UserName}',
'{oObjectId}',
{oStore.Id}"
Dim oResult As Boolean = DatabaseIDB.ExecuteNonQueryWithConnectionObject(oSQL, Connection, ExternalTransaction, Transaction)
If oResult = False Then
LogAndThrow("IDB FileObject could not be created!")
End If
'---------------------------------------------------------------------------
'TODO: File dates in try catch
Dim oSystemAttributes As New Dictionary(Of String, Object) From {
{"OriginFileName", pData.File.FileName},
{"OriginCreationDatetime", pData.File.FileCreatedAt},
{"OriginChangedDatetime", pData.File.FileChangedAt}
}
For Each oAttribute As KeyValuePair(Of String, Object) In oSystemAttributes
Try
' Dont write empty attributes
If oAttribute.Value Is Nothing Then
Continue For
End If
Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, oObjectId, oAttribute.Key, oAttribute.Value, pData.User.Language, pData.User.UserName)
If oSuccess Then
Logger.Debug("System Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value)
Else
Logger.Warn("System attribute value could not be written")
End If
Catch ex As Exception
LogAndThrow(ex, $"System attribute [{oAttribute.Key}] could not be written!")
End Try
Next
'---------------------------------------------------------------------------
' Finally, commit the transaction
Transaction?.Commit()
Return New VersionFileResponse(oObjectId)
Catch ex As Exception
Logger.Warn("Error occurred while creating file!")
Logger.Error(ex)
Logger.Info("Cleaning up files.")
If Not IsNothing(oFilePath) AndAlso IO.File.Exists(oFilePath) Then
Try
IO.File.Delete(oFilePath)
Catch exInner As Exception
Logger.Warn("Error while cleaning up files.")
Logger.Error(exInner)
End Try
End If
Logger.Info("Rolling back transaction.")
Transaction?.Rollback()
Return New VersionFileResponse(ex)
End Try
End Function
Private Function TestFileChecksumExists(pChecksum As String) As Long
Try
Dim oChecksumSQL = $"SELECT IDB_OBJ_ID FROM TBIDB_FILE_OBJECT WHERE FILE_HASH = '{pChecksum}'"
Dim oExistingObjectId As Long = DatabaseIDB.GetScalarValue(oChecksumSQL)
If oExistingObjectId > 0 Then
Logger.Info("Returning early with ObjectId [{0}] because Checksum [{1}] already exists.", oExistingObjectId, pChecksum)
Return oExistingObjectId
End If
Return Nothing
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Private Function NewObjectId(pKindType As String, pBusinessEntity As String, pWho As String) As Long
Try
Dim oNewObjectIdSQL = $"DECLARE @NEW_IDB_OBJ_ID BIGINT
EXEC PRIDB_NEW_OBJECT '{pKindType}','{pWho}','{pBusinessEntity}',0, @IDB_OBJ_ID = @NEW_IDB_OBJ_ID OUTPUT;
SELECT @NEW_IDB_OBJ_ID"
Dim oObjectId As Long = DatabaseIDB.GetScalarValueWithConnectionObject(oNewObjectIdSQL, Connection, ExternalTransaction, Transaction)
Logger.Info("New Object with Id [{0}] created!", oObjectId)
If IsNothing(oObjectId) Then
LogAndThrow("Could not create new ObjectId!")
End If
Return oObjectId
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pFilename As String, pKeepFilename As Boolean) As String
' TODO: save actual extensions
If pKeepFilename Then
Return pFilename
Else
Return $"{IDB_OBJ_ID}.ddfo"
End If
End Function
Private Function GetDateSubDirectory(pDate As Date) As String
Return IO.Path.Combine(pDate.ToString("yyyy"), pDate.ToString("MM"), pDate.ToString("dd"))
End Function
End Class
End Namespace

View File

@@ -0,0 +1,38 @@
Imports System.Runtime.Serialization
Imports DigitalData.Modules.ZooFlow.State
Namespace Methods.IDB.VersionFile
<Serializable>
<DataContract>
Public Class VersionFileRequest
<DataMember>
Public Property File As FileProperties
''' <summary>
''' Name/title of the ObjectStore to save the file to, ex. Work
''' </summary>
<DataMember>
Public Property StoreName As String
''' <summary>
''' The business entity of the file, ex DEFAULT
''' </summary>
<DataMember>
Public Property BusinessEntity As String
''' <summary>
''' The kind of object to be created, ex. DOC
''' </summary>
<DataMember>
Public Property KindType As String
''' <summary>
''' User Importing the file
''' </summary>
''' <returns></returns>
<DataMember>
Public Property User As UserState
End Class
End Namespace

View File

@@ -0,0 +1,22 @@
Imports System.Runtime.Serialization
Namespace Methods.IDB.VersionFile
<Serializable>
<DataContract>
Public Class VersionFileResponse
Inherits Messages.BaseResponse
<DataMember>
Public Property ObjectId As Long
Public Sub New(pObjectId As Long)
MyBase.New()
ObjectId = pObjectId
End Sub
Public Sub New(pException As Exception, Optional pDetails As String = "")
MyBase.New(pException, pDetails)
End Sub
End Class
End Namespace