Connecting Tech Pros Worldwide Forums | Help | Site Map

Looking for proper way to code this

dfetrow410@hotmail.com
Guest
 
Posts: n/a
#1: Jan 12 '06
Is there a better way to break this out a bit?

static void Main(string[] args)
{
try
{
int rc1;
ROBOFTPAUTOMATIONLib.Automate RoboFTPSession = new
ROBOFTPAUTOMATIONLib.Automate();
RoboFTPSession = new Automate();
rc1 = RoboFTPSession.RoboStartSession("PUC-FTP", 1, 0, "");
rc1 = RoboFTPSession.RoboSendCommand("FTPLOGON \"ftp.xxxxxx.com\"
/user=xxxxx /pw=xxxxxx", 10 * 10);
rc1 = RoboFTPSession.RoboSendCommand("CHGDIR \"C:\\\"", 100 * 10);
rc1 = RoboFTPSession.RoboSendCommand("FTPCD \"test\"", 100 * 10);
rc1 = RoboFTPSession.RoboSendCommand("SENDFILE \"*.txt\"", 10000000
* 10);
rc1 = RoboFTPSession.RoboSendCommand("FTPLOGOFF", 10 * 10);
rc1 = RoboFTPSession.RoboSendCommand("STOP", 10 * 10);
}
catch(Exception)
{

}

}


Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Jan 12 '06

re: Looking for proper way to code this


Not really. The best I think you could do is change the variable name
from RoboFTPSession to ftp, and that should make it look a little better.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

<dfetrow410@hotmail.com> wrote in message
news:1137096684.115293.17070@g44g2000cwa.googlegro ups.com...[color=blue]
> Is there a better way to break this out a bit?
>
> static void Main(string[] args)
> {
> try
> {
> int rc1;
> ROBOFTPAUTOMATIONLib.Automate RoboFTPSession = new
> ROBOFTPAUTOMATIONLib.Automate();
> RoboFTPSession = new Automate();
> rc1 = RoboFTPSession.RoboStartSession("PUC-FTP", 1, 0, "");
> rc1 = RoboFTPSession.RoboSendCommand("FTPLOGON \"ftp.xxxxxx.com\"
> /user=xxxxx /pw=xxxxxx", 10 * 10);
> rc1 = RoboFTPSession.RoboSendCommand("CHGDIR \"C:\\\"", 100 * 10);
> rc1 = RoboFTPSession.RoboSendCommand("FTPCD \"test\"", 100 * 10);
> rc1 = RoboFTPSession.RoboSendCommand("SENDFILE \"*.txt\"", 10000000
> * 10);
> rc1 = RoboFTPSession.RoboSendCommand("FTPLOGOFF", 10 * 10);
> rc1 = RoboFTPSession.RoboSendCommand("STOP", 10 * 10);
> }
> catch(Exception)
> {
>
> }
>
> }
>[/color]


Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#3: Jan 12 '06

re: Looking for proper way to code this


dfetrow410@hotmail.com <dfetrow410@hotmail.com> wrote:[color=blue]
> Is there a better way to break this out a bit?[/color]

Well, you could encapsulate a command and whatever the second parameter
is into a struct or class, then have a list of them:

RoboCommand[] commands = new RoboCommand[]
{
new RoboCommand ("FTPLOGON \"ftp.xxxxxx.com\" [...]", 10*10),
new RoboCommand ("CHGDIR ....", 100*10),
new RoboCommand ("FTPCD ....", 100*10),
etc
}

foreach (RoboCommand command : commands)
{
RoboFtpSession.RoboSendCommand (command.Name,
command.OtherParameter);
}

(Depending on exactly what RoboFtpSession is, you could change that to
just command.Send() perhaps.)

Also, you're not using the value of the rc1 variable, so I'd get rid of
it.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Closed Thread