diff --git a/EDMIService.Tests/EDMIService.Tests.vbproj b/EDMIService.Tests/EDMIService.Tests.vbproj
new file mode 100644
index 00000000..3f162b8b
--- /dev/null
+++ b/EDMIService.Tests/EDMIService.Tests.vbproj
@@ -0,0 +1,128 @@
+
+
+
+
+
+ Debug
+ AnyCPU
+ {E3DA65CA-964D-4896-991A-B5426884E215}
+ Library
+ EDMIService.Tests
+ EDMIService.Tests
+ 512
+ Windows
+ v4.7.2
+ {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}
+ 10.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
+ False
+ UnitTest
+
+
+
+
+ true
+ full
+ true
+ true
+ bin\Debug\
+ EDMIService.Tests.xml
+ 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
+
+
+ pdbonly
+ false
+ true
+ true
+ bin\Release\
+ EDMIService.Tests.xml
+ 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
+
+
+ On
+
+
+ Binary
+
+
+ Off
+
+
+ On
+
+
+
+ ..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll
+
+
+ ..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ Application.myapp
+
+
+ True
+ True
+ Resources.resx
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+ VbMyResourcesResXFileCodeGenerator
+ Resources.Designer.vb
+ My.Resources
+ Designer
+
+
+
+
+ MyApplicationCodeGenerator
+ Application.Designer.vb
+
+
+ SettingsSingleFileGenerator
+ My
+ Settings.Designer.vb
+
+
+
+
+
+
+
+ Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".
+
+
+
+
+
+
\ No newline at end of file
diff --git a/EDMIService.Tests/My Project/Application.Designer.vb b/EDMIService.Tests/My Project/Application.Designer.vb
new file mode 100644
index 00000000..88dd01c7
--- /dev/null
+++ b/EDMIService.Tests/My Project/Application.Designer.vb
@@ -0,0 +1,13 @@
+'------------------------------------------------------------------------------
+'
+' This code was generated by a tool.
+' Runtime Version:4.0.30319.42000
+'
+' Changes to this file may cause incorrect behavior and will be lost if
+' the code is regenerated.
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
diff --git a/EDMIService.Tests/My Project/Application.myapp b/EDMIService.Tests/My Project/Application.myapp
new file mode 100644
index 00000000..758895de
--- /dev/null
+++ b/EDMIService.Tests/My Project/Application.myapp
@@ -0,0 +1,10 @@
+
+
+ false
+ false
+ 0
+ true
+ 0
+ 1
+ true
+
diff --git a/EDMIService.Tests/My Project/AssemblyInfo.vb b/EDMIService.Tests/My Project/AssemblyInfo.vb
new file mode 100644
index 00000000..1827f286
--- /dev/null
+++ b/EDMIService.Tests/My Project/AssemblyInfo.vb
@@ -0,0 +1,18 @@
+Imports System
+Imports System.Reflection
+Imports System.Runtime.InteropServices
+
+
+
+
+
+
+
+
+
+
+
+
+'
+
+
diff --git a/EDMIService.Tests/My Project/Resources.Designer.vb b/EDMIService.Tests/My Project/Resources.Designer.vb
new file mode 100644
index 00000000..a7b5bc0f
--- /dev/null
+++ b/EDMIService.Tests/My Project/Resources.Designer.vb
@@ -0,0 +1,62 @@
+'------------------------------------------------------------------------------
+'
+' This code was generated by a tool.
+' Runtime Version:4.0.30319.42000
+'
+' Changes to this file may cause incorrect behavior and will be lost if
+' the code is regenerated.
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
+
+Namespace My.Resources
+
+ 'This class was auto-generated by the StronglyTypedResourceBuilder
+ 'class via a tool like ResGen or Visual Studio.
+ 'To add or remove a member, edit your .ResX file then rerun ResGen
+ 'with the /str option, or rebuild your VS project.
+ '''
+ ''' A strongly-typed resource class, for looking up localized strings, etc.
+ '''
+ _
+ Friend Module Resources
+
+ Private resourceMan As Global.System.Resources.ResourceManager
+
+ Private resourceCulture As Global.System.Globalization.CultureInfo
+
+ '''
+ ''' Returns the cached ResourceManager instance used by this class.
+ '''
+ _
+ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
+ Get
+ If Object.ReferenceEquals(resourceMan, Nothing) Then
+ Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("EDMIService.Tests.Resources", GetType(Resources).Assembly)
+ resourceMan = temp
+ End If
+ Return resourceMan
+ End Get
+ End Property
+
+ '''
+ ''' Overrides the current thread's CurrentUICulture property for all
+ ''' resource lookups using this strongly typed resource class.
+ '''
+ _
+ Friend Property Culture() As Global.System.Globalization.CultureInfo
+ Get
+ Return resourceCulture
+ End Get
+ Set(ByVal value As Global.System.Globalization.CultureInfo)
+ resourceCulture = value
+ End Set
+ End Property
+ End Module
+End Namespace
diff --git a/EDMIService.Tests/My Project/Resources.resx b/EDMIService.Tests/My Project/Resources.resx
new file mode 100644
index 00000000..af7dbebb
--- /dev/null
+++ b/EDMIService.Tests/My Project/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/EDMIService.Tests/My Project/Settings.Designer.vb b/EDMIService.Tests/My Project/Settings.Designer.vb
new file mode 100644
index 00000000..33d9134f
--- /dev/null
+++ b/EDMIService.Tests/My Project/Settings.Designer.vb
@@ -0,0 +1,73 @@
+'------------------------------------------------------------------------------
+'
+' This code was generated by a tool.
+' Runtime Version:4.0.30319.42000
+'
+' Changes to this file may cause incorrect behavior and will be lost if
+' the code is regenerated.
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
+
+Namespace My
+
+ _
+ Partial Friend NotInheritable Class MySettings
+ Inherits Global.System.Configuration.ApplicationSettingsBase
+
+ Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings)
+
+#Region "My.Settings Auto-Save Functionality"
+#If _MyType = "WindowsForms" Then
+ Private Shared addedHandler As Boolean
+
+ Private Shared addedHandlerLockObject As New Object
+
+ _
+ Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
+ If My.Application.SaveMySettingsOnExit Then
+ My.Settings.Save()
+ End If
+ End Sub
+#End If
+#End Region
+
+ Public Shared ReadOnly Property [Default]() As MySettings
+ Get
+
+#If _MyType = "WindowsForms" Then
+ If Not addedHandler Then
+ SyncLock addedHandlerLockObject
+ If Not addedHandler Then
+ AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
+ addedHandler = True
+ End If
+ End SyncLock
+ End If
+#End If
+ Return defaultInstance
+ End Get
+ End Property
+ End Class
+End Namespace
+
+Namespace My
+
+ _
+ Friend Module MySettingsProperty
+
+ _
+ Friend ReadOnly Property Settings() As Global.EDMIService.Tests.My.MySettings
+ Get
+ Return Global.EDMIService.Tests.My.MySettings.Default
+ End Get
+ End Property
+ End Module
+End Namespace
diff --git a/EDMIService.Tests/My Project/Settings.settings b/EDMIService.Tests/My Project/Settings.settings
new file mode 100644
index 00000000..85b890b3
--- /dev/null
+++ b/EDMIService.Tests/My Project/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/EDMIService.Tests/UnitTest1.vb b/EDMIService.Tests/UnitTest1.vb
new file mode 100644
index 00000000..9dd9a080
--- /dev/null
+++ b/EDMIService.Tests/UnitTest1.vb
@@ -0,0 +1,9 @@
+Imports System.Text
+Imports Microsoft.VisualStudio.TestTools.UnitTesting
+
+ Public Class UnitTest1
+
+ Public Sub TestMethod1()
+ End Sub
+
+End Class
\ No newline at end of file
diff --git a/EDMIService.Tests/packages.config b/EDMIService.Tests/packages.config
new file mode 100644
index 00000000..7079f816
--- /dev/null
+++ b/EDMIService.Tests/packages.config
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Service.EDMIService/BaseClass.vb b/Service.EDMIService/BaseClass.vb
new file mode 100644
index 00000000..92377d5e
--- /dev/null
+++ b/Service.EDMIService/BaseClass.vb
@@ -0,0 +1,11 @@
+Imports DigitalData.Modules.Logging
+
+Public Class BaseClass
+ Friend LogConfig As LogConfig
+ Friend Logger As Logger
+
+ Public Sub New(pLogConfig As LogConfig)
+ LogConfig = pLogConfig
+ Logger = pLogConfig.GetLogger()
+ End Sub
+End Class
diff --git a/Service.EDMIService/BaseMethod.vb b/Service.EDMIService/BaseMethod.vb
new file mode 100644
index 00000000..f54faa5f
--- /dev/null
+++ b/Service.EDMIService/BaseMethod.vb
@@ -0,0 +1,26 @@
+Imports DigitalData.Modules.Database
+Imports DigitalData.Modules.Logging
+Imports DigitalData.Services.EDMIService.IDB
+
+Public MustInherit Class BaseMethod
+ Inherits BaseClass
+
+ Friend ReadOnly Database As MSSQLServer
+ Friend ReadOnly Helpers As Helpers
+
+ Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
+ MyBase.New(pLogConfig)
+ Database = pMSSQLServer
+ Helpers = New Helpers(pLogConfig, pMSSQLServer)
+ End Sub
+
+ Public Function LogAndThrow(pMessage As String)
+ Logger.Warn(pMessage)
+ Throw New ApplicationException(pMessage)
+ End Function
+
+ Public Function LogAndThrow(pException As Exception)
+ Logger.Error(pException)
+ Throw pException
+ End Function
+End Class
diff --git a/Service.EDMIService/EDMIService.vb b/Service.EDMIService/EDMIService.vb
index 456aaa28..ae0a4dfc 100644
--- a/Service.EDMIService/EDMIService.vb
+++ b/Service.EDMIService/EDMIService.vb
@@ -11,6 +11,7 @@ Imports DigitalData.Modules.EDMI.API.Rights
Imports DigitalData.Services.EDMIService.Exceptions
Imports DigitalData.Services.EDMIService.GlobalState
Imports DigitalData.Services.EDMIService.FileStorage
+Imports DigitalData.Services.EDMIService.FileStorage.SetAttributeValue
Public Class EDMIService
@@ -33,6 +34,9 @@ Public Class EDMIService
Private ReadOnly _Debug As Boolean = False
Private ReadOnly _Username As String
+ Private _IDBHelpers As IDB.Helpers
+
+
Public Shared Sub Configure(Config As ServiceConfiguration)
Dim oBaseAddress = Config.BaseAddresses.Item(0)
Dim oBinding = EDMI.API.Channel.GetBinding()
@@ -53,111 +57,21 @@ Public Class EDMIService
_Username = oUsername
_Logger = LogConfig.GetLogger()
_Logger.Debug("New Request by User [{0}]", _Username)
+
+ _IDBHelpers = New IDB.Helpers(LogConfig, MSSQL_IDB)
End Sub
Public Function NewFile(Data As NewFile.NewFileRequest) As NewFile.NewFileResponse Implements IEDMIService.NewFile
_Logger.Debug("Start of Method [NewFile]")
-
- Try
- Dim oNewObjectIdSQL = $"DECLARE @NEW_IDB_OBJ_ID BIGINT
- EXEC PRIDB_NEW_OBJECT '{Data.KindType}','{Data.Who}','{Data.BusinessEntity}',0, @IDB_OBJ_ID = @NEW_IDB_OBJ_ID OUTPUT;
- SELECT @NEW_IDB_OBJ_ID"
- Dim oObjectId As Long = MSSQL_IDB.GetScalarValue(oNewObjectIdSQL)
- _Logger.Info("New Object with Id [{0}] created!", oObjectId)
-
- If IsNothing(oObjectId) Then
- LogAndThrow("Could not create new ObjectId!")
- End If
-
- '---------------------------------------------------------------------------
-
- ' Find ObjectStore by Title
- _Logger.Debug("Checking for DataStore [{0}].", Data.StoreName)
- Dim oStore = GlobalState.ObjectStores.
- Where(Function(store) store.Path.Equals(Data.StoreName, StringComparison.OrdinalIgnoreCase)).
- SingleOrDefault()
-
- If oStore Is Nothing Then
- LogAndThrow($"DataStore [{Data.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(Data.FileImportedAt) Then
- oSubDirectory = GetDateSubDirectory(Now)
- Else
- oSubDirectory = GetDateSubDirectory(Data.FileImportedAt)
- End If
- _Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
-
- ' Check and create final path, if necessary
- Dim oFinalPath = Path.Combine(oBasePath, oSubDirectory)
- If Not Directory.Exists(oFinalPath) Then
- Try
- _Logger.Debug("Path does not exist, creating: [{0}]", oFinalPath)
- Directory.CreateDirectory(oFinalPath)
- _Logger.Debug("Created folder [{0}]", oFinalPath)
- Catch ex As Exception
- Throw GetFault(ex)
- 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, Data.FileName, oKeepFileName)
- _Logger.Debug("Filename is [{0}]", oFileName)
-
- Dim oFileObjectPath As String = Path.Combine(oFinalPath, oFileName)
- Dim oFileObjectInfo As FileInfo = New FileInfo(oFileObjectPath)
-
- Dim oFileObjectSize As Long = Data.FileContents.Length
- Dim oFileObjectExtension As String = oFileObjectInfo.Extension.Substring(1)
- Dim oFileObjectName As String = oFileObjectInfo.Name
-
- _Logger.Debug("File Information for [{0}]:", oFileObjectName)
- _Logger.Debug("Size: [{0}]", oFileObjectSize)
- _Logger.Debug("Extension: [{0}]", oFileObjectExtension)
- _Logger.Debug("Checksum: [{0}]", Data.FileChecksum)
-
- Try
- Using oStream = New FileStream(oFileObjectPath, FileMode.Create, FileAccess.Write)
- _Logger.Info("ImportFile: Saving file to path [{0}]", oFileObjectPath)
- _Logger.Info("ImportFile: Content Length: {0}", oFileObjectSize)
-
- oStream.Write(Data.FileContents, 0, oFileObjectSize)
- oStream.Flush(True)
- oStream.Close()
- End Using
- Catch ex As Exception
- _Logger.Error(ex)
- LogAndThrow("Could not write file to disk!")
- End Try
-
- ' Insert into DB
- Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO '{oFileObjectPath}', '{oFileObjectName}', '{oFileObjectExtension}',{oFileObjectSize},{Data.FileChecksum} ,'{Data.Who}','{oObjectId}',{oStore.Id}"
- Dim oResult As Boolean = MSSQL_IDB.ExecuteNonQuery(oSQL)
-
- If oResult = False Then
- LogAndThrow("IDB FileObject could not be created!")
- End If
-
- Return New NewFile.NewFileResponse(oObjectId)
- Catch ex As FaultException
- Return New NewFile.NewFileResponse(ex)
-
- End Try
+ Dim oNewFile As New NewFileMethod(LogConfig, MSSQL_IDB, GlobalState.ObjectStores)
+ Return oNewFile.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 SetAttributeValueMethod(LogConfig, MSSQL_IDB)
+ Return oSetAttributeValue.Run(Data)
+ End Function
#Region "=== Heartbeat ==="
Public Function Heartbeat() As Boolean Implements IEDMIService.Heartbeat
@@ -544,23 +458,17 @@ Public Class EDMIService
Public Function TestObjectIdExists(Data As TestObjectIdExistsRequest) As TestObjectIdExistsResponse Implements IEDMIService.TestObjectIdExists
Try
- Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {Data.ObjectId}"
- Dim oTable As DataTable = MSSQL_IDB.GetDatatable(oSQL)
+ Dim oDeleted As Boolean = False
+ Dim oActive As Boolean = False
- If IsNothing(oTable) OrElse oTable.Rows.Count = 0 Then
- _Logger.Warn("ObjectId {0} does not exist")
+ If _IDBHelpers.TestObjectIdExists(Data.ObjectId, oDeleted, oActive) = False Then
Return New TestObjectIdExistsResponse(False)
End If
- Dim oRow As DataRow = oTable.Rows.Item(0)
- Dim oActive = Utils.NotNull(oRow.Item("ACTIVE"), False)
- Dim oDeleted = Utils.NotNull(oRow.Item("DELETED"), False)
-
Return New TestObjectIdExistsResponse(True) With {
.Deleted = oDeleted,
.Inactive = Not oActive
}
-
Catch ex As Exception
_Logger.Error(ex)
Return New TestObjectIdExistsResponse(False)
@@ -574,17 +482,10 @@ Public Class EDMIService
#End Region
#Region "=== Private ==="
- Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pFilename As String, pKeepFilename As Boolean) As String
- If pKeepFilename Then
- Return pFilename
- Else
- Return $"{IDB_OBJ_ID}.ddfo"
- End If
- End Function
- 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)
@@ -674,10 +575,7 @@ Public Class EDMIService
End If
End Function
- Private Function LogAndThrow(pMessage As String)
- _Logger.Warn(pMessage)
- Throw New ApplicationException(pMessage)
- End Function
+
#End Region
diff --git a/Service.EDMIService/EDMIService.vbproj b/Service.EDMIService/EDMIService.vbproj
index 786f0875..2526cd55 100644
--- a/Service.EDMIService/EDMIService.vbproj
+++ b/Service.EDMIService/EDMIService.vbproj
@@ -127,18 +127,24 @@
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
-
diff --git a/Service.EDMIService/Helpers/Exceptions.vb b/Service.EDMIService/Exceptions.vb
similarity index 100%
rename from Service.EDMIService/Helpers/Exceptions.vb
rename to Service.EDMIService/Exceptions.vb
diff --git a/Service.EDMIService/Filestorage/NewFile/NewFileMethod.vb b/Service.EDMIService/Filestorage/NewFile/NewFileMethod.vb
new file mode 100644
index 00000000..925449c1
--- /dev/null
+++ b/Service.EDMIService/Filestorage/NewFile/NewFileMethod.vb
@@ -0,0 +1,200 @@
+Imports System.Data.SqlClient
+Imports DigitalData.Modules.Database
+Imports DigitalData.Modules.Database.MSSQLServer.TransactionMode
+Imports DigitalData.Modules.Logging
+Imports DigitalData.Services.EDMIService.FileStorage
+Imports DigitalData.Services.EDMIService.GlobalState
+
+Public Class NewFileMethod
+ Inherits BaseMethod
+
+ Private ReadOnly ObjectStores As List(Of ObjectStore)
+ Private ReadOnly Connection As SqlConnection
+ Private ReadOnly Transaction As SqlTransaction
+
+ Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer, pObjectStores As List(Of ObjectStore))
+ MyBase.New(pLogConfig, pMSSQLServer)
+ ObjectStores = pObjectStores
+
+ Connection = Database.GetConnection()
+ Transaction = Connection.BeginTransaction()
+ End Sub
+
+ Public Function Run(pData As NewFile.NewFileRequest) As NewFile.NewFileResponse
+ Dim oConnection As SqlConnection = Nothing
+ Dim oTransaction As SqlTransaction = Nothing
+ Dim oFilePath As String = Nothing
+
+ Dim oExistingObjectId = TestFileChecksumExists(pData.FileChecksum)
+ If oExistingObjectId > 0 Then
+ Return New NewFile.NewFileResponse(oExistingObjectId)
+ End If
+
+ Try
+
+ Dim oObjectId = NewObjectId(pData.KindType, pData.BusinessEntity, pData.Who)
+ 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 = 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.FileImportedAt) Then
+ oSubDirectory = GetDateSubDirectory(Now)
+ Else
+ oSubDirectory = GetDateSubDirectory(pData.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)
+ 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.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.FileContents.Length
+ Dim oFileObjectExtension As String = oFileObjectInfo.Extension.Substring(1)
+ Dim oFileObjectName As String = oFileObjectInfo.Name
+
+ Logger.Debug("File Information for [{0}]:", oFileObjectName)
+ Logger.Debug("Size: [{0}]", oFileObjectSize)
+ Logger.Debug("Extension: [{0}]", oFileObjectExtension)
+ Logger.Debug("Checksum: [{0}]", pData.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.FileContents, 0, oFileObjectSize)
+ oStream.Flush(True)
+ oStream.Close()
+ End Using
+ Catch ex As Exception
+ Logger.Error(ex)
+ LogAndThrow($"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}', '{oFileObjectExtension}',{oFileObjectSize},'{pData.FileChecksum}' ,'{pData.Who}','{oObjectId}',{oStore.Id}"
+ Dim oResult As Boolean = Database.ExecuteNonQueryWithConnectionObject(oSQL,
+ oConnection,
+ MSSQLServer.TransactionMode.ExternalTransaction,
+ oTransaction)
+
+ If oResult = False Then
+ LogAndThrow("IDB FileObject could not be created!")
+ End If
+
+ ' Finally, commit the transaction
+ oTransaction?.Commit()
+
+ Return New NewFile.NewFileResponse(oObjectId)
+ Catch ex As Exception
+ Logger.Warn("Error occurred while importing 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.")
+ oTransaction?.Rollback()
+
+ Return New NewFile.NewFileResponse(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 = Database.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 = Database.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
+ 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
diff --git a/Service.EDMIService/Filestorage/NewFile/NewFileResponse.vb b/Service.EDMIService/Filestorage/NewFile/NewFileResponse.vb
index 20a0e28e..2302d40f 100644
--- a/Service.EDMIService/Filestorage/NewFile/NewFileResponse.vb
+++ b/Service.EDMIService/Filestorage/NewFile/NewFileResponse.vb
@@ -1,9 +1,9 @@
Imports System.Runtime.Serialization
-Namespace FileStorage.NewFile
+Namespace FileStorage.SetAttributeValue
- Public Class NewFileResponse
+ Public Class SetAttributeValueResponse
Inherits Messages.BaseResponse
@@ -14,8 +14,8 @@ Namespace FileStorage.NewFile
ObjectId = pObjectId
End Sub
- Public Sub New(pException As Exception)
- MyBase.New(pException)
+ Public Sub New(pException As Exception, Optional pDetails As String = "")
+ MyBase.New(pException, pDetails)
End Sub
End Class
diff --git a/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueMethod.vb b/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueMethod.vb
new file mode 100644
index 00000000..627c909f
--- /dev/null
+++ b/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueMethod.vb
@@ -0,0 +1,31 @@
+Imports DigitalData.Modules.Logging
+Imports DigitalData.Modules.Database
+Imports DigitalData.Services.EDMIService.IDB
+
+Namespace FileStorage.SetAttributeValue
+ Public Class SetAttributeValueMethod
+ Inherits BaseMethod
+
+ Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
+ MyBase.New(pLogConfig, pDatabase)
+ End Sub
+
+ Public Function Run(pData As SetAttributeValueRequest) As SetAttributeValueResponse
+ Try
+ If Helpers.TestObjectIdExists(pData.ObjectId) = False Then
+ LogAndThrow("ObjectId does not exist!")
+ End If
+
+ 'TODO: Finish
+
+
+ Return New SetAttributeValueResponse(pData.ObjectId)
+ Catch ex As Exception
+ Logger.Warn("Error occurred while setting attribute value!")
+
+ Return New SetAttributeValueResponse(ex)
+ End Try
+ End Function
+ End Class
+
+End Namespace
\ No newline at end of file
diff --git a/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueRequest.vb b/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueRequest.vb
new file mode 100644
index 00000000..064562c9
--- /dev/null
+++ b/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueRequest.vb
@@ -0,0 +1,23 @@
+Imports System.Runtime.Serialization
+
+Namespace FileStorage.SetAttributeValue
+
+
+ Public Class SetAttributeValueRequest
+ '''
+ ''' Object Id
+ '''
+
+ Public Property ObjectId As Long
+
+ Public Property AttributeName As String
+
+ Public Property AttributeValue As String
+
+ Public Property Who As Long
+ End Class
+
+
+End Namespace
+
+
diff --git a/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueResponse.vb b/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueResponse.vb
new file mode 100644
index 00000000..26d1e11f
--- /dev/null
+++ b/Service.EDMIService/Filestorage/SetAttributeValue/SetAttributeValueResponse.vb
@@ -0,0 +1,22 @@
+Imports System.Runtime.Serialization
+
+Namespace FileStorage.NewFile
+
+
+ Public Class NewFileResponse
+ Inherits Messages.BaseResponse
+
+
+ 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
diff --git a/Service.EDMIService/Helpers/TraceSwitch.vb b/Service.EDMIService/Helpers/TraceSwitch.vb
deleted file mode 100644
index f34db423..00000000
--- a/Service.EDMIService/Helpers/TraceSwitch.vb
+++ /dev/null
@@ -1,34 +0,0 @@
-Public Class TraceSwitch
- Inherits SourceSwitch
-
- Public Sub New(Name As String)
- MyBase.New("System.ServiceModel")
- Level = SourceLevels.Information
- WcfTracesController.Instance.LevelController = AddressOf WcfTracesLevelController
- End Sub
-
- Public Sub WcfTracesLevelController(ByVal level As SourceLevels)
- Me.Level = level
- End Sub
-End Class
-
-Public Class WcfTracesController
- Private Shared Controller As WcfTracesController = Nothing
-
- Private Sub New()
- End Sub
-
- Public Delegate Sub TraceLevelController(ByVal level As SourceLevels)
- Public LevelController As TraceLevelController
-
- Public Shared ReadOnly Property Instance As WcfTracesController
- Get
-
- If Controller Is Nothing Then
- Controller = New WcfTracesController()
- End If
-
- Return Controller
- End Get
- End Property
-End Class
diff --git a/Service.EDMIService/IDB/Helpers.vb b/Service.EDMIService/IDB/Helpers.vb
new file mode 100644
index 00000000..50d023d0
--- /dev/null
+++ b/Service.EDMIService/IDB/Helpers.vb
@@ -0,0 +1,44 @@
+Imports DigitalData.Modules.Database
+Imports DigitalData.Modules.Language
+Imports DigitalData.Modules.Logging
+Imports DigitalData.Services.EDMIService.Messages
+
+Namespace IDB
+ Public Class Helpers
+ Inherits BaseClass
+
+ Private MSSQLServer As MSSQLServer
+
+ Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
+ MyBase.New(pLogConfig)
+ MSSQLServer = pMSSQLServer
+ End Sub
+
+ 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}"
+ Dim oTable As DataTable = MSSQLServer.GetDatatable(oSQL)
+
+ If IsNothing(oTable) OrElse oTable.Rows.Count = 0 Then
+ Logger.Warn("ObjectId {0} does not exist")
+ Return False
+ End If
+
+ Dim oRow As DataRow = oTable.Rows.Item(0)
+ Dim oActive = Utils.NotNull(oRow.Item("ACTIVE"), False)
+ Dim oDeleted = Utils.NotNull(oRow.Item("DELETED"), False)
+
+ IsDeleted = oDeleted
+ IsActive = oActive
+
+ Return True
+
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+
+ End Try
+ End Function
+ End Class
+
+End Namespace
\ No newline at end of file
diff --git a/Service.EDMIService/IEDMIService.vb b/Service.EDMIService/IEDMIService.vb
index a58f8933..313c00b4 100644
--- a/Service.EDMIService/IEDMIService.vb
+++ b/Service.EDMIService/IEDMIService.vb
@@ -66,6 +66,9 @@ Interface IEDMIService
Function NewFile(Data As NewFile.NewFileRequest) As NewFile.NewFileResponse
+
+ Function SetAttributeValue(Data As SetAttributeValue.SetAttributeValueRequest) As SetAttributeValue.SetAttributeValueResponse
+
'-----------------------------------------------------
' Everything below this line is subject to change!
'-----------------------------------------------------
diff --git a/Service.EDMIService/Helpers/AccessRightResult.vb b/Service.EDMIService/Messages/AccessRightResult.vb
similarity index 100%
rename from Service.EDMIService/Helpers/AccessRightResult.vb
rename to Service.EDMIService/Messages/AccessRightResult.vb
diff --git a/Service.EDMIService/Helpers/BaseResponse.vb b/Service.EDMIService/Messages/BaseResponse.vb
similarity index 71%
rename from Service.EDMIService/Helpers/BaseResponse.vb
rename to Service.EDMIService/Messages/BaseResponse.vb
index e8b3d075..4b14fc23 100644
--- a/Service.EDMIService/Helpers/BaseResponse.vb
+++ b/Service.EDMIService/Messages/BaseResponse.vb
@@ -9,6 +9,8 @@ Namespace Messages
Public Property OK As Boolean
Public Property ErrorMessage As String
+
+ Public Property ErrorDetails As String
Public Sub New()
OK = True
@@ -23,6 +25,12 @@ Namespace Messages
OK = False
ErrorMessage = Exception.Message
End Sub
+
+ Public Sub New(Exception As Exception, Details As String)
+ OK = False
+ ErrorMessage = Exception.Message
+ ErrorDetails = Details
+ End Sub
End Class
End Namespace
diff --git a/Service.EDMIService/Helpers/DatabaseResult.vb b/Service.EDMIService/Messages/DatabaseResult.vb
similarity index 100%
rename from Service.EDMIService/Helpers/DatabaseResult.vb
rename to Service.EDMIService/Messages/DatabaseResult.vb
diff --git a/Service.EDMIService/Helpers/Messages.vb b/Service.EDMIService/Messages/Messages.vb
similarity index 100%
rename from Service.EDMIService/Helpers/Messages.vb
rename to Service.EDMIService/Messages/Messages.vb
diff --git a/Service.EDMIService/WindowsService.vb b/Service.EDMIService/WindowsService.vb
index a9cb0e65..d93a22b7 100644
--- a/Service.EDMIService/WindowsService.vb
+++ b/Service.EDMIService/WindowsService.vb
@@ -38,23 +38,9 @@ Public Class WindowsService
Try
Dim oServicePath As String = AppDomain.CurrentDomain.BaseDirectory
- _LogConfig = New LogConfig(LogConfig.PathType.CustomPath, IO.Path.Combine(oServicePath, "Log"), Nothing, Nothing, Nothing, 3)
+ _LogConfig = New LogConfig(LogConfig.PathType.CustomPath, IO.Path.Combine(oServicePath, "Log"), FileKeepRangeInDays:=3)
_Logger = _LogConfig.GetLogger()
- Try
- Dim directory As New IO.DirectoryInfo(_LogConfig.LogDirectory)
-
- For Each file As IO.FileInfo In directory.GetFiles
- If (Now - file.CreationTime).Days > 29 Then
- file.Delete()
- Else
- Exit For
- End If
- Next
- Catch ex As Exception
- _Logger.Error(ex)
- End Try
-
_Logger.Info("Service {0} is starting...", SERVICE_DISPLAY_NAME)
_Logger.Info("ServiceDirectory: {0}", oServicePath)
@@ -132,28 +118,6 @@ Public Class WindowsService
End Try
End Sub
- Private Sub UpdateTraceLogging()
- Try
- ' Changing Tracelevels programmatically,
- ' See: https://wcfpro.wordpress.com/2010/11/21/how-to-add-wcf-traces-programmatically/
- _Logger.Debug("UpdateTraceLogging running..")
- _Logger.Debug("SourceLevels is off by default")
-
- Dim oTraceLevel = SourceLevels.Off
-
- _Logger.Debug("Debug is currently set to {0}", _ConfigManager.Config.Debug)
- If _ConfigManager.Config.Debug Then
- oTraceLevel = SourceLevels.Warning
- End If
-
- _Logger.Debug("Setting TraceLevel to {0}", oTraceLevel)
- WcfTracesController.Instance.LevelController(oTraceLevel)
- Catch ex As Exception
- _Logger.Warn("TraceLogging could not be updated!")
- _Logger.Error(ex)
- End Try
- End Sub
-
Private Function StartFirebird() As Firebird
_Logger.Debug("Connecting to Firebird")