EDMIService: Small tweaks for AppServer

This commit is contained in:
Jonathan Jenne 2021-06-17 13:11:39 +02:00
parent 54e93d0f73
commit 2529c30726
3 changed files with 64 additions and 85 deletions

View File

@ -106,8 +106,7 @@ Public Class EDMIService
Return New TableResult(oFilteredTable)
Else
_Logger.Warn($"ReturnDatatableFromCache: Datatable {Name} does not exist")
Dim oDetails As New DataTableDoesNotExistFault(Name)
Throw New FaultException(Of DataTableDoesNotExistFault)(oDetails)
Throw GetFault($"ReturnDatatableFromCache: Datatable {Name} does not exist")
End If
Catch ex As FaultException
@ -116,8 +115,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -137,8 +135,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -155,8 +152,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -173,8 +169,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -194,8 +189,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -212,8 +206,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -230,8 +223,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -251,8 +243,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -269,8 +260,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -287,8 +277,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -345,8 +334,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -390,8 +378,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -417,10 +404,9 @@ Public Class EDMIService
Throw ex
Catch ex As Exception
Dim oDetails As New UnexpectedErrorFault(ex)
_Logger.Warn("GetFileInfoByObjectId: " & oDetails.ErrorMessage)
_Logger.Warn("GetFileInfoByObjectId: " & ex.Message)
_Logger.Error(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -439,8 +425,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -528,8 +513,7 @@ Public Class EDMIService
Dim oObjectId = MSSQL_IDB.GetScalarValue(oSQL)
If oObjectId Is Nothing Then
Dim oDetails As New UnexpectedErrorFault(New Exception("NewObjectId: Could not create new ObjectId!"))
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault("NewObjectId: Could not create new ObjectId!")
End If
Return New NewObjectIdResponse With {.ObjectId = oObjectId}
@ -539,37 +523,50 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
Public Function NewFileObject(Data As NewFileObjectRequest) As NewFileObjectResponse Implements IEDMIService.NewFileObject
Try
Dim oRelpath As String
Dim oStoreType As String = Data.StoreType
_Logger.Debug("DataStore type is [{0}]", oStoreType)
If oStoreType = String.Empty Then
_Logger.Debug("DataStore empty, set to [{0}]", ClassConstants.FileStoreWork)
oStoreType = ClassConstants.FileStoreWork
End If
oRelpath = GetFileStorePraefix(oStoreType)
Dim oRelpath As String = GetFileStorePraefix(oStoreType)
Dim oSubDirectory As String
If IsNothing(Data.DateImported) Then
oRelpath = GetFolderToday(oRelpath)
oSubDirectory = GetDateSubDirectory(Now)
Else
oSubDirectory = GetDateSubDirectory(Data.DateImported)
End If
_Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
oRelpath = Path.Combine(oRelpath, oSubDirectory)
If Not Directory.Exists(oRelpath) Then
Try
Dim oDate = CDate(Data.DateImported)
oRelpath = GetFolderDate(oRelpath, oDate)
_Logger.Debug("Path does not exist, creating: [{0}]", oRelpath)
Directory.CreateDirectory(oRelpath)
_Logger.Debug("Created folder [{0}]", oRelpath)
Catch ex As Exception
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End If
_Logger.Debug($"oRelpath is [{oRelpath}]")
_Logger.Debug("Relative Path is [{0}]", oRelpath)
Dim oFileObjectPath As String = Path.Combine(oRelpath, GetFileObjectFileName(Data.ObjectId, Data.Extension, Data.KeepExtension))
_Logger.Debug("Final Path is [{0}]", oFileObjectPath)
Return New NewFileObjectResponse With {.FileObjectPath = oFileObjectPath}
Catch ex As FaultException
_Logger.Error(ex)
@ -577,8 +574,7 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
@ -609,63 +605,49 @@ Public Class EDMIService
Catch ex As Exception
_Logger.Error(ex)
Dim oDetails As New UnexpectedErrorFault(ex)
Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage)
Throw GetFault(ex)
End Try
End Function
#End Region
Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pExtension As String, pKeepExtension As Boolean) As String
If Not pExtension.StartsWith("."c) Then
pExtension &= "."c
End If
If pKeepExtension Then
Return $"{IDB_OBJ_ID}.{pExtension}"
Return $"{IDB_OBJ_ID}{pExtension}"
Else
Return $"{IDB_OBJ_ID}.ddfo"
End If
End Function
Private Function GetFileStorePraefix(pStoreType As String) As String
Dim oObjectStore
If pStoreType = ClassConstants.FileStoreArchive Then
oObjectStore = GlobalState.ObjectStores.Item(0)
Else ' pStoreType = ClassConstants.FileStoreWork Then
oObjectStore = GlobalState.ObjectStores.Item(1)
End If
_Logger.Debug($"oObjectStore is [{oObjectStore.Path}]")
Return oObjectStore.Path
End Function
Private Function GetFolderToday(pRelationalPath As String) As String
Dim oDateSubDirectoryName As String = GetDateSubDirectory(Now)
Dim oFolderToday As String = Path.Combine(pRelationalPath, oDateSubDirectoryName)
' Create the destination directory if it does not exist
If Not Directory.Exists(oFolderToday) Then
Try
Directory.CreateDirectory(oFolderToday)
_Logger.Debug($"Created NEW todayFolder [{oFolderToday}]")
Catch ex As Exception
_Logger.Error(ex)
Return ""
End Try
End If
Return oFolderToday
End Function
Private Function GetFolderDate(pRelationalPath As String, pDate As Date) As String
Dim oDateSubDirectoryName As String = GetDateSubDirectory(pDate)
Dim oFolderDateSepecial As String = Path.Combine(pRelationalPath, oDateSubDirectoryName)
' Create the destination directory if it does not exist
If Not Directory.Exists(oFolderDateSepecial) Then
Try
Directory.CreateDirectory(oFolderDateSepecial)
_Logger.Debug($"Created NEW DateSpecialFolder [{oFolderDateSepecial}]")
Catch ex As Exception
_Logger.Error(ex)
Return ""
End Try
End If
Return oFolderDateSepecial
End Function
Private Function GetDateSubDirectory([Date] As Date) As String
Return [Date].ToString("yyyy-MM-dd")
Private Function GetDateSubDirectory(pDate As Date) As String
Return Path.Combine(pDate.ToString("yyyy"), pDate.ToString("MM"), pDate.ToString("dd"))
End Function
Private Function GetFault(Exception As Exception) As FaultException
Dim oFault As New UnexpectedErrorFault(Exception)
Return New FaultException(Of UnexpectedErrorFault)(oFault, New FaultReason(oFault.InnerException.Message))
End Function
Private Function GetFault(ErrorMessage As String) As FaultException
Dim oFault As New UnexpectedErrorFault(New ApplicationException(ErrorMessage))
Return New FaultException(Of UnexpectedErrorFault)(oFault, New FaultReason(oFault.InnerException.Message))
End Function
End Class

View File

@ -12,10 +12,6 @@ Namespace Exceptions
End Sub
End Class
<DataContract>
Public Class BaseFault
''' <summary>

View File

@ -22,7 +22,8 @@ Public Class Scheduler
Public Sub New(LogConfig As LogConfig, MSSQL_ECM As MSSQLServer, TableStore As DataSet)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_Logger = LogConfig.GetLoggerFor("Scheduler")
_Factory = New StdSchedulerFactory(_Props)
_MSSQL = MSSQL_ECM
_JobListener = New JobListener(LogConfig, _MSSQL, TableStore)