Search in sources :

Example 1 with AgentFile

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());
}
Also used : AgentFile(org.netxms.client.server.AgentFile) AgentFile(org.netxms.client.server.AgentFile) File(java.io.File)

Example 2 with AgentFile

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());
    }
}
Also used : ProgressListener(org.netxms.client.ProgressListener) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) AgentFile(org.netxms.client.server.AgentFile) File(java.io.File) AgentFileData(org.netxms.client.AgentFileData) FileInputStream(java.io.FileInputStream)

Example 3 with AgentFile

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 4 with AgentFile

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 5 with AgentFile

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Aggregations

AgentFile (org.netxms.client.server.AgentFile)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 IOException (java.io.IOException)7 PartInitException (org.eclipse.ui.PartInitException)7 NXCException (org.netxms.client.NXCException)7 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)7 File (java.io.File)4 ArrayList (java.util.ArrayList)3 AgentFileData (org.netxms.client.AgentFileData)3 ProgressListener (org.netxms.client.ProgressListener)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ConsoleJobCallingServerJob (org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 GroupMarker (org.eclipse.jface.action.GroupMarker)1