diff --git a/ComputingServices/ComputingServices/ComputingServices.vbproj b/ComputingServices/ComputingServices/ComputingServices.vbproj index acc4052..a3ce14a 100644 --- a/ComputingServices/ComputingServices/ComputingServices.vbproj +++ b/ComputingServices/ComputingServices/ComputingServices.vbproj @@ -124,6 +124,10 @@ Settings.settings True + + + + diff --git a/ComputingServices/ComputingServices/SharedMemory/HashValue.vb b/ComputingServices/ComputingServices/SharedMemory/HashValue.vb new file mode 100644 index 0000000..1da4e69 --- /dev/null +++ b/ComputingServices/ComputingServices/SharedMemory/HashValue.vb @@ -0,0 +1,23 @@ +Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic +Imports Microsoft.VisualBasic.Scripting.MetaData +Imports Microsoft.VisualBasic.Serialization + +Namespace SharedMemory + + Public Class HashValue : Implements sIdEnumerable + + Public Property Identifier As String Implements sIdEnumerable.Identifier + Public Property value As Object + Public Property Type As TypeInfo + + Sub New(name As String, x As Object) + Identifier = name + value = x + Type = New TypeInfo(x.GetType) + End Sub + + Public Overrides Function ToString() As String + Return $"Dim {Identifier} As {Type.ToString} = {JsonContract.GetJson(value, Type.GetType)}" + End Function + End Class +End Namespace \ No newline at end of file diff --git a/ComputingServices/ComputingServices/SharedMemory/MemoryServices.vb b/ComputingServices/ComputingServices/SharedMemory/MemoryServices.vb new file mode 100644 index 0000000..00bc358 --- /dev/null +++ b/ComputingServices/ComputingServices/SharedMemory/MemoryServices.vb @@ -0,0 +1,87 @@ +Imports Microsoft.VisualBasic.Net +Imports Microsoft.VisualBasic.Serialization + +Namespace SharedMemory + + ''' + ''' Shared the memory with the remote machine. + ''' + Public Class MemoryServices : Implements IDisposable + + ''' + ''' 建议使用NameOf来设置或者获取参数值 + ''' + ''' + ''' + Default Public Property value(name As String) As Object + Get ' Gets the memory data from remote machine. + + End Get + Set(value As Object) + + End Set + End Property + + ''' + ''' 这个是提供给远程主机读取使用的 + ''' + ReadOnly __variables As New Dictionary(Of HashValue) + 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 + If __variables.ContainsKey(name) Then + Else + __variables.Add(name, New HashValue(name, value)) + End If + End Function + + Public Overrides Function ToString() As String + Return __remote.GetJson + 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() + Call __variables.Clear() + 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 \ No newline at end of file diff --git a/ComputingServices/ComputingServices/SharedMemory/Protocols.vb b/ComputingServices/ComputingServices/SharedMemory/Protocols.vb new file mode 100644 index 0000000..660f8c5 --- /dev/null +++ b/ComputingServices/ComputingServices/SharedMemory/Protocols.vb @@ -0,0 +1,20 @@ +Imports Microsoft.VisualBasic.Net.Protocols + +Namespace SharedMemory + + Module Protocols + + Public Enum MemoryProtocols + Read + Write + End Enum + + Public Function ReadValue(name As String) As RequestStream + + End Function + + Public Function WriteValue(name As String, value As Object) As RequestStream + + End Function + End Module +End Namespace \ No newline at end of file diff --git a/ComputingServices/ComputingServices/SharedMemory/SharedSvr.vb b/ComputingServices/ComputingServices/SharedMemory/SharedSvr.vb new file mode 100644 index 0000000..4c5f0cd --- /dev/null +++ b/ComputingServices/ComputingServices/SharedMemory/SharedSvr.vb @@ -0,0 +1,49 @@ +Imports Microsoft.VisualBasic.Net + +Namespace SharedMemory + + ''' + ''' Memory shared services. + ''' + Public Class SharedSvr : Implements IDisposable + + ReadOnly __localSvr As TcpSynchronizationServicesSocket + + Sub New(local As Integer) + __localSvr = New TcpSynchronizationServicesSocket(local) + End Sub + +#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). + __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 \ No newline at end of file diff --git a/ComputingServices/ComputingServices/Taskhost.d/Linq/LinqPool.vb b/ComputingServices/ComputingServices/Taskhost.d/Linq/LinqPool.vb index d0069eb..f73e0d8 100644 --- a/ComputingServices/ComputingServices/Taskhost.d/Linq/LinqPool.vb +++ b/ComputingServices/ComputingServices/Taskhost.d/Linq/LinqPool.vb @@ -1,117 +1,117 @@ -Imports System.Threading -Imports Microsoft.VisualBasic.Net +Imports System.Threading +Imports Microsoft.VisualBasic.Net Imports Microsoft.VisualBasic.Parallel.Tasks -Namespace TaskHost - - Public Class LinqPool : Implements IDisposable - - ''' - ''' linq池 - ''' - ReadOnly __linq As New Dictionary(Of String, LinqProvider) - ReadOnly __openQuerys As New TaskQueue(Of IPEndPoint) - - Public Function GetLinq(uid As String) As LinqProvider - Return __linq(uid) - End Function - - ''' - ''' uid参数是Linq Portal的Tostring函数的结果 - ''' - ''' - Public Sub Free(uid As String) - If Not __linq.ContainsKey(uid) Then Return - - Dim x As LinqProvider = __linq(uid) - Call x.Free ' 释放Linq数据源的指针 - - SyncLock __linq - Call __linq.Remove(uid) ' 从哈希表之中移除数据源释放服务器资源 - End SyncLock - End Sub - - ''' - ''' - ''' - ''' - ''' - ''' 这里应该是集合的类型,函数会自动从这个类型信息之中得到元素的类型; - ''' 假若函数获取得到集合之中的元素的类型失败的话,则会直接使用所传入的类型参数作为集合之中的元素类型 - ''' - ''' - Public Function OpenQuery(source As IEnumerable, type As Type) As IPEndPoint - Dim elType As Type = type.GetTypeElement(True) - If elType Is Nothing Then - elType = type - End If - - Dim task As New __openTask(__linq) With { - .elType = elType, - .source = source - } - Return __openQuerys.Join(AddressOf task.OpenQuery) - End Function - - Private Class __openTask - - ReadOnly __linq As Dictionary(Of String, LinqProvider) - - Public source As IEnumerable - Public elType As Type - - Sub New(ByRef linq As Dictionary(Of String, LinqProvider)) - __linq = linq - End Sub - - Public Function OpenQuery() As IPEndPoint - Dim linq As New LinqProvider(source, elType) ' 创建 Linq 数据源 - Dim portal As IPEndPoint = linq.Portal - Dim uid As String = portal.ToString - - Call __linq.Add(portal.ToString, linq) ' 数据源添加入哈希表之中 - - Return portal - End Function +Namespace TaskHost + + Public Class LinqPool : Implements IDisposable + + ''' + ''' linq池 + ''' + ReadOnly __linq As New Dictionary(Of String, LinqProvider) + ReadOnly __openQuerys As New TaskQueue(Of IPEndPoint) + + Public Function GetLinq(uid As String) As LinqProvider + Return __linq(uid) + End Function + + ''' + ''' uid参数是Linq Portal的Tostring函数的结果 + ''' + ''' + Public Sub Free(uid As String) + If Not __linq.ContainsKey(uid) Then Return + + Dim x As LinqProvider = __linq(uid) + Call x.Free ' 释放Linq数据源的指针 + + SyncLock __linq + Call __linq.Remove(uid) ' 从哈希表之中移除数据源释放服务器资源 + End SyncLock + End Sub + + ''' + ''' + ''' + ''' + ''' + ''' 这里应该是集合的类型,函数会自动从这个类型信息之中得到元素的类型; + ''' 假若函数获取得到集合之中的元素的类型失败的话,则会直接使用所传入的类型参数作为集合之中的元素类型 + ''' + ''' + Public Function OpenQuery(source As IEnumerable, type As Type) As IPEndPoint + Dim elType As Type = type.GetTypeElement(True) + If elType Is Nothing Then + elType = type + End If + + Dim task As New __openTask(__linq) With { + .elType = elType, + .source = source + } + Return __openQuerys.Join(AddressOf task.OpenQuery) + End Function + + Private Class __openTask + + ReadOnly __linq As Dictionary(Of String, LinqProvider) + + Public source As IEnumerable + Public elType As Type + + Sub New(ByRef linq As Dictionary(Of String, LinqProvider)) + __linq = linq + End Sub + + Public Function OpenQuery() As IPEndPoint + Dim linq As New LinqProvider(source, elType) ' 创建 Linq 数据源 + Dim portal As IPEndPoint = linq.Portal + Dim uid As String = portal.ToString + + Call __linq.Add(portal.ToString, linq) ' 数据源添加入哈希表之中 + + Return portal + End Function End Class -#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). - - For Each x In __linq - Call Free(x.Key) - Next - - Call __linq.Free - 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) +#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). + + For Each x In __linq + Call Free(x.Key) + Next + + Call __linq.Free + 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 Region - End Class + End Class End Namespace \ No newline at end of file