Jan 15, 2015, 11:37 AM
[CLOSED] Updating Progress bar from controller
Hi Guys,
I am trying to update a progress bar with the progress of a file download, I get the progress bar up, however it only updates to (say) 7 files of 7 once all the files have been uploaded. As an aside is there a way to change the message, that way I could change the word download to processing
View code:
I am trying to update a progress bar with the progress of a file download, I get the progress bar up, however it only updates to (say) 7 files of 7 once all the files have been uploaded. As an aside is there a way to change the message, that way I could change the word download to processing
View code:
Html.X().ButtonGroup().MarginSpec("5 5 5 0").Items(
Html.X().Button().Text("Get Trades").ID("GetTrades").Icon(Icon.WorldLink).Width(150)
.DirectEvents(de =>
{
de.Click.Before = "ShowProgressBar()";
de.Click.Url = Url.Action("GetTrades");
}
)
),
Controller: public ActionResult ShowProgressBar() {
// we're going to want something that lets the user know what is happening....
X.Msg.Show(new MessageBoxConfig
{
Title = "Please wait",
Message = "Connecting Client...",
ProgressText = "Initializing...",
Width = 300,
Progress = true,
Closable = true
});
return this.Direct();
}
public ActionResult GetTrades()
{
// before we do anything lets set up a folder to move the processed files into
// get the date
DateTime now = DateTime.Now;
string datestring = now.ToString("yyyy-MM-dd");
// set the target path (for processed files....)
string targetPath = "//localhost/getFiles/processed/" + datestring +"/";
// create the folder if it doesn't already exist
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
// now lets set up the file paths
// set the remote path (Client server)
string remotePath = "/tmp/D:/XXX/XXX/XML/";
// set the local path (downloaded files go here...)
string localPath = "//localhost/getfiles/";
// set a variable to let us know if trades have downloaded
int TradesDownloaded= 0;
// now deal with the files
// open FTP
ftp ftpClient = new ftp(@"ftp://TEST", "TESTUSER", "TESTPASSWORD");
// get the names of each file in the directory
string[] filesForDownload = ftpClient.directoryListSimple(remotePath);
// varable to let us know how many trades are are to be downloaded
int TradesToDownload = (filesForDownload.Length) -3;
//Update message box
X.Msg.UpdateProgress(0, string.Format("Downloading File {0} of {1}...", 0, TradesToDownload));
// loop through files and downlaod
for (int i = 0; i < filesForDownload.Count(); i++) {
//download(remoteFile, localfile)
string remoteFile = remotePath + filesForDownload[i];
string localFile = localPath + filesForDownload[i];
if (ftpClient.download(remoteFile, @localFile)) {
// delete file
ftpClient.delete(remoteFile);
// increment the count
TradesDownloaded++;
X.Msg.UpdateProgress(((int)TradesDownloaded) / TradesToDownload, string.Format("Downloading File {0} of {1}...", TradesDownloaded, TradesToDownload));
}
}
// close the connection
ftpClient = null;
}
Last edited by Daniil; Jan 21, 2015 at 12:52 PM.
Reason: [CLOSED]