473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

handling events raised in custom providers

I am making use of the Provider model to create custom logic providers for an
in house winform application.

I have my own provider consumer that is responsible for loading the proper
provider and delegating the methods back to the provider. The provider
consumer also handles events raised from the provider.

The problem that I'm having is the events are not being established properly
within the providers to the provider consumer..

The event in question is a simple "message" back to the provider consumer,
which the provider consumer then bubbles back to it's calling object using
the same event handler that it uses to bubble up it's own messages.

Attached sample code...

In my ProviderConsume r class:

public event MessageHandlerD elegate ErrorMessage;

private void ErrorMessageHan dler(string msg)
{
if (this.ErrorMess age != null)
{
ErrorMessage(ms g);
}
else
{
throw new Exception(msg);
}
}

private void LoadProviders()
{
if (dataProvider == null)
{
lock (thisLock)
{
if (dataProvider == null)
{
try
{
DataSynchProvid erConfiguration section =
(DataSynchProvi derConfiguratio n)System.Config uration.Configu rationManager.G etSection("Data Providers");
dataProviders = new DataProviderBas eCollection();

System.Web.Conf iguration.Provi dersHelper.Inst antiateProvider s(section.Provi ders, dataProviders, typeof(DataSync h.ProviderBases .DataProviderBa se));
dataProvider =
dataProviders[this.loadingPro vider];
if (dataProvider == null)
{
//throw new
System.Configur ation.Provider. ProviderExcepti on("Unable to load the specified
provider");
ErrorMessageHan dler("Unable to load
specified provider: " + this.loadingPro vider);
}
else
{
dataProvider.Er rorMessage += new
MessageHandlerD elegate(this.Er rorMessageHandl er);
dataProvider.Re portMessage += new
MessageHandlerD elegate(this.Re portMessageHand ler);

ReportMessageHa ndler("DataProv ider " +
this.loadingPro vider + " Loaded Successfully");
}
}
catch (Exception ex)
{
#if DEBUG
System.Windows. Forms.MessageBo x.Show("Message " +
Environment.New Line + "-------" + Environment.New Line + ex.Message +
Environment.New Line + Environment.New Line + "InnerException " +
Environment.New Line + "--------------" + Environment.New Line +
ex.InnerExcepti on, "DataSynch::Dat aProviderConsum er::LoadProvide rs()");
#else
throw new
System.Configur ation.Provider. ProviderExcepti on(ex.Message,
ex.InnerExcepti on);
#endif
}
}
}
}
}

As you can see, in the LoadProviders method, once the provider is loaded,
its events are added the consumers message handler..

In the Prover class:

public event MessageHandlerD elegate ErrorMessage;

private void ErrorMessageHan dler(string msg)
{
// raise message if possible, otherwise, eat it..
if (ErrorMessage != null)
{
ErrorMessage(ms g);
}
}

public override bool ConnectDB()
{
if (this.dbConn.St ate == ConnectionState .Open)
{
return true;
}
else
{
if (this.connectio nString.Length == 0)
{
ErrorMessageHan dler("Connectio n String can not be empty");
return false;
}
else
{
[ ... snip ... ]

Now, when the error event happens in the provider, it goes to the
errormessagehan dler and the errormessage event is null, even though it is set
in the LoadProviders() method in the consumer.

What, if anything am I doing wrong?
Jul 13 '06 #1
0 1175

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2538
by: C# Learner | last post by:
Some time ago, I remember reading a discussion about the strengths and weaknesses of exception handling. One of the weaknesses that was put forward was that exception handling is inefficient (in the way of CPU usage), compared to the "normal" practise returning values. How true is this? Will using using exception handling, in general, be much less efficient than returning values, or less efficient at all? Just curious...
5
390
by: Bevo | last post by:
In my enterprise application I'd like my DataAccess layer to be responsible for handling all database error situations and to basically throw custom exceptions according to whether db connection is ok or not, that is, cDBDownException if ok or cDBException if not ok. These two exceptions would provide all information about the original cause etc. 1. Is this a wise exception handling policy? 2. We use both Oracle and SQL Server. Which...
0
1640
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control is defined within an aspx page <MyTag:MyControl id="MyControl1" runat="server">: MyControl handle succesfully events raised from its children. When I try to create dynamically MyControl and to Add it to another control, event handling doesn't work...
5
2557
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called "Enlighten.LinkMad.Businesslogic". In one of my frontend websites I use this type to authenticate a user who is trying to login. The following excerpt is from the web.config of the particular site showing the reference to the custom provider, allowing .Net to do...
12
2807
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown when menu items are clicked.Besides these i would like to put a custom status bar. Any error message encountered in any of the webpage will be displayed in the banner. The problem iam encountering is how to access the customer status bar in child...
4
5297
by: Ty Salistean | last post by:
So, here is a wierd question that we have been discussing for a bit now. Does an event fire even though nothing is subscribed to listen to the event? For instance, does the Click event of a button fire even though nothing is subscribed to listen to the event. The answer is NO in a traditional Publisher/Subscriber design pattern (at least I think it is). I have stated that if nothing is subscribed, then the event never gets
1
1544
by: Fred Chateau | last post by:
Can exceptions only be handled in a protected block? For example, can I globally catch and handle any exception generated from an ASP.NET page without placing the entire Page_Load event handler code in a try-catch block? -- Regards, Fred Chateau
1
2068
by: Ryan | last post by:
I am trying to log events to SQL Server instead of the computers event log, but, although I get no errors, I have no luck. The webevents_events table is empty. I have a custom event that I am raising (passwordchange), and can see it beign raised successfully...just it seems to go nowhere. I have run aspnet_regsql to setup the database to handle event recording. I am fairly sure I am missing something in my web.config file. (I would...
0
1545
by: Cramer | last post by:
Using ASP.NET 3.5: Can a custom HTTP Module be used to register for the Application_Start event? Or _must_ I use Global.asax to work with Application.Start? I understand that I can use a custom HTTP Module to register for other pipeline events (like Application.BeginRequest), but I was told that the only place that I can set up an event handler for Application.Start is in Global.asax. My preference would be to register an HTTP Module...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9957
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.