|
Maybe a Regular Expression?
|
|
|
|
|
|
"Regular Expression"
Now thats one thing i can never get my head around and yet my two most used functions of all time used in a string extention method could be done using a one line RegEx
public static string ChopOffBefore(this string s, string Before)
{
int End = s.ToUpper().IndexOf(Before.ToUpper());
if (End > -1)
{
return s.Substring(End + Before.Length);
}
return s;
}
public static string ChopOffAfter(this string s, string After)
{
int End = s.ToUpper().IndexOf(After.ToUpper());
if (End > -1)
{
return s.Substring(0, End);
}
return s;
}
I just could not live without them, must be old school
modified 6-Apr-15 10:54am.
|
|
|
|
|
Rather than converting both strings to upper-case, which creates a new string, you simply need to pass a StringComparison to the IndexOf method:
int End = s.IndexOf(Before, StringComparison.OrdinalIgnoreCase);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You sir are 100% right
I just about always use "StringComparison.OrdinalIgnoreCase" when using a string key in a dictionary but forget to use it on things like IndexOf and i never use string.empty bcus "" is faster to type.
Not only that but it is very rare for me to lock string when using threads and i tend to just swap strings in and out to avoid race conditions but it has never caught me out so long as the strings are not too big.
When i am not a macro writer (thats all we are becoming with .Net) i am a string butcher
|
|
|
|
|
Hi,
I would like to develop a tool which would be help to install windows OS on selected IP's Machines , These IP's are in same LAN. How can i do coding in C#.
Thanks in Advance.
|
|
|
|
|
Just how do you propose to do that?
Unless the PC's have an OS installed, they won't have an IP address, so you won't be able to contact them...and if they have an OS installed, it's going to be up to the OS exactly what you have to do, won't it?
And just how do you propose to handle licencing and the various product keys you are going to need?
I know you can do it - see Remote Installation Services[^] - But I don't think you can "kick the process off" from a centralised computer - you have to arrange for the individual PCs to boot from the network.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
In case my systems already have OS : My tool has to give me list of IPs connected in the network and then i select few of the IPs(single IP) and it has to install selected software's(OS's,msoffice,Adobe reader, VLC player.. etc) On those meashines .
|
|
|
|
|
|
Systems like this already exist. Alteris by Symantec and System Center Configuration Management from Microsoft, among others.
The problem you're describing is far more complex than you realize. You need a client running on each machine, reporting back to a central server what it's IP currently is along with some identifier that uniquely ID's that machine.
Why? Laptops. Laptops can change IP addresses just by popping the machine out of the docking station. The DNS infrastructure will not update the change in IP address instantly, so when your server tries to contact the machine using DNS information, it won't get a response.
More problems consist of how you're going to sync up content between the server and the clients? How is the client going to know what it has to install and what it already installed? How is the content going to be transferred from the server to the clients for installation? How is the client going to verify that it has all the content for an installation?
What happens if the client or the server drops off the network in the middle of a content transfer? How are you going to recover from this situation?
No, you cannot run all installers from a server location. Some installers just don't tolerate that while others cannot be installed by multiple machines at the same time. It will work for most installers, but there's always one that will bite you in the ass. Trust me, I've been there.
If you think commercial software packages are too expensive to justify this, think about how much you get paid by the hour and how long it's going to take you to write both the server and client ends of this system and completely test it. I guarantee you it'll be more expensive than using an off-the-shelf solution.
|
|
|
|
|
Think about this. Why is it you don't already see a tool out there doing this?
Because what you want to do isn't possible without having some tool already running on the target machine.
On top of that, it's a MASSIVE security risk.
What you want to do isn't possible.
|
|
|
|
|
Dave Kreskowiak wrote: What you want to do isn't possible.
In theory, it is - you can use a Group Policy Startup Script[^] and push it to all PC's in the group.
I've not tried it, but it should work in a well controlled corporate environment. Nasty though!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
If the machine is already in AD and has an O/S on it, yeah it works. All actions run under the Local System account.
I'm approaching from the standpoint of a bare metal machine. No O/S, no anything on it.
|
|
|
|
|
So was I, but he replied with "In case my systems already have OS : My tool has to give me list ..." which changed it all a bit.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Problem Background:
In my WPF application, in one of the window/page contains 3 List Boxes and 1 ComboBox. These 3 ListBoxes are binded with XML dataprovider and there is no issues. I mean when 1st listbox selection changes automatically updates listbox2. In the same way, listbox3 updates as listbox2 changes. These are all worked out in XAMl file alone and there is code-behind except InitializeComponent() and few lines of code for loading this XAML file dynamically using XAMLReader(this is my requirement)
Problem facing Requirement:
OnSelection change event of any of the ListBox, need to populate ComboBox data dynamically( it will fire webservices which is based on above mentioned 3 LisBox selection). For this purpose, in SelectionChange I am trying to get
ListBoxObj.SelectedItem - Always contains XML tree.(i.e) of type XMLElement
I have tried all possiblities, everywhere I am getting only XML tree.
Anyone have any idea, how to extract ListBox selected Item Text from XMLElement?
Thanks
|
|
|
|
|
Try setting the SelectedValuePath[^] property to the XPath expression of the value you need to extract, and then reading the SelectedValue[^] property.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have two buttons (button1 and button2), a List<int> and a database. When form is loading, it selects a row from database with some values and assign them value to some labels and int variables. When I click on button1, the id of the row is inserted in list as an int value (idintrebare). In List can be maximum 26 elements. Here is my problem: when I click on button2, I want to select from database, rows where idintrebare is equal with id field from table (questions), but only one row per click, and assing to the same labels and int variables values from table. If all elements from list were selected, application will exit. Here is what I tried:
First I have the list:
List<int> coada = new List<int>(26);
Function for select data:
private void selectCoada()
{
using (Conexiune.getConnection())
{
foreach (int idi in coada)
{
string select = "SELECT DISTINCT * FROM questions WHERE id = '" + idi + "' LIMIT 1";
SQLiteCommand cmd = new SQLiteCommand(select, Conexiune.getConnection());
cmd.CommandType = CommandType.Text;
SQLiteDataReader rdra = cmd.ExecuteReader(CommandBehavior.CloseConnection);
try
{
while (rdra.Read())
{
textBox1.Text = rdra["question"].ToString();
textBox2.Text = rdra["answer1"].ToString();
textBox3.Text = rdra["answer2"].ToString();
textBox4.Text = rdra["answer3"].ToString();
r1 = (int)rdra["option1"];
r2 = (int)rdra["option2"];
r3 = (int)rdra["option3"];
idintrebare = Convert.ToInt32(rdra["id"]);
SimulatorManager.Intrebare = textBox1.Text;
}
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
In button1 I have just:
coada.add(idintrebare);
In button2 I have:
selectCoada();
The problem is that it selects only one value from list. I tried to use a for like this:
private void selectCoada()
{
using (Conexiune.getConnection())
{
for(int i=0;i<=coada.Count;i++) {
foreach (int idi in coada)
{
string select = "SELECT DISTINCT * FROM questions WHERE id = '" + idi + "' LIMIT 1";
SQLiteCommand cmd = new SQLiteCommand(select, Conexiune.getConnection());
cmd.CommandType = CommandType.Text;
SQLiteDataReader rdra = cmd.ExecuteReader(CommandBehavior.CloseConnection);
try
{
while (rdra.Read())
{
textBox1.Text = rdra["question"].ToString();
textBox2.Text = rdra["answer1"].ToString();
textBox3.Text = rdra["answer2"].ToString();
textBox4.Text = rdra["answer3"].ToString();
r1 = (int)rdra["option1"];
r2 = (int)rdra["option2"];
r3 = (int)rdra["option3"];
idintrebare = Convert.ToInt32(rdra["id"]);
SimulatorManager.Intrebare = textBox1.Text;
}
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
, but also didn't worked.
|
|
|
|
|
If you want to select one row each time button2 is clicked, and move through the rows in order:
private List<int> coada = new List<int>(26);
private currentIdi = 0;
if(coada.Count < 27) coada.add(idintrebare);
if(currentIdi == coada.Count || currentIdi == 25) Application.Exit;
currentIdi++;
selectCoada(coada[currentIdi]);
private void selectCoada(int idi)
{
using (Conexiune.getConnection())
{
string select = "SELECT DISTINCT * FROM questions WHERE id = '" + idi + "' LIMIT 1";
}
}
Comment: I think it's always a good idea to disable Controls when their use would cause an error, or when their use is irrelevant because the app is "not ready" to handle them. You might think about disabling 'button2 until clicking on it really can do something without an error.
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
I receive:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
|
|
|
|
|
Code is good, but when all item have been passed and should show finish message, I receive that
|
|
|
|
|
It's ok, I fixed it. Thank you very much for your help, I understand now
|
|
|
|
|
Good
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
Unfortunately, I still have a problem. I thought I fixed it, but I was wrong. I understand why I receive that, but I don't know how to fix it. Can you help me with that?
|
|
|
|
|
If the problem you have now is a totally new kind of problem you haven't mentioned before, then I suggest you start a new question and include code samples, error messages, etc.
If it's the same problem you've discussed already, I suggest you add a new post to this thread and describe exactly what's not working the way you expect.
Have you stepped through your code with the debugger and isolated where the problem occurs ?
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
Aaaa sorry, I thought you might know what problem can appear in that case. Well, On button2, you know that I call select function. Well, after last id was selected from list, I receive that error message about index. That means that the list is empty and currentIdi can't have a negative value.
modified 5-Apr-15 9:36am.
|
|
|
|