this.fileToSend = fileToSend;
}
@Override
protected IStatus run(IProgressMonitor ipmonitor) {
SubMonitor monitor = SubMonitor.convert(ipmonitor);
monitor.beginTask(Messages.SendFileAction_monitor_set_up_session_text, 101);
setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
log.info("Asking " + user + " to accept our transfer."); //$NON-NLS-1$ //$NON-NLS-2$
monitor.subTask(MessageFormat.format(Messages.SendFileAction_monitor_notifying_text,
user.getHumanReadableName()));
try {
setStreamSession(streamServiceManager.createSession(
sendFileService, user,
FileDescription.fromFile(fileToSend), null));
monitor.worked(1);
} catch (RemoteCancellationException e) {
errorPopup(getName(), Messages.SendFileAction_error_file_transfer_rejected_text, e,
monitor);
return Status.CANCEL_STATUS;
} catch (ConnectionException e) {
errorPopup(getName(), Messages.SendFileAction_error_no_connection_establish_text, e,
monitor);
return Status.CANCEL_STATUS;
} catch (TimeoutException e) {
errorPopup(getName(), Messages.SendFileAction_error_timed_out_text,
e, monitor);
return Status.CANCEL_STATUS;
} catch (ExecutionException e) {
monitor.subTask(MessageFormat.format(Messages.SendFileAction_unexpected_error,
e.getMessage()));
log.error("Unexpected error: ", e); //$NON-NLS-1$
return new Status(IStatus.ERROR, Saros.SAROS,
Messages.SendFileAction_status_could_not_create_session_text, e);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
monitor.setTaskName(Messages.SendFileAction_monitor_sending_text);
try {
send(getStreamSession(), fileToSend,
monitor.newChild(100, SubMonitor.SUPPRESS_SETTASKNAME));
} catch (InterruptedIOException e) {
monitor.subTask(Messages.SendFileAction_monitor_canceled_text);
return Status.CANCEL_STATUS;
} catch (IOException e) {
if (streamException == null) {
// plain IOE
log.error("Error while sending file: ", e); //$NON-NLS-1$
return new Status(IStatus.ERROR, Saros.SAROS,
"Error while sending file", e); //$NON-NLS-1$
} else {
// IOE because stream is down
if (streamException instanceof ReceiverGoneException) {
monitor.subTask(Messages.SendFileAction_monitor_receiver_left_during_transfer_text);
return Status.CANCEL_STATUS;
}
if (streamException instanceof ConnectionException) {
monitor.subTask(Messages.SendFileAction_monitor_lost_connection_text);
return Status.CANCEL_STATUS;
}
log.error("Unexpected error: ", streamException); //$NON-NLS-1$
return new Status(IStatus.ERROR, Saros.SAROS,
Messages.SendFileAction_status_unexpected_error, streamException);
}
} catch (RemoteCancellationException e) {
monitor.subTask(Messages.SendFileAction_monitor_canceled_text);
return Status.CANCEL_STATUS;
} catch (SarosCancellationException e) {
monitor.subTask(Messages.SendFileAction_monitor_canceled_text);
return Status.CANCEL_STATUS;
} finally {
readyToStop.countDown();
monitor.done();
}
monitor.setTaskName(sendSuccessfully ? Messages.SendFileAction_monitor_successful_sent_text
: Messages.SendFileAction_monitor_not_sent_whole_file_text);
return sendSuccessfully ? Status.OK_STATUS : Status.CANCEL_STATUS;
}