shared memory services

master
xieguigang 10 years ago
parent decc3554f5
commit 54fffef600

@ -124,6 +124,10 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="SharedMemory\Protocols.vb" />
<Compile Include="SharedMemory\SharedSvr.vb" />
<Compile Include="SharedMemory\HashValue.vb" />
<Compile Include="SharedMemory\MemoryServices.vb" />
<Compile Include="Taskhost.d\Invoke\TaskInvoke.vb" />
<Compile Include="Taskhost.d\Linq\LinqPool.vb" />
<Compile Include="Taskhost.d\Linq\ILinq%28Of T%29.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

@ -0,0 +1,87 @@
Imports Microsoft.VisualBasic.Net
Imports Microsoft.VisualBasic.Serialization
Namespace SharedMemory
''' <summary>
''' Shared the memory with the remote machine.
''' </summary>
Public Class MemoryServices : Implements IDisposable
''' <summary>
''' 使NameOf
''' </summary>
''' <param name="name"></param>
''' <returns></returns>
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
''' <summary>
''' 使
''' </summary>
ReadOnly __variables As New Dictionary(Of HashValue)
ReadOnly __remote As IPEndPoint
ReadOnly __localSvr As SharedSvr
''' <summary>
'''
''' </summary>
''' <param name="remote"></param>
''' <param name="local">local services port that provides to the remote</param>
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

@ -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

@ -0,0 +1,49 @@
Imports Microsoft.VisualBasic.Net
Namespace SharedMemory
''' <summary>
''' Memory shared services.
''' </summary>
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

@ -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
''' <summary>
''' linq
''' </summary>
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
''' <summary>
''' uidLinq PortalTostring
''' </summary>
''' <param name="uid"></param>
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
''' <summary>
'''
''' </summary>
''' <param name="source"></param>
''' <param name="type">
'''
''' 使
''' </param>
''' <returns></returns>
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
''' <summary>
''' linq
''' </summary>
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
''' <summary>
''' uidLinq PortalTostring
''' </summary>
''' <param name="uid"></param>
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
''' <summary>
'''
''' </summary>
''' <param name="source"></param>
''' <param name="type">
'''
''' 使
''' </param>
''' <returns></returns>
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
Loading…
Cancel
Save