예제 #1
0
        private void AddNodesForServer(ServerDefinition server)
        {
            var serverNode = new DatabaseTreeNode
            {
                ServerDefinition = server,
                IsServerNode     = true
            };

            try
            {
                var databases = QueryRunner.GetDatabasesForServer(server);

                var nodes = new List <TreeViewModel <DatabaseTreeNode> >();
                foreach (var db in databases.OrderBy(db => db.DatabaseName))
                {
                    if (Settings.HideSystemDatabases && systemDatabases.Contains(db.DatabaseName))
                    {
                        continue;
                    }

                    var dbNode = new DatabaseTreeNode
                    {
                        IsServerNode       = false,
                        DatabaseDefinition = db,
                    };
                    var dbNodeViewModel = new TreeViewModel <DatabaseTreeNode>(db.DatabaseName, dbNode);
                    dbNodeViewModel.IsChecked = server.SelectedDatabases.Contains(db.DatabaseName);
                    nodes.Add(dbNodeViewModel);
                }

                var serverNodeViewModel = new TreeViewModel <DatabaseTreeNode>($"{server.DisplayName} ({nodes.Count})", serverNode);
                serverNodeViewModel.Children.AddRange(nodes);
                serverNodeViewModel.IsExpanded = false;

                nodes.ForEach(node => node.InitParent(serverNodeViewModel));

                databaseTreeModel.Add(serverNodeViewModel);
            }
            catch (Exception)
            {
                var serverNodeViewModel = new TreeViewModel <DatabaseTreeNode>(server.DisplayName + " (Connection Failed)", serverNode);
                databaseTreeModel.Add(serverNodeViewModel);
            }
        }
예제 #2
0
        private void AddNodesForServer(ServerDefinition server)
        {
            var serverNode = new DatabaseTreeNode
            {
                ServerDefinition = server,
                IsServerNode     = true
            };

            try
            {
                var databases = QueryRunner.GetDatabasesForServer(server);

                var serverNodeViewModel = new TreeViewModel <DatabaseTreeNode>(server.DisplayName, serverNode);
                databaseTreeModel.Add(serverNodeViewModel);

                foreach (var db in databases)
                {
                    if (Settings.Default.HideSystemDatabases && systemDatabases.Contains(db.DatabaseName))
                    {
                        continue;
                    }

                    var dbNode = new DatabaseTreeNode
                    {
                        IsServerNode       = false,
                        DatabaseDefinition = db
                    };
                    var dbNodeViewModel = new TreeViewModel <DatabaseTreeNode>(db.DatabaseName, dbNode);
                    serverNodeViewModel.Children.Add(dbNodeViewModel);
                }
            }
            catch (Exception)
            {
                var serverNodeViewModel = new TreeViewModel <DatabaseTreeNode>(server.DisplayName + " (Connection Failed)", serverNode);
                databaseTreeModel.Add(serverNodeViewModel);
            }

            DatabasesTreeView.Items.Refresh();
        }