Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
Imports Microsoft.VisualBasic.Net
Imports Microsoft.VisualBasic.Serialization
Namespace SharedMemory
'''
''' Shared the memory with the remote machine.
'''
Public Class MemoryServices : Implements IDisposable
Implements IObjectModel_Driver
'''
''' Gets the memory data from remote machine.
'''
'''
''' 建议使用NameOf来设置或者获取参数值
'''
Public Function GetValue(Of T)(name As String) As T
Return __remote.ReadValue(Of T)(name)
End Function
'''
'''
'''
'''
''' 建议使用NameOf来设置或者获取参数值
'''
'''
Public Function SetValue(Of T)(name As String, value As T) As Boolean
Return __remote.WriteValue(name, value)
End Function
Public Function [TypeOf](name As String) As Type
Return __remote.TypeOf(name)
End Function
Public Function IsCompatible(Of T)(name As String, x As T) As Boolean
Dim type As Type = [TypeOf](name)
Dim ref As Type = GetType(T)
Return type.Equals(ref) OrElse ref.IsInheritsFrom(type)
End Function
ReadOnly __remote As IPEndPoint
ReadOnly __localSvr As SharedSvr
'''
'''
'''
'''
''' local services port that provides to the remote
Sub New(remote As IPEndPoint, local As Integer)
__remote = remote
__localSvr = New SharedSvr(local)
End Sub
Public Function Allocate(name As String, value As Object, Optional [overrides] As Boolean = False) As Boolean
Return __localSvr.Allocate(name, value, [overrides])
End Function
Public Overrides Function ToString() As String
Return __remote.GetJson
End Function
Public Function Run() As Integer Implements IObjectModel_Driver.Run
Return __localSvr.Run
End Function
#Region "IDisposable Support"
Private disposedValue As Boolean ' To detect redundant calls
' IDisposable
Protected Overridable Sub Dispose(disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: dispose managed state (managed objects).
Call __localSvr.Dispose()
End If
' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
' TODO: set large fields to null.
End If
Me.disposedValue = True
End Sub
' TODO: override Finalize() only if Dispose(disposing As Boolean) above has code to free unmanaged resources.
'Protected Overrides Sub Finalize()
' ' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above.
' Dispose(False)
' MyBase.Finalize()
'End Sub
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above.
Dispose(True)
' TODO: uncomment the following line if Finalize() is overridden above.
' GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
End Namespace