PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework How to invoke methods from a SyncProcessMessage?

Reply

How to invoke methods from a SyncProcessMessage?

 
Thread Tools Rate Thread
Old 04-04-2006, 06:42 PM   #1
=?Utf-8?B?TWFydGluUGFyw6k=?=
Guest
 
Posts: n/a
Default How to invoke methods from a SyncProcessMessage?


Hi,
I am working on a project and I ran into a little nag! I am writting a
set of custom attributes ,
[PreProcess(Type, aMethod)]
and [PostProcess(Type, aMethod)].
The goal here is to put these attributes on methods so that before the
method is executed the [PreProcess] method is executed and once the method
is
completed the [PostProcess] is executed.

public class JustSomeClass : ContextBoundObject
{
[PreProcess( typeof(AnotherClass), "PreCondition" )
[PostProcess( typeof(AnotherClass), "PostCondition" )
public void SomeMethod()
{
}
}

That would turn out that when JustSomeClass.SomeMethod() is called, we would
call AnotherClass.PreCondition and once completed we would call
AnotherClass.PostCondition.

I have managed to get this to work, here is waht my sink looks like:

public IMessage SyncProcessMessage( IMessage msg )
{
IMessage returnMessage = null;

// Process the Pre-Condition on the method
PreProcess( msg );

// Execute the method
returnMessage = _nextSink.SyncProcessMessage( msg );

// Process the Post-Condition on the method
returnMessage = PostProcess( returnMessage );

return returnMessage;
}


But I have some nagging little issues to resolve.
#1 - If my Pre-Condition also has [PreProcess()] and [PostProcess()], they
are not called. Seems like my sink is ignored. The same goes for my
PostCondition.
#2 - If my PreCondition sets uses CallContext.SetData() to set store some
data in the logical thread, it gets lost: meaning when I try to retrieve it
I
get a null. This will only happen if the object that I try to set derives
from ILogicalThreadAffinative .


I think that both issues come from the way that I call the PreProcess and
PostProcess. When I need to call PreProcess I create an instance of the
object like so:
Object classObject = Activator.CreateInstance( ClassType );
then I call the method
m_classType.InvokeMember( m_methodName,
BindingFlags.Default |
BindingFlags.InvokeMethod,
null,
classObject,
null );

Since all PreProcess and PostProcess ahve the same signature, this is easy.


Finally my question:
How can I call my PreProcess and PostProcess method in order to get their
own PreProcess and POstProcess attributes evaluated? I see a lot of
documentation about processing messages, but I don't understand how I could
invoke these methods using messages.

Thank you!

--
Lancelot@community.nospam
Martin Paré :-)

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off