Example #1
0
        private void OnSelectedConnectionChanged(Connection previous)
        {
            if (Connection == null)
            {
                return;
            }
            if (Connection == _selectConnectionItem)
            {
                return;
            }
            if (Connection == _addNewConnectionItem)
            {
                Task.Delay(100)
                .ContinueWith(task =>
                {
                    _connection = previous;
                    NotifyOfPropertyChange(() => Connection);
                })
                .ContinueWith(task =>
                {
                    ShowConnectionDialog();
                });
            }
            else
            {
                // Save selected connection to file to enable auto-connect
                var viewModel = new ConnectionViewModel(Runtime, ConnectionType);
                viewModel.SaveConnectionFile(Connection);

                // Invoke delegate that will handle the connection change
                OnConnectionChanged?.Invoke(Connection);
            }
        }
Example #2
0
        /// <summary>
        /// Shows the connection dialog to add or update connection settings.
        /// </summary>
        public void ShowConnectionDialog(Connection connection = null)
        {
            var existing = Connections
                           .Where(x => x != connection)
                           .Select(x => x.Name)
                           .ToArray();

            var viewModel = new ConnectionViewModel(Runtime, ConnectionType)
            {
                DataItem        = connection ?? new Connection(),
                ConnectionNames = existing
            };

            Runtime.Invoke(() =>
            {
                if (Runtime.ShowDialog(viewModel))
                {
                    // Ensure connection has a Name specified
                    if (string.IsNullOrWhiteSpace(viewModel.DataItem.Name))
                    {
                        viewModel.DataItem.Name = viewModel.DataItem.Uri;
                    }

                    // Initialize collection of new connection items
                    var connections = (connection == null)
                        ? new[] { viewModel.DataItem }
                        : new Connection[0];

                    // Reset Connections list
                    connection = connection ?? viewModel.DataItem;
                    InsertConnections(connections, connection);
                }
            });
        }
        /// <summary>
        /// Gets a JSON Web Token via a new Connection dialog.
        /// </summary>
        public void GetJsonWebToken()
        {
            var viewModel = new ConnectionViewModel(Runtime, ConnectionTypes.Jwt)
            {
                DataItem = new Connection()
            };

            if (Runtime.ShowDialog(viewModel, 10, 10))
            {
                EditItem.JsonWebToken = viewModel.DataItem.JsonWebToken;
            }
        }
Example #4
0
        private Connection GetAutoConnection(IEnumerable <Connection> connections = null)
        {
            if (!AutoConnectEnabled)
            {
                return(_selectConnectionItem);
            }

            var viewModel  = new ConnectionViewModel(Runtime, ConnectionType);
            var connection = viewModel.OpenConnectionFile();

            connections = connections ?? Connections;

            // Auto-connect to previous connection, if possible
            return(connections.FirstOrDefault(x => x.Name == connection?.Name)
                   ?? _selectConnectionItem);
        }