/// <summary>
        /// Fetches all schema names from the current connection and loads them in the <see cref="SchemasList"/> tree.
        /// </summary>
        /// <returns><c>true</c> if schemas were loaded successfully, <c>false</c> otherwise.</returns>
        private bool LoadSchemas()
        {
            if (SchemasList.HeaderNodes.Count < 2)
            {
                return(false);
            }

            try
            {
                // Avoids flickering of schemas list while adding the items to it.
                SchemasList.BeginUpdate();

                LoadedSchemas.ForEach(schema => schema.Dispose());
                LoadedSchemas.Clear();
                foreach (TreeNode node in SchemasList.Nodes)
                {
                    node.Nodes.Clear();
                }

                DataTable databases = _wbConnection.GetSchemaCollection("Databases", null);
                foreach (DataRow row in databases.Rows)
                {
                    string schemaName = row["DATABASE_NAME"].ToString();

                    // If the user has specified a filter then check it
                    if (!string.IsNullOrEmpty(_filter) && !schemaName.ToUpper().Contains(_filter))
                    {
                        continue;
                    }

                    // Create the DbSchema and MySqlListViewNode objects
                    var    schemaObject = new DbSchema(_wbConnection, schemaName, row["DEFAULT_CHARACTER_SET_NAME"].ToString(), row["DEFAULT_COLLATION_NAME"].ToString(), DisplaySchemaCollationsToolStripMenuItem.Checked);
                    string lcSchemaName = schemaName.ToLowerInvariant();
                    var    headerNode   = SchemasList.HeaderNodes[_systemSchemasListValues.Contains(lcSchemaName) ? 1 : 0];
                    LoadedSchemas.Add(schemaObject);
                    var node = SchemasList.AddDbObjectNode(headerNode, schemaObject);
                    node.ImageIndex = DisplaySchemaCollationsToolStripMenuItem.Checked ? 1 : 0;
                }

                if (SchemasList.Nodes[0].GetNodeCount(true) > 0)
                {
                    SchemasList.Nodes[0].Expand();
                }

                // Avoids flickering of schemas list while adding the items to it.
                SchemasList.EndUpdate();

                return(true);
            }
            catch (Exception ex)
            {
                MiscUtilities.ShowCustomizedErrorDialog(Resources.SchemasLoadingErrorTitle, ex.Message, true);
                MySqlSourceTrace.WriteAppErrorToLog(ex);
                return(false);
            }
        }
        /// <summary>
        /// Sets the appearance of <see cref="MySqlListViewNode"/> objects appearing in the <see cref="SchemasList"/>.
        /// </summary>
        /// <param name="refreshSchemasList">Flag indicating whether the <see cref="SchemasList"/> must be refreshed after resetting the appearance.</param>
        private void SetItemsAppearance(bool refreshSchemasList)
        {
            var displayCollations = DisplaySchemaCollationsToolStripMenuItem.Checked;

            if (Settings.Default.SchemasDisplayCollations != displayCollations)
            {
                Settings.Default.SchemasDisplayCollations = displayCollations;
                MiscUtilities.SaveSettings();
            }

            SchemasList.ClearHeaderNodes();
            SchemasList.SetItemsAppearance(displayCollations, false);
            SchemasList.AddHeaderNode("Schemas");
            SchemasList.AddHeaderNode("System Schemas");
            if (refreshSchemasList)
            {
                RefreshSchemasToolStripMenuItem_Click(null, EventArgs.Empty);
            }
        }
        public SchemasList ListSchemas(bool recursive)
        {
            PInvokes.GSettingsSchemaSource.ListSchemas(
                GSettingsSchemaSourcePtr,
                recursive,
                out IntPtr nonRelocatableSchemas,
                out IntPtr relocatableSchemas);

            var schemas = new SchemasList();

            if (nonRelocatableSchemas != IntPtr.Zero)
            {
                schemas.NonRelocatable.AddRange(Utilities.MarshalUtility.MarshalStringArray(nonRelocatableSchemas));
            }

            if (relocatableSchemas != IntPtr.Zero)
            {
                schemas.Relocatable.AddRange(Utilities.MarshalUtility.MarshalStringArray(relocatableSchemas));
            }

            return(schemas);
        }
        /// <summary>
        /// Fetches all schema names from the current connection and loads them in the <see cref="SchemasList"/> tree.
        /// </summary>
        /// <returns><c>true</c> if schemas were loaded successfully, <c>false</c> otherwise.</returns>
        private bool LoadSchemas()
        {
            if (SchemasList.HeaderNodes.Count < 2)
            {
                return(false);
            }

            Cursor = Cursors.WaitCursor;
            try
            {
                // Avoids flickering of schemas list while adding the items to it.
                SchemasList.BeginUpdate();

                LoadedSchemas.ForEach(schema => schema.Dispose());
                LoadedSchemas.Clear();
                foreach (TreeNode node in SchemasList.Nodes)
                {
                    node.Nodes.Clear();
                }

                var databases = _wbConnection.GetSchemaInformation(SchemaInformationType.Databases, false, null);
                foreach (DataRow row in databases.Rows)
                {
                    var schemaName = row["DATABASE_NAME"].ToString();

                    // If the user has specified a filter then check it
                    if (!string.IsNullOrEmpty(_filter) && !schemaName.ToUpper().Contains(_filter))
                    {
                        continue;
                    }

                    // Create the DbSchema and MySqlListViewNode objects
                    var schemaObject = new DbSchema(_wbConnection, schemaName,
                                                    row["DEFAULT_CHARACTER_SET_NAME"].ToString(),
                                                    row["DEFAULT_COLLATION_NAME"].ToString(),
                                                    DisplaySchemaCollationsToolStripMenuItem.Checked);
                    var lcSchemaName = schemaName.ToLowerInvariant();
                    var headerNode   = SchemasList.HeaderNodes[MySqlWorkbenchConnection.SystemSchemaNames.Contains(lcSchemaName) ? 1 : 0];
                    LoadedSchemas.Add(schemaObject);
                    var node = SchemasList.AddDbObjectNode(headerNode, schemaObject);
                    node.ImageIndex = DisplaySchemaCollationsToolStripMenuItem.Checked ? 1 : 0;
                }

                if (SchemasList.Nodes[0].GetNodeCount(true) > 0)
                {
                    SchemasList.Nodes[0].Expand();
                }

                // Avoids flickering of schemas list while adding the items to it.
                SchemasList.EndUpdate();

                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, true, Resources.SchemasLoadingErrorTitle);
                return(false);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }