Exemplo n.º 1
0
        public async Task <IInteractiveWindowVisualComponent> GetOrCreateVisualComponent(IInteractiveWindowComponentContainerFactory componentContainerFactory, int instanceId = 0)
        {
            Shell.AssertIsOnMainThread();

            if (ActiveWindow != null)
            {
                // Right now only one instance of interactive window is allowed
                if (instanceId != 0)
                {
                    throw new InvalidOperationException("Right now only one instance of interactive window is allowed");
                }

                return(ActiveWindow);
            }

            var evaluator = RInstallationHelper.VerifyRIsInstalled(Shell, _settings.RBasePath)
                ? new RInteractiveEvaluator(RSession, History, Shell, _settings)
                : (IInteractiveEvaluator) new NullInteractiveEvaluator();

            ActiveWindow = componentContainerFactory.Create(instanceId, evaluator);
            var interactiveWindow = ActiveWindow.InteractiveWindow;

            interactiveWindow.TextView.Closed += (_, __) => evaluator.Dispose();
            _operations.InteractiveWindow      = interactiveWindow;
            await interactiveWindow.InitializeAsync();

            ActiveWindow.Container.UpdateCommandStatus(true);
            return(ActiveWindow);
        }
Exemplo n.º 2
0
 public void CancelEdit()
 {
     Shell.AssertIsOnMainThread();
     EditedConnection?.Reset();
     EditedConnection = null;
     IsEditingNew     = false;
 }
Exemplo n.º 3
0
        private bool TryStartEditing(IConnectionViewModel connection)
        {
            Shell.AssertIsOnMainThread();

            // When 'Edit' button is clicked second time, we close the panel.
            // If panel has changes, offer save the changes.
            if (EditedConnection != null && EditedConnection.HasChanges)
            {
                var dialogResult = Shell.ShowMessage(Resources.ConnectionManager_EditedConnectionHasChanges,
                                                     MessageButtons.YesNoCancel);
                switch (dialogResult)
                {
                case MessageButtons.Yes:
                    Save(EditedConnection);
                    break;

                case MessageButtons.Cancel:
                    return(false);
                }
            }

            var wasEditingConnection = EditedConnection;

            CancelEdit();

            // If it is the same connection that was edited then we came here as a result
            // of a second click on the edit button. Don't start editing it again.
            if (connection != wasEditingConnection)
            {
                EditedConnection     = connection;
                connection.IsEditing = true;
            }
            return(true);
        }
Exemplo n.º 4
0
        public bool TryDelete(IConnectionViewModel connection)
        {
            Shell.AssertIsOnMainThread();
            CancelTestConnection();

            if (connection == null)
            {
                return(false);
            }

            var confirmMessage = connection.IsActive
                ? Resources.ConnectionManager_RemoveActiveConnectionConfirmation.FormatCurrent(connection.Name)
                : Resources.ConnectionManager_RemoveConnectionConfirmation.FormatCurrent(connection.Name);

            var confirm = Shell.ShowMessage(confirmMessage, MessageButtons.YesNo);

            if (confirm == MessageButtons.No)
            {
                return(false);
            }

            if (connection.IsActive)
            {
                try {
                    Shell.ProgressDialog.Show(ct => ConnectionManager.DisconnectAsync(ct), Resources.ConnectionManager_DeleteConnectionProgressBarMessage.FormatInvariant(connection.Name));
                } catch (OperationCanceledException) {
                    return(false);
                }
            }

            var result = ConnectionManager.TryRemove(connection.Name);

            UpdateConnections();
            return(result);
        }
Exemplo n.º 5
0
        public bool TryEdit(IConnectionViewModel connection)
        {
            Shell.AssertIsOnMainThread();
            if (connection == null)
            {
                return(false);
            }

            return(TryStartEditing(connection));
        }
Exemplo n.º 6
0
        public void Edit(IConnectionViewModel connection)
        {
            Shell.AssertIsOnMainThread();
            if (connection == null)
            {
                return;
            }

            TryStartEditing(connection);
        }
