update service and api

This commit is contained in:
Jonathan Jenne
2020-02-04 15:42:12 +01:00
parent 265c08d5d5
commit c66a2dc5e5
21 changed files with 622 additions and 396 deletions

View File

@@ -1,26 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<sources>
<source propagateActivity="true" name="System.ServiceModel" switchValue="Warning, ActivityTracing">
<source name="System.ServiceModel" switchValue="Information,ActivityTracing"
propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="E:\EDMService\Trace.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="Xml" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack">
<filter type="" />
</add>
<add initializeData="C:\logs\TracingAndLogging-service.svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="xml" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
@@ -34,12 +30,20 @@
</appSettings>
<system.serviceModel>
<diagnostics wmiProviderEnabled="true">
<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtTransportLevel="true" />
<endToEndTracing propagateActivity="true" activityTracing="true"
messageFlowTracing="true" />
</diagnostics>
<bindings>
<netTcpBinding>
<binding name="tcpBinding" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="32" maxNameTableCharCount="2147483647" />
<binding name="tcpBinding" sendTimeout="00:10:00" transferMode="Buffered"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>

View File

@@ -1,9 +1,9 @@
Imports System.ServiceModel
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports System.IO
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Services.IDBService
Imports System.IO
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)>
Public Class IDBService
@@ -31,17 +31,16 @@ Public Class IDBService
#Region "Auth"
Private Function TestUserAuth() As Boolean
Try
Dim oSQL As String = $"SELECT FNIDB_AUTH_USER('{_username}') FROM RDB$DATABASE;"
Dim oResult As Boolean = Database.GetScalarValue(oSQL)
Return oResult
'Dim oSQL As String = $"SELECT FNIDB_AUTH_USER('{_username}') FROM RDB$DATABASE;"
'Dim oResult As Boolean = Database.GetScalarValue(oSQL)
'Return oResult
Return True
Catch ex As Exception
_logger.Error(ex)
Return False
End Try
End Function
#End Region
#Region "Heartbeat"
Public Function Heartbeat() As Boolean Implements IIDBService.Heartbeat
Return True
@@ -129,7 +128,7 @@ Public Class IDBService
#End Region
#Region "Document"
#Region "Document (with FileContainer)"
Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResult Implements IIDBService.NewFile
Try
Dim oContainer As FileContainer
@@ -237,6 +236,35 @@ Public Class IDBService
End Sub
#End Region
#Region "Document"
Public Function ImportFile(FileInfo As FileInfo, Contents() As Byte) As DocumentResult2 Implements IIDBService.ImportFile
Dim oFilePath = Path.Combine(AppConfig.ContainerPath, FileInfo.Name)
Dim oDocument = New DocumentResult2.DocumentObject() With {.FileName = FileInfo.Name}
Try
_logger.Info("Saving file [{0}] to path [{1}]", FileInfo.Name, oFilePath)
Using oStream = New FileStream(oFilePath, FileMode.CreateNew)
oStream.Write(Contents, 0, Contents.Length)
oStream.Flush(True)
oStream.Close()
End Using
Dim oAttributes = IO.File.GetAttributes(oFilePath) Or FileAttributes.ReadOnly
_logger.Info("Setting LastAccessTime")
IO.File.SetLastAccessTime(oFilePath, Date.Now.AddYears(30))
_logger.Info("Setting ReadOnly Attribute")
IO.File.SetAttributes(oFilePath, oAttributes)
Return New DocumentResult2(oDocument)
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResult2(ex.Message)
End Try
End Function
#End Region
#Region "Utils"
Public Function GetDocumentByDocumentId(DocumentId As Long) As DocumentResult Implements IIDBService.GetDocumentByDocumentId
Try

View File

@@ -90,6 +90,7 @@
<Compile Include="Exceptions.vb" />
<Compile Include="Results\DatabaseResult.vb" />
<Compile Include="IDBService.vb" />
<Compile Include="Results\DocumentResult2.vb" />
<Compile Include="Results\IndexResult.vb" />
<Compile Include="WindowsService.vb">
<SubType>Component</SubType>

View File

@@ -1,4 +1,5 @@
Imports System.ServiceModel
Imports System.IO
Imports System.ServiceModel
Imports DigitalData.Modules.Filesystem
<ServiceContract([Namespace]:="http://DigitalData.Services.IDBService")>
@@ -26,7 +27,7 @@ Interface IIDBService
Function ExecuteNonQuery(SQL As String) As NonQueryResult
#End Region
#Region "Document"
#Region "Document (with FileContainer)"
<OperationContract>
Function NewFile(FileName As String, Contents As Byte()) As DocumentResult
@@ -38,8 +39,11 @@ Interface IIDBService
<OperationContract>
Function DeleteFile(DocObject As DocumentObject) As Boolean
#End Region
#Region "Document (New)"
<OperationContract>
Function ImportFile(FileInfo As FileInfo, Contents As Byte()) As DocumentResult2
#End Region
#Region "Utils"

View File

@@ -0,0 +1,28 @@
<Serializable>
Public Class DocumentResult2
Inherits BaseResult
Public Document As DocumentObject
Public HasContents As Boolean = False
Public Contents As Byte()
Public Sub New(Document As DocumentObject)
MyBase.New()
Me.Document = Document
End Sub
Public Sub New(Document As DocumentObject, Contents As Byte())
MyBase.New()
Me.Document = Document
Me.Contents = Contents
Me.HasContents = True
End Sub
Public Sub New(ErrorMessage As String)
MyBase.New(ErrorMessage)
End Sub
Public Class DocumentObject
Public FileName As String
End Class
End Class