public synchronized void backupNow(boolean synchronous, IProgressMonitor monitor) {

    monitor = Policy.monitorFor(monitor);

    File backupFolder = new File(backupFolderPath);
    if (!backupFolder.exists()) {
      backupFolder.mkdir();
    }

    final TaskDataExportOperation backupJob =
        new TaskDataSnapshotOperation(backupFolderPath, getBackupFileName());
    try {
      if (!synchronous) {
        backupJob.run(monitor);
        removeOldBackups();
      } else {
        IProgressService service = PlatformUI.getWorkbench().getProgressService();
        service.run(false, true, backupJob);
      }
    } catch (InterruptedException e) {
    } catch (Throwable e) {
      if (!errorDisplayed) {
        final Status status =
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                Messages.TaskListBackupManager_Error_occured_during_scheduled_tasklist_backup,
                e);
        errorDisplayed = true;
        if (Display.getCurrent() != null) {
          TasksUiInternal.logAndDisplayStatus(
              Messages.TaskListBackupManager_Scheduled_task_data_backup, status);
        } else {
          PlatformUI.getWorkbench()
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    public void run() {
                      TasksUiInternal.logAndDisplayStatus(
                          Messages.TaskListBackupManager_Scheduled_task_data_backup, status);
                    }
                  });
        }
      }

      // clean up corrupt backup file
      if (backupJob.getDestinationFile() != null) {
        backupJob.getDestinationFile().delete();
      }
    }
  }
Example #2
0
 /** @since 3.9 */
 protected IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) {
   if (!isUser()) {
     return Policy.backgroundMonitorFor(monitor);
   }
   return Policy.subMonitorFor(monitor, ticks);
 }
 public RemoteOperation(IProgressMonitor monitor, TaskRepository taskRepository) {
   this.fMonitor = Policy.monitorFor(monitor);
   this.taskRepository = taskRepository;
 }