C# Help

Started by G_G, September 15, 2009, 12:18:13 am

Previous topic - Next topic

Ryex

October 07, 2009, 12:09:47 am #60 Last Edit: October 07, 2009, 01:03:52 am by Ryexander
I just got a brilliant idea! if you run two servers at the same time through the same port you get an error because only one use of the port is normally permitted could this be used to test if the server was running?

EDIT so I looked around and it would be something like this right?

            IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
            try
            {
                TcpListener tcpListener = new TcpListener(ipAddress, <portnumber the server is useing>);
                tcpListener.Start();
            }
            catch (SocketException ex)
            {
                MessageBox.Show(ex.Message, "kaboom");
            }


the Exception would throw if the server was already running right?

the only problem is how do I get access to those functions? I need to be using a specific name space but which one?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

What you are doing there is pretty much implementing a C# version of RMX-OS. You don't need to do that.

@G_G: Message.Show freezes the execution until the users closes the dialog. It returns a DialogResult instance which you can compare to DialogResult.XXXX constants to check which button was pressed. I used the same thing in Blizz-ABS Config.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

Quote from: Blizzard on October 07, 2009, 05:43:32 am
What you are doing there is pretty much implementing a C# version of RMX-OS. You don't need to do that.

@G_G: Message.Show freezes the execution until the users closes the dialog. It returns a DialogResult instance which you can compare to DialogResult.XXXX constants to check which button was pressed. I used the same thing in Blizz-ABS Config.


C# version of RMX-OS? no I'm just building a GUI for it, and i don't want the run button to work if there is already a server copy running or there is something already using the port that RMX-OS is configured to use. the GUI will have other stuff too. like a tab for easy configuration of RMX-OX and quick viewing of the log files. I also plan to have the ability to register a new user with the option to make said user a admin. other stuff too.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Hm... I think that it's possible to check if a process is still running if you keep a reference at it. So when you run the ruby process with RMX-OS, you could use an additional thread to check if the process is still alive.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Okay just a question..so I have my file on my host, now how would I like make it go to another host to get the file, if the firsthost is down? Here's my code.

WebClient download = new WebClient();
byte[] filedata = download.DownloadData("first host here");
FileStream file = File.Create(Application.StartupPath + "\\update.zip");
file.Write(filedata, 0, filedata.Length);
file.close();


Now last night my host was down so it couldnt download the file, so I want it to be able to go to another host if it cant access the first. Is it possible? if so how?

Ryex

ga I'm trying to load all the options from the RMX-OS cfg.ini file
I'm storing the entire file to a string and then going through with regexp to find "Keyword = value" matches storing the value according how ever since some of the values are things like 'Localhost' with the single quotes or "Localhost" with double quotes I need to remove the '' or "" if it has them
but so far I have been unsuccessful in creating a working regexp to match something surrounded by quotes can some one help me?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Can you get back at me with that later? My brain is unusable today. I'll put a regex together that will parse the file properly for you.

Or you can try to use the integrated "read ini" methods.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

Quote from: Blizzard on October 08, 2009, 03:46:04 am
Can you get back at me with that later? My brain is unusable today. I'll put a regex together that will parse the file properly for you.

Or you can try to use the integrated "read ini" methods.

I could... if the file was in proper ini format. right now its formatted like a ruby script and RMX-OS loads it like one.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

October 08, 2009, 01:11:13 pm #68 Last Edit: October 08, 2009, 02:06:34 pm by Blizzard
Well... Except for sections and having spaces between the key, the = sign and the value, it's pretty much the same.

EDIT:

Run this regex for strings.

"(\S+?) = \"(.*)\""


Then run this regex for more strings:

"(\S+?) = '(.*)'"


This one for boolean:

"(\S+) = (true|false)"


Floats:

"(\S+) = (\d+\.\d+)"


And integers:

"(\S+) = (\d+)[^\.]"


I put all regexes in " quotes and escaped the " quote character within. I didn't use regex with C# so far so I'm not sure if you use a string for it or if there is an integrated regex class (i.e. /(\S+) = (\d+\.\d+)/)

