Beispiel #1
0
        private void ConnectToServer(object parameter)
        {
            InputStringDialog dialog = new InputStringDialog();

            _ = dialog.ShowDialog();
            if (dialog.Result == null)
            {
                return;
            }

            IMetadataReader metadataProvider = _shell.GetService <IMetadataReader>();

            string serverName = (string)dialog.Result;
            Server server     = new Server()
            {
                Address = serverName
            };

            if (!metadataProvider.CheckServerConnection(server))
            {
                _ = MessageBox.Show(
                    "Unable to connect server!",
                    ONE_C_SHARP,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                return;
            }

            var treeNode = new TreeNodeViewModel()
            {
                NodeText    = server.Address,
                NodeIcon    = new BitmapImage(new Uri(LOCAL_SERVER)),
                NodePayload = server
            };

            treeNode.ContextMenuItems.Add(new MenuItemViewModel()
            {
                MenuItemHeader  = "Connect to database...",
                MenuItemIcon    = new BitmapImage(new Uri(CONNECT_TO_DATABASE)),
                MenuItemCommand = new AsyncCommand(ConnectToInfoBase, CanExecuteConnectToInfoBase),
                MenuItemPayload = treeNode
            });

            _shell.AddTreeNode(treeNode);
        }