Exemplo n.º 7
0
 public void CancelTestConnection()
 {
     Shell.AssertIsOnMainThread();
     if (_testingConnection != null)
     {
         _testingConnection.TestingConnectionCts?.Cancel();
         _testingConnection.TestingConnectionCts      = null;
         _testingConnection.IsTestConnectionSucceeded = false;
         _testingConnection.TestConnectionFailedText  = null;
     }
 }
Exemplo n.º 8
0
        public Task <IInteractiveWindowVisualComponent> GetOrCreateVisualComponentAsync(int instanceId = 0)
        {
            Shell.AssertIsOnMainThread();

            if (_visualComponentTcs == null)
            {
                _visualComponentTcs = new TaskCompletionSource <IInteractiveWindowVisualComponent>();
                CreateVisualComponentAsync(instanceId).DoNotWait();
            }
            else if (instanceId != 0)
            {
                // Right now only one instance of interactive window is allowed
                throw new InvalidOperationException("Right now only one instance of interactive window is allowed");
            }

            return(_visualComponentTcs.Task);
        }
Exemplo n.º 9
0
        public async Task TestConnectionAsync(IConnectionViewModel connection)
        {
            Shell.AssertIsOnMainThread();
            if (connection == null)
            {
                return;
            }

            CancelTestConnection();

            connection.TestingConnectionCts = new CancellationTokenSource();
            _testingConnection = connection;

            try {
                await ConnectionManager.TestConnectionAsync(connection, connection.TestingConnectionCts.Token);

                connection.IsTestConnectionSucceeded = true;
            } catch (ArgumentException) {
                if (connection.TestingConnectionCts != null)
                {
                    connection.TestConnectionFailedText = Resources.ConnectionManager_TestConnectionFailed_PathIsInvalid;
                }
            } catch (RHostDisconnectedException exception) {
                if (connection.TestingConnectionCts != null)
                {
                    connection.TestConnectionFailedText = Resources.ConnectionManager_TestConnectionFailed_Format.FormatInvariant(exception.Message);
                }
            } catch (ComponentBinaryMissingException) {
                if (connection.TestingConnectionCts != null)
                {
                    connection.TestConnectionFailedText = Resources.ConnectionManager_TestConnectionFailed_RHostIsMissing;
                }
            } catch (OperationCanceledException) {
                if (connection.TestingConnectionCts != null)
                {
                    connection.TestConnectionFailedText = Resources.ConnectionManager_TestConnectionCanceled;
                }
            } finally {
                connection.TestingConnectionCts?.Dispose();
                connection.TestingConnectionCts = null;
                _testingConnection = null;
            }
        }
Exemplo n.º 10
0
        public void BrowseLocalPath(IConnectionViewModel connection)
        {
            Shell.AssertIsOnMainThread();
            if (connection == null)
            {
                return;
            }

            string latestLocalPath;
            Uri    latestLocalPathUri;

            if (connection.Path != null && Uri.TryCreate(connection.Path, UriKind.Absolute, out latestLocalPathUri) &&
                latestLocalPathUri.IsFile && !latestLocalPathUri.IsUnc)
            {
                latestLocalPath = latestLocalPathUri.LocalPath;
            }
            else
            {
                latestLocalPath = Environment.SystemDirectory;

                try {
                    latestLocalPath = new RInstallation().GetCompatibleEngines().FirstOrDefault()?.InstallPath;
                    if (string.IsNullOrEmpty(latestLocalPath) || !Directory.Exists(latestLocalPath))
                    {
                        // Force 64-bit PF
                        latestLocalPath = Environment.GetEnvironmentVariable("ProgramW6432");
                    }
                } catch (ArgumentException) { } catch (IOException) { }
            }

            var path = Shell.FileDialog.ShowBrowseDirectoryDialog(latestLocalPath);

            if (path != null)
            {
                // Verify path
                var ri = new RInterpreterInfo(string.Empty, path);
                if (ri.VerifyInstallation(null, null, Shell))
                {
                    connection.Path = path;
                }
            }
        }
