private void DownloadFile(string name)
{
var filePath = GetFilePath(name);
AddCommand(CommandFactory.CreateCommand<DownloadedFilePartMessage>(
CommandType.Download,
Slave,
name,
command => // execute
{
Send(new DownloadFilePartMessage
{
Id = command.Id,
CurrentPart = 0,
Path = filePath
});
},
download => // continue
{
try
{
FileHelper.WriteDownloadedPart(Slave.OutputDirectory, download.Path,
download.CurrentPart, download.RawPart);
Send(new DownloadFilePartMessage
{
Id = download.Id,
Path = download.Path,
CurrentPart = download.CurrentPart + 1
});
}
catch (Exception e)
{
FireFailedStatus(download.Id, "Downloading", e.Message);
}
},
download => // complete
{
try
{
FileHelper.WriteDownloadedPart(Slave.OutputDirectory, download.Path, download.CurrentPart, download.RawPart);
//TotalTransaction.Content = $"Successful transactions: {++m_sucessfulTransactions}/{m_totalTransactions}";
FireSlaveEvent(SlaveEventType.FileDownloaded, Path.GetFileName(download.Path));
FinishCurrentCommand();
}
catch (Exception e)
{
FireFailedStatus(download.Id, "Downloading", e.Message);
}
},
FinishCurrentCommand // fault
));
m_totalTransactions++;
}