private void SyncSelectedObjects(TreeNode selectedNode, bool nodeChecked)
        {
            if ((selectedNode == this.siteTree.TopNode) ||
                 (null == this.siteTree.Tag))
            {
                return;
            }

            SelectedObjects selectedObjs = (SelectedObjects)this.siteTree.Tag;
            Type objectType = selectedNode.Tag.GetType();

            //
            // Add or remove selected items from the selected objects list.
            //
            if (nodeChecked) {
                if(typeof(string) == objectType && selectedNode.Tag == "AddDB")
                {
                    AddDbConnectionDialog dbDialog = new AddDbConnectionDialog();
                    if(dbDialog.ShowDialog() == DialogResult.OK)
                    {
                        string dbConnectionString = dbDialog.textBoxDbConnectionString.Text.Trim();
                        try
                        {
                            var dbConn = new DbConnectionStringBuilder { ConnectionString = dbConnectionString };
                            // dbConn.ConnectionString = dbConnectionString;
                            if (dbConn.ContainsKey("Provider") && (dbConn["Provider"].ToString() == "SQLOLEDB" || dbConn["Provider"].ToString().Contains("SQLNCLI")))
                            {
                                dbConn.Remove("Provider");
                            }

                            var sqlConn = new SqlConnectionStringBuilder(dbConn.ConnectionString);

                            //sqlConn.ConnectionString = dbConnectionString;
                            Site site = (Site)selectedNode.Parent.Tag;
                            Database db = new Database("", sqlConn.InitialCatalog, sqlConn.ConnectionString) { ParentSite = site };
                            site.Add(db);
                            selectedNode.Tag = db;
                            objectType = typeof(Database);
                        }
                        catch (System.ArgumentException ex)
                        {
                            string message = "Invalid connection string.\r\n\r\nValid connection string should be like\r\n 'Data Source=<servername>; Initial Catalog=<intialCatalog>; Trusted_Connection=<Yes|No>'";
                            MessageBox.Show(message);
                            selectedNode.Tag = "AddDB";
                            selectedNode.Checked = false;
                            TraceHelper.Tracer.WriteTrace(message);
                            return;
                        }
                    }
                    else
                    {
                        selectedNode.Tag = "AddDB";
                        selectedNode.Checked = false;
                        return;
                    }

                }
                //
                // If this is a child node, and it's been checked, make sure its
                // parent nodes are checked.
                //
                TreeNode nodeParent = selectedNode.Parent;
                while (null != nodeParent) {
                    if (!nodeParent.Checked) {
                        nodeParent.Checked = true;
                    }
                    nodeParent = nodeParent.Parent;
                }

                if (typeof(Site) == objectType) {
                    if (!selectedObjs.SelectedSites.Contains((Site)selectedNode.Tag)) {
                        selectedObjs.SelectedSites.Add((Site)selectedNode.Tag);
                    }
                    // It's actually not possible to check (enable) anything
                    // in the tree without at least one site being checked.
                    this.StartButton.Enabled = true;
                }
                else if (typeof(Database) == objectType)
                {
                    if (!selectedObjs.SelectedDatabases.Contains((Database)selectedNode.Tag))
                    {
                        selectedObjs.SelectedDatabases.Add((Database)selectedNode.Tag);
                    }
                }
                else if (typeof(IISServer) == objectType)
                {
                    if (!selectedObjs.SelectedServers.Contains((IISServer)selectedNode.Tag))
                    {
                        selectedObjs.SelectedServers.Add((IISServer)selectedNode.Tag);
                    }
                }
            }
            else
            {
                if (typeof(Site) == objectType)
                {
                    if (selectedObjs.SelectedSites.Contains((Site)selectedNode.Tag))
                    {
                        selectedObjs.SelectedSites.Remove((Site)selectedNode.Tag);
                    }
                }
                else if (typeof(Database) == objectType)
                {
                    if (selectedObjs.SelectedDatabases.Contains((Database)selectedNode.Tag))
                    {
                        selectedObjs.SelectedDatabases.Remove((Database)selectedNode.Tag);
                    }
                }
                else if (typeof(IISServer) == objectType)
                {
                    if (!selectedObjs.SelectedServers.Contains((IISServer)selectedNode.Tag))
                    {
                        selectedObjs.SelectedServers.Remove((IISServer)selectedNode.Tag);
                    }
                }
                this.StartButton.Enabled = (0 != selectedObjs.SelectedSites.Count());
            }
        }
 public void Add(Database db)
 {
     _databases.Add(db);
 }