Exemplo n.º 11
0
        public void Save(IConnectionViewModel connectionViewModel)
        {
            Shell.AssertIsOnMainThread();
            if (connectionViewModel == null || !connectionViewModel.HasChanges)
            {
                return;
            }

            if ((connectionViewModel.IsRenamed || IsEditingNew) &&
                ConnectionManager.GetConnection(connectionViewModel.Name) != null)
            {
                Shell.ShowMessage(Resources.ConnectionManager_CantSaveWithTheSameName.FormatCurrent(connectionViewModel.Name), MessageButtons.OK);
                return;
            }

            if (connectionViewModel.IsConnected)
            {
                var confirm = Shell.ShowMessage(Resources.ConnectionManager_RenameActiveConnectionConfirmation.FormatCurrent(connectionViewModel.OriginalName), MessageButtons.YesNo);
                if (confirm == MessageButtons.Yes)
                {
                    var message = Resources.ConnectionManager_RenameConnectionProgressBarMessage.FormatInvariant(connectionViewModel.OriginalName, connectionViewModel.Name);
                    try {
                        Shell.ProgressDialog.Show(ct => ConnectionManager.DisconnectAsync(ct), message);
                    } catch (OperationCanceledException) {
                        return;
                    }
                }
            }

            ConnectionManager.AddOrUpdateConnection(connectionViewModel);

            if (connectionViewModel.IsRenamed)
            {
                ConnectionManager.TryRemove(connectionViewModel.OriginalName);
            }

            EditedConnection = null;
            IsEditingNew     = false;
            UpdateConnections();
        }
Exemplo n.º 12
0
        public void Connect(IConnectionViewModel connection, bool connectToEdited)
        {
            Shell.AssertIsOnMainThread();
            if (connection == null || !connection.IsValid)
            {
                return;
            }

            if (connection != EditedConnection)
            {
                CancelEdit();
            }
            else if (connectToEdited)
            {
                connection.UpdatePath();
                Save(connection);
            }
            else
            {
                return;
            }

            CancelTestConnection();

            if (connection.IsActive && !IsConnected)
            {
                Shell.ProgressDialog.Show(ConnectionManager.ReconnectAsync, Resources.ConnectionManager_ReconnectionToProgressBarMessage.FormatInvariant(connection.Name));
            }
            else
            {
                var activeConnection   = ConnectionManager.ActiveConnection;
                var connectionToSwitch = ConnectionManager.GetConnection(connection.Name);
                if (activeConnection != null && connectionToSwitch.BrokerConnectionInfo == activeConnection.BrokerConnectionInfo)
                {
                    var text = Resources.ConnectionManager_ConnectionsAreIdentical.FormatCurrent(activeConnection.Name, connection.Name);
                    Shell.ShowMessage(text, MessageButtons.OK);
                }
                else
                {
                    var connect = true;
                    if (activeConnection != null && _settings.ShowWorkspaceSwitchConfirmationDialog == YesNo.Yes)
                    {
                        var message = Resources.ConnectionManager_SwitchConfirmation.FormatCurrent(activeConnection.Name, connection.Name);
                        if (Shell.ShowMessage(message, MessageButtons.YesNo) == MessageButtons.No)
                        {
                            connect = false;
                        }
                    }

                    if (connect)
                    {
                        var progressBarMessage = activeConnection != null
                            ? Resources.ConnectionManager_SwitchConnectionProgressBarMessage.FormatCurrent(activeConnection.Name, connection.Name)
                            : Resources.ConnectionManager_ConnectionToProgressBarMessage.FormatCurrent(connection.Name);

                        Shell.ProgressDialog.Show(ct => ConnectionManager.ConnectAsync(connection, ct), progressBarMessage);
                    }
                }
            }

            UpdateConnections();
        }
Exemplo n.º 13
0
 public bool TryEditNew()
 {
     Shell.AssertIsOnMainThread();
     IsEditingNew = TryStartEditing(new ConnectionViewModel());
     return(IsEditingNew);
 }
Exemplo n.º 14
0
 public void EditNew()
 {
     Shell.AssertIsOnMainThread();
     IsEditingNew = TryStartEditing(new ConnectionViewModel());
 }