use of org.netxms.client.ProgressListener in project netxms by netxms.
the class AgentFileManager method tailFile.
/**
* Starts file tail
*/
private void tailFile(final boolean followChanges, final int offset) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
final Object[] objects = selection.toArray();
if (((AgentFile) objects[0]).isDirectory())
return;
final AgentFile sf = ((AgentFile) objects[0]);
ConsoleJobCallingServerJob job = new ConsoleJobCallingServerJob(Messages.get().AgentFileManager_DownloadJobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return String.format(Messages.get().AgentFileManager_DownloadJobError, sf.getFullName(), objectId);
}
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
final AgentFileData file = session.downloadFileFromAgent(objectId, sf.getFullName(), offset, followChanges, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask("Download file " + sf.getFullName(), (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, this);
runInUIThread(new Runnable() {
@Override
public void run() {
try {
// $NON-NLS-1$ //$NON-NLS-2$
String secondaryId = Long.toString(objectId) + "&" + URLEncoder.encode(sf.getName(), "UTF-8");
AgentFileViewer.createView(secondaryId, objectId, file, followChanges);
} catch (Exception e) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MessageDialogHelper.openError(window.getShell(), Messages.get().AgentFileManager_Error, String.format(Messages.get().AgentFileManager_OpenViewError, e.getLocalizedMessage()));
Activator.logError("Exception in AgentFileManager.tailFile", e);
}
}
});
}
};
job.start();
}
use of org.netxms.client.ProgressListener in project netxms by netxms.
the class AgentFileManager method downloadDir.
/**
* Recursively download directory from agent to local pc
*
* @param sf
* @param localFileName
* @throws IOException
* @throws NXCException
*/
private void downloadDir(final AgentFile sf, String localFileName, ZipOutputStream zos, final IProgressMonitor monitor, ConsoleJobCallingServerJob job) throws NXCException, IOException {
List<AgentFile> files = sf.getChildren();
if (files == null) {
files = session.listAgentFiles(sf, sf.getFullName(), sf.getNodeId());
sf.setChildren(files);
}
for (AgentFile f : files) {
if (job.isCanceled())
break;
if (f.isDirectory()) {
downloadDir(f, localFileName + "/" + f.getName(), zos, monitor, job);
} else {
monitor.subTask(String.format("Compressing file %s", f.getFullName()));
final AgentFileData file = session.downloadFileFromAgent(objectId, f.getFullName(), 0, false, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, job);
if (file != null && file.getFile() != null) {
FileInputStream fis = new FileInputStream(file.getFile());
ZipEntry zipEntry = new ZipEntry(localFileName + "/" + f.getName());
zos.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zos.write(bytes, 0, length);
}
zos.closeEntry();
fis.close();
}
}
}
}
use of org.netxms.client.ProgressListener in project netxms by netxms.
the class AgentFileManager method downloadFile.
/**
* Downloads file
* @throws NXCException
* @throws IOException
*/
private void downloadFile(final String remoteName) {
ConsoleJobCallingServerJob job = new ConsoleJobCallingServerJob(Messages.get().SelectServerFileDialog_JobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
final AgentFileData file = session.downloadFileFromAgent(objectId, remoteName, 0, false, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask("Downloading file " + remoteName, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, this);
if (file != null && file.getFile() != null) {
DownloadServiceHandler.addDownload(file.getFile().getName(), remoteName, file.getFile(), "application/octet-stream");
runInUIThread(new Runnable() {
@Override
public void run() {
DownloadServiceHandler.startDownload(file.getFile().getName());
}
});
}
}
@Override
protected String getErrorMessage() {
return Messages.get().AgentFileManager_DirectoryReadError;
}
};
job.setUser(false);
job.start();
}
use of org.netxms.client.ProgressListener in project netxms by netxms.
the class ServerFileManager method createFile.
/**
* Create new file
*/
private void createFile() {
final StartClientToServerFileUploadDialog dlg = new StartClientToServerFileUploadDialog(getSite().getShell());
if (dlg.open() == Window.OK) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().UploadFileToServer_JobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
List<File> fileList = dlg.getLocalFiles();
for (int i = 0; i < fileList.size(); i++) {
final File localFile = fileList.get(i);
String remoteFile = fileList.get(i).getName();
if (fileList.size() == 1)
remoteFile = dlg.getRemoteFileName();
session.uploadFileToServer(localFile, remoteFile, new ProgressListener() {
private long prevWorkDone = 0;
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask(Messages.get(getDisplay()).UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(), (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) (workDone - prevWorkDone));
prevWorkDone = workDone;
}
});
monitor.done();
}
}
@Override
protected String getErrorMessage() {
return Messages.get().UploadFileToServer_JobError;
}
}.start();
}
}
use of org.netxms.client.ProgressListener in project netxms by netxms.
the class DynamicFileViewer method restartTracking.
/**
* Restart tracking after failure
*/
private void restartTracking() {
if (monitoringJob != null) {
monitoringJob.cancel();
monitoringJob = null;
}
if (restartJob != null)
restartJob.cancel();
text.append(// $NON-NLS-1$
"\n\n" + // $NON-NLS-1$
"----------------------------------------------------------------------\n" + Messages.get().FileViewer_NotifyFollowConnectionLost + // $NON-NLS-1$
"\n----------------------------------------------------------------------\n");
showMessage(ERROR, Messages.get().FileViewer_NotifyFollowConnectionLost);
restartJob = new ConsoleJobCallingServerJob(Messages.get().DynamicFileViewer_RestartFileTracking, null, Activator.PLUGIN_ID, null) {
private boolean running = true;
@Override
protected void canceling() {
running = false;
}
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
// Try to reconnect in every 20 seconds
while (running) {
try {
final AgentFileData file = session.downloadFileFromAgent(nodeId, remoteFileName, 1024, true, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask("Track file " + remoteFileName, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, this);
// When successfully connected - display notification to client.
runInUIThread(new Runnable() {
@Override
public void run() {
if (text.isDisposed()) {
running = false;
return;
}
hideMessage();
text.append(// $NON-NLS-1$
"-------------------------------------------------------------------------------\n" + Messages.get().FileViewer_NotifyFollowConnectionEnabed + // $NON-NLS-1$
"\n-------------------------------------------------------------------------------\n\n");
append(loadFile(file.getFile()));
startTracking(nodeId, fileId, remoteFileName);
}
});
break;
} catch (Exception e) {
}
Thread.sleep(20000);
}
}
@Override
protected String getErrorMessage() {
return Messages.get().DynamicFileViewer_CannotRestartFileTracking;
}
};
restartJob.setUser(false);
restartJob.setSystem(true);
restartJob.start();
}
Aggregations