|
The idea is that other components can get another component based on its key.
At the moment there is no configuration file aspects, but I may consider it...
The problem is that one type of component can be added multiple times, some of them can be configured to act more generically, in theory I could install two OffScreenSensor's but with different keys.
|
|
|
|
|
That is a different problem however than using a key.
venomation wrote: some of them can be configured to act more generically, in theory I could
install two OffScreenSensor's but with different keys.
Which only apples to what I said if when you say "install" then it refers to something that is basically code, and not something that a 'user' would muck with.
If it does refer to 'code' then you are not using a "component" but rather an instance of a component. So the name refers to an instance even if most only have a single instance.
|
|
|
|
|
Its generally not a good idea to use strings as keys to get components like that. My boss is a notorious mispeller. Do you really want to spend time tracking down why your app doesn't work because somebody spelled it "scren" in 3 out of 100 places? GUIDs as I suggested earlier actually wouldn't be AS prone. Why? I'd probably type in "screen" myself because I can do that faster then copy & pasting from somewhere. With a GUID? I'm not going to type that in. Thats going to be a strict c&p.
Is adding a component multiple times "theoretical"? or is it really going to happen?
Would it be more practical to have a single instance of OffscreenSensor that can sense things from multiple locations?
Instead of doing something like:
Components["Screen1"].EventHappened +=
you could do something like:
IScreenSensor sensor = ServiceLocator.GetService<IScreenSensor>();
sensor.GetScreen(1).EventHappened +=
sensor.GetScreen(2).EventHappened +=
etc.
string keys are also prone to lazy search and replace issues .
|
|
|
|
|
SledgeHammer01 wrote: Its generally not a good idea to use strings as keys to get components like that. My boss is a notorious mispeller. Do you really want to spend time tracking down why your app doesn't work because somebody spelled it "scren" in 3 out of 100 places? GUIDs as I suggested earlier actually wouldn't be AS prone. Why? I'd probably type in "screen" myself because I can do that faster then copy & pasting from somewhere. With a GUID? I'm not going to type that in. Thats going to be a strict c&p.
I would suggest unit testing and system testing to solve that problem. Additionally that also solves the problem where they typed in "alternativeScreen" (a valid component) when it should have been "screen" (also valid.)
And myself I would be opposed to using a guid because that means that to figure out what component instance is in use one would need to look it up every time.
However depending on the actual requirements I would probably use a generated enumeration.
|
|
|
|
|
To add a key to a Dictionary, it must be unique. If there is a property of the Sensor object that is unique, use it in place of the made-up string. This will help you recreate the entire object from this key. If you just need a random string and you don't care about what it is, use a GUID.
|
|
|
|
|
If your goal is to make it easy for you to select one of the available, limited, set of choices of "unique keys" during development: then using an Enum makes very good sense: it gives you Intellisense display of the choices possible.
But that Enum could just as well be passed, as Luc pointed out, as an argument to a constructor overload or whatever for the OffScreenSensor class: unless, of course, you make use of that second parameter in other important ways in the function you call.
But, what's the usage/relationship of the new "OffScreenSensor" you create and pass as a parameter, along with the second parameter that serves a unique key to some (we assume) existing OffScreenSensor you are going to access by using the unique key?
That's what's puzzling here. Is the new "OffScreenSensor" some temporary entity that's never preserved: outside the scope of the functional call: never entered in your storage (dictionary or whatever) for the other (assume instances of ?) OffScreenSensor's ?
Are the OffScreenSensor instances in the (assumed) Dictionary sub-classed "flavors" of some master class OffScreenSensor ?
Is there a security aspect here ?
Without some sense of what your "big picture" goals are here, it's difficult to respond meaningfully.
In a technical forum like this, "vague" is automatically amplified
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
|
Yeah, use an enum , or go for GUIDs
|
|
|
|
|
hi
i designed my form as
textbox, button
now in the buttonclick event i wrote a code which is as follows!
try
{
string constr = "User Id = scott;Password=tiger;Provider=Msdaora.1";
OleDbConnection con = new OleDbConnection(constr);
con.Open();
MessageBox.Show(" Connected to ORACLE!");
string q = "create table pert(enum number,ename varchar2(10),sal number)";
OleDbCommand cmd = new OleDbCommand(q, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Table Created!");
}
catch (OleDbException a)
{
MessageBox.Show(a.Message);
}
now in the string q how do i add a textbox1.text so that while running my program i give the table name dynamically instead of statistically mentioning the table name as shown in the string q.
|
|
|
|
|
Perhaps with a parameter (I haven't tried it); certainly with concatenation, but that would be bad form.
|
|
|
|
|
was that an anwswer! its looking like something else!
|
|
|
|
|
with precautions, no bad form I'd say.
|
|
|
|
|
IMO the answer holds two parts:
1. don't use a TextBox, use a ComboBox (with ComboBoxStyle.DropDownList) presenting the allowable table names.
2. then perform string concatenation to build the SQL statement.
|
|
|
|
|
the dropdown list would eliminate the facility of having tablenames according to user choices. This IMO is essential if we are dealing with a SQL Parser or a simillar application, or a situation where we need user-specified entity names in the database.
We can use a textbox and employ reguler expressions / validation controls in order to eliminate the possibility of an incorrect tablename.
|
|
|
|
|
Something needs to be done to protect against abuse. Validation is one way, yes.
|
|
|
|
|
Try the following:
string q = "create table " + Textbox1.text + "(enum number,ename varchar2(10),sal number)";
a better way (cleaner and easily readable) of doing it would be to use a local string variable to store the table name from the text box and concatenate the string using that variable.
string temp = Textbox1.Text;
string q = "create table "+temp+ " (enum number,ename varchar2(10),sal number)";
|
|
|
|
|
|
why did u downvote ?? please explain
|
|
|
|
|
I disliked very much however I did not downvote.
Your code would not compile.
And it is flawed, see my other posts in this thread.
|
|
|
|
|
hi
AHSAN111!
thanks for the reply mate! the first and the second parts that u explained are working fine for me!
this is how my new code looks like!
try
{
string constr = "User Id = scott;Password=tiger;Provider=Msdaora.1";
OleDbConnection con = new OleDbConnection(constr);
con.Open();
MessageBox.Show(" Connected to ORACLE!");
string g = textBox1.Text;
string q = "create table " +g+ "(enum number,ename varchar2(10),sal number)";
OleDbCommand cmd = new OleDbCommand(q, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Table Created!");
}
|
|
|
|
|
that is bad code, it is open for SQL injection, people can type anything they like in the TextBox and make your program execute it.
I already told you precautions had to be taken against it, using a uneditable ComboBox rather than a TextBox is one way of doing just that.
|
|
|
|
|
ooh!
but if i use comboboxstyle with allowable table names! the whole purpose of what i wanted would not be served! is there any way by which it can be done! ? but thank u very much for the suggestion mate! am seriously learning a lot from this!
|
|
|
|
|
As I said, you need to use a validator to ensure that only allowable table names are used to construct the query. You can use javascript + regex or .net validation controls as it suites you.
|
|
|
|
|
hi
when i delete my program (in C#) through add/remove programs
the database still exists - how to delete him ?
thanks in advance
|
|
|
|
|
You can create a custom action in your installer that runs when the product is uninstalled.
The custom action would call a function in one of your DLL's that removes any files created by the program after it was installed.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|