473,657 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check where library is called from

I have an class library, which I shared with some of my apps.
Some of them are Winfroms apps, others are ASP .NET.
How could I check from a method in my library, is it called form an
Winforms or ASP .NET?

tnx

Nov 21 '05 #1
4 1265
You could use reflection to walk the stack and see who called you, but... If
you have a routine that wants to behave differently based on who calls it,
you would really be better off providing an argument to that routine to
specify the desired behavior explicitly. Along the same lines, you could
give the class a parameterized constructor that lets the instance know
whether it has been instantiated by WinForms or ASP.NET; store that info in
a class variable, and let the instance methods use that info as they see
fit.

"Nikolay Petrov" <jo******@mail. bg> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
I have an class library, which I shared with some of my apps.
Some of them are Winfroms apps, others are ASP .NET.
How could I check from a method in my library, is it called form an
Winforms or ASP .NET?

tnx

Nov 21 '05 #2
I don't realy want to do it this way.
The library hold 100-120 classes and modifing their constructors is a
big pain. That is way I asked the question.
I need this only in method level.

Nov 21 '05 #3
Hi,

(Untested) Throw an exception that you handle to be able to look
at the exceptions classes stack trace.

http://msdn.microsoft.com/library/de...tracetopic.asp
Ken
---------------------------
"Nikolay Petrov" <jo******@mail. bg> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
I have an class library, which I shared with some of my apps.
Some of them are Winfroms apps, others are ASP .NET.
How could I check from a method in my library, is it called form an
Winforms or ASP .NET?

tnx
Nov 21 '05 #4
Nikolay,
I would consider having a value in my app.config/web.config that indicated
if the app itself is a web app or a win forms app. Especially if web or win
determined how a specific routine behaved. The specific routine would be an
overridable method of an abstract base class (a MustInherit class), where
the app.config indicated the specific concrete class to create (basically a
Strategy pattern & Plug-in pattern
http://www.martinfowler.com/eaaCatalog/plugin.html)

My app/dll would only use the StrategyBase abstraction, while there would be
specific implementations for both ASP.NET & Win Forms. This would also allow
defining a Console App & Windows Service strategies also.

I would store the full name of the concrete class that inherits from the
abstract base class in the app.config file. I then use
System.Activato r.CreateInstanc e to create instances of this class. Something
like:

<configuratio n>
<configSections >
<!-- define a custom config section to keep appSettings clean -->
<sectionGroup name="myCompany ">
<sectionGroup name="myProduct ">
<section name="myDll"
type="System.Co nfiguration.Sin gleTagSectionHa ndler"
/>
</sectionGroup>
</sectionGroup>
</configSections>
<myCompany>
<myProduct>
<!-- the "type" attribute is "namespace.clas s, assembly" -->
<myDll setting1="Value 1" setting2="value two"
type="MyProject .AspNetStrategy , MyProject" />
</myProduct>
</myCompany>
</configuration>

Imports System.Configur ation

Public MustInherit Class StrategyBase

Public MustOverride Sub Something()

Public Shared Function GetStrategy() As StrategyBase
Dim myDllConfig As IDictionary
Dim value1 As String
Dim value2 As String
Dim strategyTypeNam e As String

myDllConfig =
DirectCast(Conf igurationSettin gs.GetConfig("m yCompany/myProduct/myDll"),
IDictionary)
value1 = DirectCast(myDl lConfig("settin g1"), String)
value2 = DirectCast(myDl lConfig("settin g2"), String)
strategyTypeNam e = DirectCast(myDl lConfig("type") , String)

Dim strategyType As Type = Type.GetType(st rategyTypeName)
Dim strategyObject As Object =
Activator.Creat eInstance(strat egyType)
Return DirectCast(stra tegyObject, StrategyBase)
End Function

End Class

Public Class AspNetStrategy
Inherits StrategyBase

Public Overrides Sub Something()
' Do "Something" for ASP.NET apps
End Sub

End Class

Public Class WinFormsStrateg y
Inherits StrategyBase

Public Overrides Sub Something()
' Do "Something" for Win Forms apps
End Sub

End Class

In the above "value1" & "value2" could optionally be used as parameters to
the specific StrategyBase object.

See the following on how to create new sections via the configSections
section.

http://msdn.microsoft.com/library/de...onhandlers.asp

and:
http://msdn.microsoft.com/library/de...ionsschema.asp

Also read about the System.Configur ation.Configura tionSettings class and
other classes in the System.Configur ation namespace.
Hope this helps
Jay

"Nikolay Petrov" <jo******@mail. bg> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
|I have an class library, which I shared with some of my apps.
| Some of them are Winfroms apps, others are ASP .NET.
| How could I check from a method in my library, is it called form an
| Winforms or ASP .NET?
|
| tnx
|
Nov 21 '05 #5

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

Similar topics

20
10132
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
23
1615
by: John Rivers | last post by:
This shows you how to implement html rendering methods and libraries in ASPX pages. This also means super fast debugging as no re-initialising of IIS is required after editting! This gets around the ridiculous situation of ASPX pages not being allowed to have methods. I am working on a way to do this with classes as well!
4
1899
by: Shawn | last post by:
Hi. I have a ToolBar with a couple of ToolBarButtons. On postback after clicking on of the buttons Page_Load is called first then the ToolBarButton's click event is called. Is there anyway for me to check in Page_Load which of the buttons have been clicked? Thanks, Shawn
4
1335
by: Rich | last post by:
Hi I have five check boxes in a windows form. They are called chkEQUDS01, chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am getting the text name for the check boxes from a datatable and have wrote the code below: If dtEq.Rows(0).Item(2) = 1 Then chkEQUDS01.Enabled = True chkEQUDS01.Text = dtEq.Rows(0).Item(1) End If
9
3760
by: Sameh Ahmed | last post by:
Hello there Is there a way through dotNet to check if a certain user is a member of a specific group? I use ADSI to get the memberships of the user then compare them to the group I want to check, but this way the user has to be a member of this group directly and if he is a member of a group that is a member of that group he will not be considered a member of the group I am checking although he is implicitly. so basically what I need is...
5
1908
by: Tony | last post by:
Every 10 seconds I need to search a SQL table for orders to print. The orders are created through WebForms on ASP.NET clients. The orders should not print until 10 minutes before they are due. The network printer will be available from the server running IIS and SQL Server 2000. If this were a Windows Forms application, then I would create a system timer in Form1.Load(). How is this done in an ASP.NET application?
4
1684
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project that build a class library dll. Here we have a class called C We have one dependency and that is from the user control to the class library because in the constructor for class B in the user control we have a call to
55
3296
by: lovecreatesbea... | last post by:
Do you check all error conditions for all library calls in you code? Is it necessary to check all errors? Is it convenient to check all errors (or how to make code clean and readable with mass of non business logic related code block)? The following code from net-snmp library calls atoi five times but checks none. Do we code a wrapper my_atoi_with_error_check() around atoi and call this new one everywhere else? Is it a good practice...
2
4246
by: Christof Warlich | last post by:
Hi, I'm working on a (template) library that is up to now entirely implemented in header-files. This makes the library quite convenient to use as no extra object code needs to be linked when using the library. But now, the library needs to run some initialization code at system startup. Usually, this initialization code would be called from a .cc file once at system startup, e.g. by assigning the init function to a global variable:
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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
8605
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...
1
6163
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
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.