You will have to do some afterprocessing for the extensions though:

"(\S+?) = \[((?:.|\n)*)\]"


This will give a string with \n , ' and " characters which you will have to filter.

And keep in mind that this doesn't support comments with " and ' characters. In fact, comments should be avoided in the ini file.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

How do I execute a code from a textbox or something? Like in rmxp you can do this
eval(code)

How would we do that in C#?

fugibo

Quote from: game_guy on October 08, 2009, 03:40:48 pm
How do I execute a code from a textbox or something? Like in rmxp you can do this
eval(code)

How would we do that in C#?


You can't. Go read up on "interpreters" and "machine code." You'd have to compile the code against your current code base, then execute it, which might be impossible.

Blizzard

October 08, 2009, 07:10:23 pm #71 Last Edit: October 08, 2009, 07:12:24 pm by Blizzard
Bullshit. http://www.codeproject.com/KB/cs/evalcscode.aspx Where's your god now?

Also, I remember that C# 4.0 was supposed to have an Eval function support natively, but I can't find it anywhere in the specs.

BTW, eval is usually bad practice. Don't use unless you'd end up with a billion switch case statements.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Quote from: Blizzard on October 08, 2009, 07:10:23 pm
Bullshit. http://www.codeproject.com/KB/cs/evalcscode.aspx Where's your god now?

Also, I remember that C# 4.0 was supposed to have an Eval function support natively, but I can't find it anywhere in the specs.

BTW, eval is usually bad practice. Don't use unless you'd end up with a billion switch case statements.


Crap. I knew someone would probably have done this anyway, but *blah.* So how does that work, recompiles the code?

G_G

October 08, 2009, 10:42:01 pm #73 Last Edit: October 09, 2009, 01:01:24 am by game_guy
I googled how to setup a tooltip and I just ran into confusing constructions, can anyone help me how to setup a tooltip?

EDIT: Dont worry about the tooltip I figured it out. But I want to figure out how to get every item from a combo box.
I figured out how to get the amount of items in it by using this.
comboBox1.Items.Count;

What I want to do is be able to like get every item in there. Like how would I do the for i in 0...size command in c#?

Blizzard

October 09, 2009, 03:40:13 am #74 Last Edit: October 09, 2009, 03:41:39 am by Blizzard
Quote from: Longfellow on October 08, 2009, 07:27:37 pm
Crap. I knew someone would probably have done this anyway, but *blah.* So how does that work, recompiles the code?


Compilation on the fly from what I can see from the code. IMO it's a stupid idea to force eval. One should be very, very careful when using it. :/

Quote from: game_guy on October 08, 2009, 10:42:01 pm
I googled how to setup a tooltip and I just ran into confusing constructions, can anyone help me how to setup a tooltip?

EDIT: Dont worry about the tooltip I figured it out. But I want to figure out how to get every item from a combo box.
I figured out how to get the amount of items in it by using this.
comboBox1.Items.Count;

What I want to do is be able to like get every item in there. Like how would I do the for i in 0...size command in c#?


It implements IEnumerable, just iterate through it.

foreach (object item in comboBox.Items)
{
}


Just don't forget to cast the objects. I hope you didn't put in objects of different classes. BTW, did you know that if you put in objects and override ToString() in the definitions of those objects, you can have code that is easier to read and more organized? The combobox calls ToString() to display the items.

class Person
{
   public string name = "Johnny";
   public override string ToString()
   {
       return this.name; // displays this item as "Johnny" in a combobox/listbox
   }
}


Syntax might have errors, I haven't written C# code for some while.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Okay one more thing the item in the iterate is pretty much the x variable then right?

Blizzard

Yeah, it's the equivalent of this Ruby code:

for item in combobox.Items
end
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Okay works perfectly thanks blizz one more thing is it possible to do it with a text file except this time with lines?
for line in text.lines?

Blizzard

For strings you can use this:

foreach(string line in text.Split("\r\n"))
{
}


If "\r\n" doesn't work for you, use just "\n".
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

thanks blizz I've been able to load and save the configuration successfully thanks to you.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />