Search in sources :

Example 1 with StartServerToAgentFileUploadDialog

use of org.netxms.ui.eclipse.filemanager.dialogs.StartServerToAgentFileUploadDialog in project netxms by netxms.

the class UploadFileToAgent method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    boolean canScheduleFileUpload = (session.getUserSystemRights() & UserAccessRights.SYSTEM_ACCESS_SCHEDULE_FILE_UPLOAD) > 0;
    final StartServerToAgentFileUploadDialog dlg = new StartServerToAgentFileUploadDialog(shell, canScheduleFileUpload);
    if (dlg.open() == Window.OK) {
        final Long[] nodeIdList = nodes.toArray(new Long[nodes.size()]);
        new ConsoleJob(Messages.get().UploadFileToAgent_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

            @Override
            protected String getErrorMessage() {
                return Messages.get().UploadFileToAgent_JobError;
            }

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                boolean multipleFiles = dlg.getServerFiles().size() > 1;
                for (ServerFile sf : dlg.getServerFiles()) {
                    String remoteFileName = dlg.getRemoteFileName();
                    if (!remoteFileName.isEmpty()) {
                        if (// $NON-NLS-1$ //$NON-NLS-2$
                        remoteFileName.endsWith("/") || remoteFileName.endsWith("\\")) {
                            remoteFileName += sf.getName();
                        } else if (multipleFiles) {
                            remoteFileName += "/" + sf.getName();
                        }
                    } else {
                        if (!dlg.isScheduled())
                            remoteFileName = null;
                    }
                    for (int i = 0; i < nodeIdList.length; i++) {
                        if (dlg.isScheduled()) {
                            ScheduledTask task = dlg.getScheduledTask();
                            // $NON-NLS-1$
                            String parameters = sf.getName() + "," + remoteFileName;
                            task.setParameters(parameters);
                            task.setObjectId(nodeIdList[i]);
                            session.addSchedule(task);
                        } else {
                            session.uploadFileToAgent(nodeIdList[i], sf.getName(), remoteFileName, dlg.isCreateJobOnHold());
                        }
                    }
                }
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) StartServerToAgentFileUploadDialog(org.netxms.ui.eclipse.filemanager.dialogs.StartServerToAgentFileUploadDialog) ServerFile(org.netxms.client.server.ServerFile) ScheduledTask(org.netxms.client.ScheduledTask) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NXCSession (org.netxms.client.NXCSession)1 ScheduledTask (org.netxms.client.ScheduledTask)1 ServerFile (org.netxms.client.server.ServerFile)1 StartServerToAgentFileUploadDialog (org.netxms.ui.eclipse.filemanager.dialogs.StartServerToAgentFileUploadDialog)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1