use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method downloadDir.
/**
* Recursively download directory from agent to local pc
*
* @param sf
* @param localFileName
* @param job
* @throws IOException
* @throws NXCException
*/
private void downloadDir(final AgentFile sf, String localFileName, final IProgressMonitor monitor, ConsoleJobCallingServerJob job) throws NXCException, IOException {
File dir = new File(localFileName);
dir.mkdir();
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()) {
// $NON-NLS-1$
downloadDir(f, localFileName + "/" + f.getName(), monitor, job);
} else {
// $NON-NLS-1$
downloadFile(f, localFileName + "/" + f.getName(), monitor, true, job);
}
}
dir.setLastModified(sf.getModifyicationTime().getTime());
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method downloadFile.
/**
* Downloads file
* @throws NXCException
* @throws IOException
*/
private void downloadFile(final AgentFile sf, final String localName, final IProgressMonitor monitor, final boolean subTask, ConsoleJobCallingServerJob job) throws IOException, NXCException {
if (subTask)
monitor.subTask(String.format("Downloading file %s", sf.getFullName()));
final AgentFileData file = session.downloadFileFromAgent(objectId, sf.getFullName(), 0, false, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
if (!subTask)
monitor.beginTask(String.format("Downloading file %s", sf.getFullName()), (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, job);
if (file.getFile() != null) {
File outputFile = new File(localName);
outputFile.createNewFile();
InputStream in = new FileInputStream(file.getFile());
OutputStream out = new FileOutputStream(outputFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
outputFile.setLastModified(sf.getModifyicationTime().getTime());
}
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method deleteFile.
/**
* Delete selected file
*/
private void deleteFile() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().ViewServerFile_DeleteConfirmation, Messages.get().ViewServerFile_DeletAck))
return;
final Object[] objects = selection.toArray();
new ConsoleJob(Messages.get().ViewServerFile_DeletFileFromServerJob, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
@Override
protected String getErrorMessage() {
return Messages.get().ViewServerFile_ErrorDeleteFileJob;
}
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
for (int i = 0; i < objects.length; i++) {
final AgentFile sf = (AgentFile) objects[i];
session.deleteAgentFile(objectId, sf.getFullName());
runInUIThread(new Runnable() {
@Override
public void run() {
sf.getParent().removeChield(sf);
viewer.refresh(sf.getParent());
}
});
}
}
}.start();
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method refreshFileOrDirectory.
/**
* Refresh file list
*/
private void refreshFileOrDirectory() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
final Object[] objects = selection.toArray();
new ConsoleJob("Reading remote directory", null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
for (int i = 0; i < objects.length; i++) {
if (!((AgentFile) objects[i]).isDirectory())
objects[i] = ((AgentFile) objects[i]).getParent();
final AgentFile sf = ((AgentFile) objects[i]);
sf.setChildren(session.listAgentFiles(sf, sf.getFullName(), objectId));
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.refresh(sf);
}
});
}
}
@Override
protected String getErrorMessage() {
return "Cannot read remote directory";
}
}.start();
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method calculateFolderSize.
/**
* Show file size
*/
private void calculateFolderSize() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
final List<AgentFile> files = new ArrayList<AgentFile>(selection.size());
for (Object o : selection.toList()) files.add((AgentFile) o);
new ConsoleJob("Calculate folder size", this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
for (AgentFile f : files) {
f.setFileInfo(session.getAgentFileInfo(f));
}
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.update(files.toArray(), null);
}
});
}
@Override
protected String getErrorMessage() {
return "Cannot calculate folder size";
}
}.start();
}
Aggregations