Author:水如烟
指示框的实现:
MessageFormAttribute.vb
MessageFormProperty.vb
MessageFormSink.vb
MessageFormAppendAttribute.vb
MessageFormCenter.vb
指示框的实现:
MessageFormAttribute.vb
Namespace uRemoting.MethodWatcher
<AttributeUsage(AttributeTargets.Class)> _
Public Class MessageFormAttribute
Inherits MethodWatcherBaseAttribute
Protected Overrides Function GetMethodWatcherProperty() As MethodWatcherBaseProperty
Return New MessageFormProperty
End Function
End Class
End Namespace
<AttributeUsage(AttributeTargets.Class)> _
Public Class MessageFormAttribute
Inherits MethodWatcherBaseAttribute
Protected Overrides Function GetMethodWatcherProperty() As MethodWatcherBaseProperty
Return New MessageFormProperty
End Function
End Class
End Namespace
MessageFormProperty.vb
Namespace uRemoting.MethodWatcher
Public Class MessageFormProperty
Inherits MethodWatcherBaseProperty
Protected Overrides Function CreateSink(ByVal nextSink As System.Runtime.Remoting.Messaging.IMessageSink) As System.Runtime.Remoting.Messaging.IMessageSink
Return New MessageFormSink(nextSink)
End Function
End Class
End Namespace
Public Class MessageFormProperty
Inherits MethodWatcherBaseProperty
Protected Overrides Function CreateSink(ByVal nextSink As System.Runtime.Remoting.Messaging.IMessageSink) As System.Runtime.Remoting.Messaging.IMessageSink
Return New MessageFormSink(nextSink)
End Function
End Class
End Namespace
MessageFormSink.vb
Imports System.Runtime.Remoting.Messaging
Namespace uRemoting.MethodWatcher
Public Class MessageFormSink
Inherits MethodWatcherBaseSink
Sub New(ByVal nextSink As IMessageSink)
MyBase.New(nextSink)
End Sub
Protected Overrides Sub After_MethodCall(ByVal replyMsg As System.Runtime.Remoting.Messaging.IMethodReturnMessage, ByVal MethodAppendType As System.Type)
If replyMsg Is Nothing Then
Return
End If
MessageFormCenter.Close(replyMsg, MethodAppendType)
MyBase.After_MethodCall(replyMsg, MethodAppendType)
End Sub
Protected Overrides Sub Before_MethodCall(ByVal callMsg As System.Runtime.Remoting.Messaging.IMethodCallMessage, ByVal MethodAppendType As System.Type)
If callMsg Is Nothing Then
Return
End If
MessageFormCenter.ShowForm(callMsg, MethodAppendType)
MyBase.Before_MethodCall(callMsg, MethodAppendType)
End Sub
Protected Overrides ReadOnly Property MethodWatcherAppendAttributeType() As System.Type
Get
Return GetType(MessageFormAppendAttribute)
End Get
End Property
End Class
End Namespace
Namespace uRemoting.MethodWatcher
Public Class MessageFormSink
Inherits MethodWatcherBaseSink
Sub New(ByVal nextSink As IMessageSink)
MyBase.New(nextSink)
End Sub
Protected Overrides Sub After_MethodCall(ByVal replyMsg As System.Runtime.Remoting.Messaging.IMethodReturnMessage, ByVal MethodAppendType As System.Type)
If replyMsg Is Nothing Then
Return
End If
MessageFormCenter.Close(replyMsg, MethodAppendType)
MyBase.After_MethodCall(replyMsg, MethodAppendType)
End Sub
Protected Overrides Sub Before_MethodCall(ByVal callMsg As System.Runtime.Remoting.Messaging.IMethodCallMessage, ByVal MethodAppendType As System.Type)
If callMsg Is Nothing Then
Return
End If
MessageFormCenter.ShowForm(callMsg, MethodAppendType)
MyBase.Before_MethodCall(callMsg, MethodAppendType)
End Sub
Protected Overrides ReadOnly Property MethodWatcherAppendAttributeType() As System.Type
Get
Return GetType(MessageFormAppendAttribute)
End Get
End Property
End Class
End Namespace
MessageFormAppendAttribute.vb
Namespace uRemoting.MethodWatcher
<AttributeUsage(AttributeTargets.Class, allowmultiple:=True)> _
Public NotInheritable Class MessageFormAppendAttribute
Inherits MethodWatcherAppendBaseAttribute
Private gMessage As String = "处理中"
Private gTitle As String = "请稍候"
Private gFormType As ApplicationBase.MessageFormType = ApplicationBase.MessageFormType.Message
Sub New(ByVal methodName As String)
MyBase.New(methodName)
End Sub
Public Property Message() As String
Get
Return gMessage
End Get
Set(ByVal value As String)
gMessage = value
End Set
End Property
Public Property Title() As String
Get
Return gTitle
End Get
Set(ByVal value As String)
gTitle = value
End Set
End Property
Public Property FormType() As ApplicationBase.MessageFormType
Get
Return gFormType
End Get
Set(ByVal value As ApplicationBase.MessageFormType)
gFormType = value
End Set
End Property
End Class
End Namespace
<AttributeUsage(AttributeTargets.Class, allowmultiple:=True)> _
Public NotInheritable Class MessageFormAppendAttribute
Inherits MethodWatcherAppendBaseAttribute
Private gMessage As String = "处理中"
Private gTitle As String = "请稍候"
Private gFormType As ApplicationBase.MessageFormType = ApplicationBase.MessageFormType.Message
Sub New(ByVal methodName As String)
MyBase.New(methodName)
End Sub
Public Property Message() As String
Get
Return gMessage
End Get
Set(ByVal value As String)
gMessage = value
End Set
End Property
Public Property Title() As String
Get
Return gTitle
End Get
Set(ByVal value As String)
gTitle = value
End Set
End Property
Public Property FormType() As ApplicationBase.MessageFormType
Get
Return gFormType
End Get
Set(ByVal value As ApplicationBase.MessageFormType)
gFormType = value
End Set
End Property
End Class
End Namespace
MessageFormCenter.vb
Imports System.Runtime.Remoting.Messaging
Namespace uRemoting.MethodWatcher
Public Class MessageFormCenter
Private Shared gWaitingFormCollection As New Dictionary(Of String, ApplicationBase.WaitingForm)
Private Sub New()
End Sub
Public Shared Sub ShowForm(ByVal callMsg As IMethodCallMessage, ByVal MethodAppendType As System.Type)
NowMethodName = MethodWatcherCommon.GetFullMethodName(callMsg, MethodAppendType)
IsClose.Add(NowMethodName, False)
Dim td As New Threading.Thread(New Threading.ThreadStart(AddressOf Show))
td.Start()
End Sub
Public Shared Sub Close(ByVal replyMsg As IMethodReturnMessage, ByVal MethodAppendType As System.Type)
NowMethodName = MethodWatcherCommon.GetFullMethodName(replyMsg, MethodAppendType)
IsClose(MethodWatcherCommon.GetFullMethodName(replyMsg, GetType(MessageFormAppendAttribute))) = True
While IsClose.ContainsKey(NowMethodName)
Windows.Forms.Application.DoEvents()
End While
gWaitingFormCollection.Remove(MethodWatcherCommon.GetFullMethodName(replyMsg, MethodAppendType))
End Sub
Private Shared Function WaitingForm(ByVal methodName As String) As ApplicationBase.WaitingForm
If Not gWaitingFormCollection.ContainsKey(methodName) Then
Dim a As MessageFormAppendAttribute = CType(MethodCollection.DefaultInstance(methodName), MessageFormAppendAttribute)
Dim f As New ApplicationBase.WaitingForm(a.FormType)
With f
.ReceiveMessage(a.Title, True)
.ReceiveMessage(a.Message)
End With
gWaitingFormCollection.Add(methodName, f)
End If
Return gWaitingFormCollection(methodName)
End Function
Private Shared IsClose As New Dictionary(Of String, Boolean)
Private Shared NowMethodName As String
Private Shared Sub Show()
WaitingForm(NowMethodName).Show()
Do While Not IsClose(NowMethodName)
Windows.Forms.Application.DoEvents()
Loop
IsClose.Remove(NowMethodName)
End Sub
End Class
End Namespace
Namespace uRemoting.MethodWatcher
Public Class MessageFormCenter
Private Shared gWaitingFormCollection As New Dictionary(Of String, ApplicationBase.WaitingForm)
Private Sub New()
End Sub
Public Shared Sub ShowForm(ByVal callMsg As IMethodCallMessage, ByVal MethodAppendType As System.Type)
NowMethodName = MethodWatcherCommon.GetFullMethodName(callMsg, MethodAppendType)
IsClose.Add(NowMethodName, False)
Dim td As New Threading.Thread(New Threading.ThreadStart(AddressOf Show))
td.Start()
End Sub
Public Shared Sub Close(ByVal replyMsg As IMethodReturnMessage, ByVal MethodAppendType As System.Type)
NowMethodName = MethodWatcherCommon.GetFullMethodName(replyMsg, MethodAppendType)
IsClose(MethodWatcherCommon.GetFullMethodName(replyMsg, GetType(MessageFormAppendAttribute))) = True
While IsClose.ContainsKey(NowMethodName)
Windows.Forms.Application.DoEvents()
End While
gWaitingFormCollection.Remove(MethodWatcherCommon.GetFullMethodName(replyMsg, MethodAppendType))
End Sub
Private Shared Function WaitingForm(ByVal methodName As String) As ApplicationBase.WaitingForm
If Not gWaitingFormCollection.ContainsKey(methodName) Then
Dim a As MessageFormAppendAttribute = CType(MethodCollection.DefaultInstance(methodName), MessageFormAppendAttribute)
Dim f As New ApplicationBase.WaitingForm(a.FormType)
With f
.ReceiveMessage(a.Title, True)
.ReceiveMessage(a.Message)
End With
gWaitingFormCollection.Add(methodName, f)
End If
Return gWaitingFormCollection(methodName)
End Function
Private Shared IsClose As New Dictionary(Of String, Boolean)
Private Shared NowMethodName As String
Private Shared Sub Show()
WaitingForm(NowMethodName).Show()
Do While Not IsClose(NowMethodName)
Windows.Forms.Application.DoEvents()
Loop
IsClose.Remove(NowMethodName)
End Sub
End Class
End Namespace