Posted By: raptor3676 | Dec 30th, 2008 @ 2:31 PM
page 1 of 1
Comments: 1 | Views: 594
Hi,

I've developed a series of  middleware tools to assist in the communication of two management system.  The steps are always the same but depending on the kind of communication there is a little preprocessing of the message.  So I set up a event driven class, so whoever uses the class just has to add an event handler and is good to go.  The events has a signature like this.

Message PreprocessMessage(Message incoming);

But when I pass the libraries thru FxCop, it complained that .Net events should go like this:

void EventHandler(object sender, EventArgs args);

so if I'm not suppossed to use events in such way what is the proper design pattern for it?


Also FxCop complains that I'm catching generic exceptions (yes my bad, I catch the Exception class).  But this is not the regular user friendly programs this ones work as Windows services and the message passing task is critical, so the rationale behind this is: in case of any error, catch it, log it and move on 'cause we can't afford to stop everything just out of one error.  I don't think I have to catch every single kind of exception just to please FxCop, or what is the rigth pattern for this, given that it is supposed to work 24x7.
blowdart
blowdart
Peek-a-boo
OK so .NET does its events in it's own way; patterns are more a way of thinking rather than a "You must implement like this".  Event Handlers are the way to go. You could implement it as an observer, but really why, when events are richer? MSDN has a good article on this

And in your scenario you might get away with catching Exception - if you have no recovery. You can exclude lines from FXCop/Static Code Analysis in VS for that one method; so for example in one of my bits of code

        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Design",
            "CA1031:DoNotCatchGeneralExceptionTypes",
            Justification = "It's simply more secure to be graceful by catching all exceptions on a deserialisation problem.")]
        private static void PreRequestHandlerExecute(object source, EventArgs eventArgs)

Note the justification parameter; use it Smiley
page 1 of 1
Comments: 1 | Views: 594
Microsoft Communities