/// <summary> /// Fires the <see cref="StatusChanged"/> event. /// </summary> /// <param name="sender">Sender object.</param> protected virtual void OnStatusChanged(MySqlService sender) { if (StatusChanged != null) { StatusChanged(this); } }
/// <summary> /// Initializes a new instance of the <see cref="ServiceMenuGroup"/> class. /// </summary> /// <param name="mySqlBoundService">The service this menu group is bound to.</param> public ServiceMenuGroup(MySqlService mySqlBoundService) { MenuItemsQuantity = 0; _boundService = mySqlBoundService; _statusMenu = new ToolStripMenuItem($"{_boundService.DisplayName} - {_boundService.Status}") { Tag = _boundService.ServiceId }; if (MySqlWorkbench.AllowsExternalConnectionsManagement) { _configureMenu = new ToolStripMenuItem(Resources.ManageInstance); _configureMenu.Click += configureInstanceItem_Click; CreateEditorMenus(); } _separator = new ToolStripSeparator(); var menuItemFont = new Font(_statusMenu.Font, FontStyle.Bold); _statusMenu.Font = menuItemFont; _startMenu = new ToolStripMenuItem(Resources.StartText, Resources.play); _startMenu.Click += start_Click; _stopMenu = new ToolStripMenuItem(Resources.StopText, Resources.stop); _stopMenu.Click += stop_Click; _restartMenu = new ToolStripMenuItem(Resources.RestartText, Resources.restart); _restartMenu.Click += restart_Click; Update(); }
/// <summary> /// Fires the <see cref="MachineServiceListChanged"/> event. /// </summary> /// <param name="machine">Machine instance.</param> /// <param name="service">MySQLService instance.</param> /// <param name="listChangeType">Service list change type.</param> protected virtual void OnMachineServiceListChanged(Machine machine, MySqlService service, ListChangeType listChangeType) { switch (listChangeType) { case ListChangeType.RemoveByEvent: case ListChangeType.RemoveByUser: MachineServiceListChanged?.Invoke(machine, service, listChangeType); if (machine.Services.Count == 0) { ChangeMachine(machine, ListChangeType.RemoveByEvent); } break; case ListChangeType.AutoAdd: if (machine.Services.Count == 1) { ChangeMachine(machine, ListChangeType.AutoAdd); } MachineServiceListChanged?.Invoke(machine, service, listChangeType); break; default: MachineServiceListChanged?.Invoke(machine, service, listChangeType); break; } SaveToFile(); }
/// <summary> /// Fires the <see cref="MachineServiceStatusChangeError"/> event. /// </summary> /// <param name="machine">Machine instance.</param> /// <param name="service">MySQLService instance.</param> /// <param name="ex">Exception thrown while trying to change the service's status.</param> protected virtual void OnMachineServiceStatusChangeError(Machine machine, MySqlService service, Exception ex) { if (MachineServiceStatusChangeError != null) { MachineServiceStatusChangeError(machine, service, ex); } }
/// <summary> /// Fires the <see cref="MachineServiceStatusChanged"/> event. /// </summary> /// <param name="machine">Machine instance.</param> /// <param name="service">MySQLService instance.</param> protected virtual void OnMachineServiceStatusChanged(Machine machine, MySqlService service) { if (MachineServiceStatusChanged != null) { MachineServiceStatusChanged(machine, service); } }
/// <summary> /// Reads machine services 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 UpdateMachineServicesInSettingsFromXml(XElement rootElement) { var machineListElement = rootElement?.Element("MachineList"); if (machineListElement == null || string.IsNullOrEmpty(machineListElement.Value)) { return; } var machineListDoc = new XmlDocument(); machineListDoc.LoadXml(machineListElement.Value); if (machineListDoc.DocumentElement == null) { return; } if (machineListDoc.DocumentElement.ChildNodes.Count == 0) { return; } var temporaryServicesList = new List <MySqlService>(); var machinesListCopy = Settings.Default.MachineList.ToList(); foreach (XmlNode machineNode in machineListDoc.DocumentElement.ChildNodes) { if (machineNode.Attributes == null) { continue; } var machineId = machineNode.Attributes["MachineId"].Value; var machine = machinesListCopy.FirstOrDefault(m => m.MachineId.Equals(machineId, StringComparison.Ordinal)); if (machine == null) { continue; } var servicesListNode = machineNode.SelectSingleNode("descendant::ServicesList"); if (servicesListNode == null || servicesListNode.ChildNodes.Count == 0) { continue; } foreach (XmlNode serviceNode in servicesListNode.ChildNodes) { var service = new MySqlService(); if (serviceNode.Attributes == null || serviceNode.Attributes.Count == 0) { continue; } service.DisplayName = serviceNode.Attributes["DisplayName"].Value; if (bool.TryParse(serviceNode.Attributes["NotifyOnStatusChange"].Value, out var parsedNotifyOnStatusChange)) { service.NotifyOnStatusChange = parsedNotifyOnStatusChange; } service.ServiceName = serviceNode.Attributes["ServiceName"].Value; if (bool.TryParse(serviceNode.Attributes["UpdateTrayIconOnStatusChange"].Value, out var parsedUpdateTrayIconOnStatusChange)) { service.UpdateTrayIconOnStatusChange = parsedUpdateTrayIconOnStatusChange; } temporaryServicesList.Add(service); } machine.Services = temporaryServicesList; } if (machinesListCopy.Count == 0) { return; } Settings.Default.MachineList = machinesListCopy; Settings.Default.Save(); }
/// <summary> /// Fires the <see cref="MachineServiceStatusChangeError"/> event. /// </summary> /// <param name="machine">Machine instance.</param> /// <param name="service">MySQLService instance.</param> /// <param name="ex">Exception thrown while trying to change the service's status.</param> protected virtual void OnMachineServiceStatusChangeError(Machine machine, MySqlService service, Exception ex) { MachineServiceStatusChangeError?.Invoke(machine, service, ex); }
/// <summary> /// Fires the <see cref="MachineServiceStatusChanged"/> event. /// </summary> /// <param name="machine">Machine instance.</param> /// <param name="service">MySQLService instance.</param> protected virtual void OnMachineServiceStatusChanged(Machine machine, MySqlService service) { MachineServiceStatusChanged?.Invoke(machine, service); }