/// <summary>
        /// Initializes a new instance of the <see cref="MySqlInstanceMenuGroup"/> class.
        /// </summary>
        /// <param name="boundInstance">The MySQL instance that this menu group is associated to.</param>
        public MySqlInstanceMenuGroup(MySqlInstance boundInstance)
        {
            BoundInstance    = boundInstance;
            InstanceMenuItem = new ToolStripMenuItem();
            var menuItemFont = new Font(InstanceMenuItem.Font, FontStyle.Bold);

            InstanceMenuItem.Font = menuItemFont;
            InstanceMenuItem.Tag  = boundInstance.InstanceId;
            if (MySqlWorkbench.AllowsExternalConnectionsManagement)
            {
                ConfigureMenuItem        = new ToolStripMenuItem(Resources.ManageInstance);
                ConfigureMenuItem.Click += ConfigureMenuItem_Click;
            }

            RecreateSqlEditorMenus();
            Separator = new ToolStripSeparator();
            Update(false);
        }
예제 #2
0
        /// <summary>
        /// Reads MySQL instances directly from the XML configuration file to update the settings object.
        /// </summary>
        /// <param name="rootElement">The root element of the configuration file.</param>
        private static void UpdateMySqlInstancesInSettingsFromXml(XElement rootElement)
        {
            var mySqlInstancesListElement = rootElement?.Element("MySQLInstancesList");

            if (mySqlInstancesListElement == null || string.IsNullOrEmpty(mySqlInstancesListElement.Value))
            {
                return;
            }

            var mySqlInstancesListDoc = new XmlDocument();

            mySqlInstancesListDoc.LoadXml(mySqlInstancesListElement.Value);
            if (mySqlInstancesListDoc.DocumentElement == null)
            {
                return;
            }

            if (mySqlInstancesListDoc.DocumentElement.ChildNodes.Count == 0)
            {
                return;
            }

            var temporaryInstancesList = new List <MySqlInstance>();

            foreach (XmlNode instanceNode in mySqlInstancesListDoc.DocumentElement.ChildNodes)
            {
                if (instanceNode.Attributes == null || instanceNode.Attributes.Count == 0)
                {
                    continue;
                }

                var instance = new MySqlInstance
                {
                    HostName = instanceNode.Attributes["HostName"].Value
                };
                if (bool.TryParse(instanceNode.Attributes["MonitorAndNotifyStatus"].Value, out var parsedMonitorAndNotifyStatus))
                {
                    instance.MonitorAndNotifyStatus = parsedMonitorAndNotifyStatus;
                }

                if (uint.TryParse(instanceNode.Attributes["MonitoringInterval"].Value, out var parsedInterval))
                {
                    instance.MonitoringInterval = parsedInterval;
                }

                if (Enum.TryParse(instanceNode.Attributes["MonitoringIntervalUnitOfMeasure"].Value, out TimeUtilities.IntervalUnitOfMeasure parsedIntervalUnitOfMeasure))
                {
                    instance.MonitoringIntervalUnitOfMeasure = parsedIntervalUnitOfMeasure;
                }

                if (uint.TryParse(instanceNode.Attributes["Port"].Value, out var parsedPort))
                {
                    instance.Port = parsedPort;
                }

                if (bool.TryParse(instanceNode.Attributes["UpdateTrayIconOnStatusChange"].Value, out var parsedUpdateTrayIconOnStatusChange))
                {
                    instance.UpdateTrayIconOnStatusChange = parsedUpdateTrayIconOnStatusChange;
                }

                instance.WorkbenchConnectionId = instanceNode.Attributes["WorkbenchConnectionId"].Value;
                temporaryInstancesList.Add(instance);
            }

            if (temporaryInstancesList.Count == 0)
            {
                return;
            }

            Settings.Default.MySQLInstancesList = temporaryInstancesList;
            Settings.Default.Save();
        }