Hi there,
I am trying to get some conditional functionality into some of my
apps. I can use the format :
[Conditional("DE BUG")]
private void doStuff()
{
//do something
}
as expected, but I would like to makr it a little more useful in a
multi-machine environment.
I want to make tweaks to an application based up whether it is running
on my development laptop, the stage server or the live server, and
conditionals seem to be the most efficient way forward. However, I am
not sure how to go about defining an environment variable to trigger
the consitional method.
Here's what I *think* I want to do... **snip unnecessary stuff**
string outputMessage; string productionServe r;
private string statusMessage() { outputMessage = "This application is running on " + Environment.Hos tName + ". "; productionServe r = "This is the production server. "; isDevBox(); return outputMessage + productionServe r; }
[Conditional( ***HERE IS WHERE I AM COMING UNSTUCK****)] private void checkIsDevBox() { //reset things like connection strings, data table names, development queries, and whatever else I need productionServe r = "This is one of the development of stage servers. "; } **snip unnecessary stuff**
It seems that I need to check if Environment.Hos tname matches one of
my two development server names, and if so, set a flag that
[Conditional] can work with. It's all very well to know this is what
I need to do, but I have not the first clue about how to go about that
bit.
Can anyone help, please?
Thanks
Marc. 6 1568
Marc,
You aren't going to be able to do this. The reason is that the
Conditional attribute is evaluated at compile-time, not run-time. It is
strictly for pre-processor values, not environment values.
If you want to do something based on the environment, you are going to
have to write code that will detect the environment you are in, and then
make the appropriate calls.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Marc Jennings" <Ma**********@c ommunity.nospam > wrote in message
news:p7******** *************** *********@4ax.c om... Hi there,
I am trying to get some conditional functionality into some of my apps. I can use the format :
[Conditional("DE BUG")] private void doStuff() { //do something }
as expected, but I would like to makr it a little more useful in a multi-machine environment.
I want to make tweaks to an application based up whether it is running on my development laptop, the stage server or the live server, and conditionals seem to be the most efficient way forward. However, I am not sure how to go about defining an environment variable to trigger the consitional method.
Here's what I *think* I want to do... **snip unnecessary stuff**
string outputMessage; string productionServe r;
private string statusMessage() { outputMessage = "This application is running on " + Environment.Hos tName + ". "; productionServe r = "This is the production server. "; isDevBox(); return outputMessage + productionServe r; }
[Conditional( ***HERE IS WHERE I AM COMING UNSTUCK****)] private void checkIsDevBox() { //reset things like connection strings, data table names, development queries, and whatever else I need productionServe r = "This is one of the development of stage servers. "; } **snip unnecessary stuff**
It seems that I need to check if Environment.Hos tname matches one of my two development server names, and if so, set a flag that [Conditional] can work with. It's all very well to know this is what I need to do, but I have not the first clue about how to go about that bit.
Can anyone help, please?
Thanks Marc.
Hi,
I dont think that will work, you are detecting the environment at runtime,
the conditionals are evaluated at compile time.
A possible solution would be define a preprocessor in the project
configuration, if you have a different project definition file in each
machine you can do what yuoui want, how factible this is would depend of
your project, if you add a new file or a new reference to one of the
projects you will need to do the same thing in the others, that is the only
( HUGE ) drawback I see. you can copy the source code though.
It probably is not a solution but may be a work around, it's the best I can
think of right now.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Marc Jennings" <Ma**********@c ommunity.nospam > wrote in message
news:p7******** *************** *********@4ax.c om... Hi there,
I am trying to get some conditional functionality into some of my apps. I can use the format :
[Conditional("DE BUG")] private void doStuff() { //do something }
as expected, but I would like to makr it a little more useful in a multi-machine environment.
I want to make tweaks to an application based up whether it is running on my development laptop, the stage server or the live server, and conditionals seem to be the most efficient way forward. However, I am not sure how to go about defining an environment variable to trigger the consitional method.
Here's what I *think* I want to do... **snip unnecessary stuff**
string outputMessage; string productionServe r;
private string statusMessage() { outputMessage = "This application is running on " + Environment.Hos tName + ". "; productionServe r = "This is the production server. "; isDevBox(); return outputMessage + productionServe r; }
[Conditional( ***HERE IS WHERE I AM COMING UNSTUCK****)] private void checkIsDevBox() { //reset things like connection strings, data table names, development queries, and whatever else I need productionServe r = "This is one of the development of stage servers. "; } **snip unnecessary stuff**
It seems that I need to check if Environment.Hos tname matches one of my two development server names, and if so, set a flag that [Conditional] can work with. It's all very well to know this is what I need to do, but I have not the first clue about how to go about that bit.
Can anyone help, please?
Thanks Marc.
Thanks for that. I guess I would have seen this if I had read the
docs properly.
It's not a problem, though. I'll just have to go back to the old
switch(Environm ent.MachineName ) kind of thing (Which I probably prefer
anyway...)
Thanks again, both responders...
On Mon, 10 Jan 2005 09:53:12 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard .caspershouse.c om> wrote: Marc,
You aren't going to be able to do this. The reason is that the Conditional attribute is evaluated at compile-time, not run-time. It is strictly for pre-processor values, not environment values.
If you want to do something based on the environment, you are going to have to write code that will detect the environment you are in, and then make the appropriate calls.
Hope this helps.
I would even suggest refactor the code into some type of factory pattern to
make the code more managable.
"Marc Jennings" wrote: Thanks for that. I guess I would have seen this if I had read the docs properly.
It's not a problem, though. I'll just have to go back to the old switch(Environm ent.MachineName ) kind of thing (Which I probably prefer anyway...)
Thanks again, both responders...
On Mon, 10 Jan 2005 09:53:12 -0500, "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote:
Marc,
You aren't going to be able to do this. The reason is that the Conditional attribute is evaluated at compile-time, not run-time. It is strictly for pre-processor values, not environment values.
If you want to do something based on the environment, you are going to have to write code that will detect the environment you are in, and then make the appropriate calls.
Hope this helps.
Alternatively, you could just use different config files on you different
systems that contain the proper configuration for the environment. That way
you don't have to hard-code machine names or the such.
Ken
"Marc Jennings" <Ma**********@c ommunity.nospam > wrote in message
news:a5******** *************** *********@4ax.c om... Thanks for that. I guess I would have seen this if I had read the docs properly.
It's not a problem, though. I'll just have to go back to the old switch(Environm ent.MachineName ) kind of thing (Which I probably prefer anyway...)
Thanks again, both responders...
On Mon, 10 Jan 2005 09:53:12 -0500, "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote:
Marc,
You aren't going to be able to do this. The reason is that the Conditional attribute is evaluated at compile-time, not run-time. It is strictly for pre-processor values, not environment values.
If you want to do something based on the environment, you are going
tohave to write code that will detect the environment you are in, and then make the appropriate calls.
Hope this helps.
To add to Daniel's reply,
Create an object that encapsulates the differences in functionality that you
need between your dev environment and your production environment (and any
others). You can have multiple child classes, one for each environment, all
inheriting from the same interface.
Then, when your app starts, call a factory method to return a child object
that matches the environment. The factory method can either refer to the
config file to detect the environment or use machine name or whatever you
want (I prefer config file, but it's your call). After that, none of your
code needs to ever write a line of different code for "production " vs "dev
environment" .
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Marc Jennings" <Ma**********@c ommunity.nospam > wrote in message
news:a5******** *************** *********@4ax.c om... Thanks for that. I guess I would have seen this if I had read the docs properly.
It's not a problem, though. I'll just have to go back to the old switch(Environm ent.MachineName ) kind of thing (Which I probably prefer anyway...)
Thanks again, both responders...
On Mon, 10 Jan 2005 09:53:12 -0500, "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote:
Marc,
You aren't going to be able to do this. The reason is that the Conditional attribute is evaluated at compile-time, not run-time. It is strictly for pre-processor values, not environment values.
If you want to do something based on the environment, you are going
tohave to write code that will detect the environment you are in, and then make the appropriate calls.
Hope this helps. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jouke Langhout |
last post by:
Hello all!
For quite some time now, I've got the following problem:
Access won't close properly when a user closes the application. An
ACCESS process stays active and that process can only be terminated by
pressing ++ and then terminate the process.
I searched the entire internet and found out that there could be two
things wrong (both of them are mentioned in the bug list on the access
|
by: ammarton |
last post by:
Hello all...I'm a bit new to working with Macros in Access so forgive
me if the terminology I use is not accurate.
To preface this, basically I am using a form on a replicated database
so the end-user can filter on a specific report they want to see. This
database was designed by my predecessor (of which he left no
documentation) and I need to add some additional functions to this
end-user filter report.
Within one Macro, he has over...
|
by: mux |
last post by:
Hi
I found out that the following piece of code throws an error.
1 #include "stdio.h"
2
3 int main()
4 {
5 int a,b;
6 a= 10;
|
by: Kumar |
last post by:
Hi Folks,
I have a question regarding conditional hyperlink in datagrid.
I want to display Hyperlink if my QID values in (1,4,5,6) other wise i
want to display just Qdescription with out hyperlink.
<asp:hyperlinkcolumn headertext="Question" SortExpression="QDescription"
datatextfield="QDescription"
|
by: Dave |
last post by:
I'm a C++ programmer of many years, trying to get my feet wet in C#.
I have a question about conditional compilation. In C++, I would
sometimes define a constant in an include file, and then have blocks of
code in different source files that were conditionally compiled based
on that constant. Now that C# has done away with include files, is
there any way of doing the same thing, short of defining the constant
multiple times at the head...
| |
by: paulo |
last post by:
Can anyone please tell me how the C language interprets the following
code:
#include <stdio.h>
int main(void)
{
int a = 1;
int b = 10;
int x = 3;
|
by: Marek |
last post by:
I use VS2005 with framework 2.0 and I just found a behavior I consider odd.
Here is the code that illustrates th eproblem:
public static void MethodA()
{
MethodB()
}
#if DEBUG
|
by: somenath |
last post by:
Hi All,
I have one question regarding the conditional operator.
In the draft C99 standard it is mentioned that
"1 The following are the sequence points described in 5.1.2.3:
-- The call to a function, after the arguments have been evaluated
(6.5.2.2).
-- The end of the first operand of the following operators: logical AND
&& (6.5.13);
|
by: John |
last post by:
Hi there,
I've just been reading "ASP.Net 2.0 - Master Pages: Tips, Tricks, and
Traps" by K. Scott Allen (http://odetocode.com/Articles/450.aspx) and
discovered how rebasing works with URL's in link tags for external css
files.
My question is, does this also work for link tags enclosed within
conditional comments? eg:
<!-->
|
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...
|
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...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |