private async Task ProjectUnloading(object sender, EventArgs args)
        {
            _coreShell.AssertIsOnMainThread();

            _unconfiguredProject.ProjectRenamedOnWriter -= ProjectRenamedOnWriter;
            _unconfiguredProject.ProjectUnloading       -= ProjectUnloading;
            _fileWatcher.Dispose();

            if (!_coreShell.Services.FileSystem.DirectoryExists(_projectDirectory))
            {
                return;
            }

            if (_toolsSettings.AlwaysSaveHistory)
            {
                _history.TrySaveToFile(Path.Combine(_projectDirectory, DefaultRHistoryName));
            }

            var rdataPath            = Path.Combine(_projectDirectory, DefaultRDataName);
            var saveDefaultWorkspace = await GetSaveDefaultWorkspace(rdataPath);

            if (!_session.IsHostRunning)
            {
                return;
            }

            Task.Run(async() => {
                if (saveDefaultWorkspace)
                {
                    await _session.SaveWorkspaceAsync(rdataPath);
                }
                await _session.SetDefaultWorkingDirectoryAsync();
            }).SilenceException <RException>().DoNotWait();
        }
Beispiel #2
0
 private async Task SaveWorkspace(string file)
 {
     try {
         await _rSession.SaveWorkspaceAsync(file);
     } catch (RException ex) {
         var message = Resources.SaveWorkspaceFailedMessageFormat.FormatCurrent(file, ex.Message);
         _shell.ShowErrorMessage(message);
     } catch (OperationCanceledException) {
     }
 }
Beispiel #3
0
        private async Task ProjectUnloadingAsync(object sender, EventArgs args)
        {
            await _coreShell.SwitchToMainThreadAsync(new CancellationTokenSource(10000).Token);

            _unconfiguredProject.ProjectRenamedOnWriter -= ProjectRenamedOnWriter;
            _unconfiguredProject.ProjectUnloading       -= ProjectUnloadingAsync;
            _workflow.RSessions.BeforeDisposed          -= BeforeRSessionsDisposed;

            _fileWatcher.Dispose();

            if (!_coreShell.FileSystem().DirectoryExists(_projectDirectory))
            {
                return;
            }

            if (_settings.AlwaysSaveHistory)
            {
                _history.TrySaveToFile(Path.Combine(_projectDirectory, DefaultRHistoryName));
            }

            var rdataPath            = Path.Combine(_projectDirectory, DefaultRDataName);
            var saveDefaultWorkspace = await GetSaveDefaultWorkspace(rdataPath);

            if (!_session.IsHostRunning)
            {
                return;
            }

            Task.Run(async() => {
                if (saveDefaultWorkspace)
                {
                    await _session.SaveWorkspaceAsync(rdataPath);
                }
                await _session.SetDefaultWorkingDirectoryAsync();
            }).SilenceException <RException>().DoNotWait();
        }