Looking for proper way to code this

  • Thread starter Thread starter dfetrow410
  • Start date Start date
D

dfetrow410

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)
{

}

}
 
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.
 
Is there a better way to break this out a bit?

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.
 
Back
Top