/// <summary> /// Event delegate method fired when the <see cref="DeleteButton"/> button is clicked. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void DeleteButton_Click(object sender, EventArgs e) { switch (_selectedItem) { case null: return; case MySqlService selectedService: { var machine = MachinesList.GetMachineById(selectedService.Host.MachineId); machine.ChangeService(selectedService, ListChangeType.RemoveByUser); MonitoredServicesListView.Items.RemoveAt(MonitoredServicesListView.SelectedIndices[0]); break; } case MySqlInstance selectedInstance: { if (InstancesList.Remove(selectedInstance)) { MonitoredInstancesListView.Items.RemoveAt(MonitoredInstancesListView.SelectedIndices[0]); } break; } } }
/// <summary> /// Removes the element at the specified index of the list. /// </summary> /// <param name="index">The zero-based index of the element to remove.</param> public void RemoveAt(int index) { MySqlInstance instance = InstancesList[index]; InstancesList.RemoveAt(index); SaveToFile(); OnInstancesListChanged(instance, ListChangedType.ItemDeleted); }
/// <summary> /// Inserts an itemText to the list at the specified index. /// </summary> /// <param name="index">The zero-based index at which <seealso cref="item"/> should be inserted.</param> /// <param name="item">The <see cref="MySqlInstance"/> object to insert to the list.</param> public void Insert(int index, MySqlInstance item) { InstancesList.Insert(index, item); item.InstanceStatusChanged += SingleInstanceStatusChanged; item.PropertyChanged += SingleInstancePropertyChanged; item.InstanceConnectionStatusTestErrorThrown += SingleInstanceConnectionStatusTestErrorThrown; SaveToFile(); OnInstancesListChanged(item, ListChangedType.ItemAdded); }
private void LateUpdate() { if (ShouldDestroy) { foreach (DropItemController dropItemController in InstancesList) { Destroy(dropItemController); } InstancesList.Clear(); ShouldDestroy = false; } }
/// <summary> /// Adds a <see cref="MySqlInstance"/> object to the end of the list. /// </summary> /// <param name="item">A <see cref="MySqlInstance"/> object to add.</param> public void Add(MySqlInstance item) { InstancesList.Add(item); item.InstanceStatusChanged += SingleInstanceStatusChanged; item.PropertyChanged += SingleInstancePropertyChanged; item.InstanceConnectionStatusTestErrorThrown += SingleInstanceConnectionStatusTestErrorThrown; if (item.ConnectionStatus == MySqlWorkbenchConnection.ConnectionStatusType.Unknown) { item.CheckInstanceStatus(false); } SaveToFile(); OnInstancesListChanged(item, ListChangedType.ItemAdded); }
/// <summary> /// Updates instances connection timeouts. /// </summary> public void UpdateInstancesConnectionTimeouts() { if (_instancesRefreshing) { return; } var monitoredInstances = InstancesList.Where(instance => instance.MonitorAndNotifyStatus); foreach (var instance in monitoredInstances) { instance.SecondsToMonitorInstance--; } }
/// <summary> /// Releases all resources used by the <see cref="MySqlInstancesList"/> class /// </summary> /// <param name="disposing">If true this is called by Dispose(), otherwise it is called by the finalizer</param> protected virtual void Dispose(bool disposing) { if (disposing) { // Free managed resources if (InstancesList != null) { foreach (MySqlInstance instance in InstancesList.Where(instance => instance != null)) { instance.Dispose(); } } } }
/// <summary> /// Event delegate method fired when the <see cref="ManageItemsDialog"/> button is closed. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void ManageItemsDialog_FormClosed(object sender, FormClosedEventArgs e) { if (DialogResult != DialogResult.OK) { return; } if (_instancesHaveChanges) { InstancesList.SaveToFile(); } if (_servicesHaveChanges) { MachinesList.SavetoFile(); } }
/// <summary> /// Removes the first occurrence of a specific <see cref="MySqlInstance"/> object with the given id from the list. /// </summary> /// <param name="connectionId">Id if the connection linked to the instance to remove.</param> /// <returns><c>true</c> if the instance is successfully removed; otherwise, <c>false</c>. This method also returns <c>false</c> if the instance was not found in the list.</returns> public bool Remove(string connectionId) { int index = InstancesList.FindIndex(ins => ins.WorkbenchConnectionId == connectionId); bool success = index >= 0; if (!success) { return(false); } try { RemoveAt(index); } catch { success = false; } return(success); }
private void EndGetInstancesForMetric(IAsyncResult async) { GetInstancesRequest request = async.AsyncState as GetInstancesRequest; try { HttpWebResponse response = request.HttpWebRequest.EndGetResponse(async) as HttpWebResponse; Stream stream = response.GetResponseStream(); DataContractSerializer serializer = new DataContractSerializer(typeof(List <Instance>)); this.instances = (List <Instance>)serializer.ReadObject(stream); InstancesList.Invoke(() => { InstancesList.DisplayMember = "Name"; InstancesList.DataSource = this.instances; }); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
/// <summary> /// Event delegate method fired when the <see cref="DeleteButton"/> button is clicked. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void DeleteButton_Click(object sender, EventArgs e) { if (_selectedItem == null) { return; } if (_selectedItem is MySqlService) { var selectedService = (MySqlService)_selectedItem; Machine machine = MachinesList.GetMachineById(selectedService.Host.MachineId); machine.ChangeService(selectedService, ListChangeType.RemoveByUser); MonitoredServicesListView.Items.RemoveAt(MonitoredServicesListView.SelectedIndices[0]); } else if (_selectedItem is MySqlInstance) { var selectedInstance = (MySqlInstance)_selectedItem; if (InstancesList.Remove(selectedInstance)) { MonitoredInstancesListView.Items.RemoveAt(MonitoredInstancesListView.SelectedIndices[0]); } } }
/// <summary> /// Determines the index of a specific itemText in the list. /// </summary> /// <param name="item">The <see cref="MySqlInstance"/> object to locate in the list.</param> /// <returns>The index of <seealso cref="item"/> if found in the list; otherwise, <c>-1</c>.</returns> public int IndexOf(MySqlInstance item) { return(InstancesList.IndexOf(item)); }
/// <summary> /// Returns an enumerator that iterates through a collection. /// </summary> /// <returns>An <see cref="IEnumerator"/> object that can be used to iterate through the collection.</returns> IEnumerator IEnumerable.GetEnumerator() { return(InstancesList.GetEnumerator()); }
/// <summary> /// Returns an enumerator that iterates through the list. /// </summary> /// <returns>An <see cref="IEnumerator"/> for the list.</returns> public IEnumerator <MySqlInstance> GetEnumerator() { return(InstancesList.GetEnumerator()); }
/// <summary> /// Copies the entire list to a compatible one-dimensional array, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the elements copied from list. The <see cref="Array"/> must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param> public void CopyTo(MySqlInstance[] array, int arrayIndex) { InstancesList.CopyTo(array, arrayIndex); }
private void Awake() { // TODO(kookehs): Map instances of this to players. InstancesList.Add(this); }
/// <summary> /// Event delegate method fired when the <see cref="MySQLInstanceToolStripMenuItem"/> context menu item is clicked. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void MySQLInstanceToolStripMenuItem_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; MonitoredServicesListView.BeginUpdate(); MySqlWorkbenchConnection selectedConnection = null; using (var monitorInstancesDialog = new MonitorMySqlServerInstancesDialog(MachinesList, InstancesList)) { if (monitorInstancesDialog.ShowDialog() == DialogResult.OK) { selectedConnection = monitorInstancesDialog.SelectedWorkbenchConnection; if (selectedConnection != null) { bool connectionAlreadyInInstance = false; // If the selected connection exists for an already monitored instance but it is not its main connection, replace the main connection with this one. foreach (var instance in InstancesList.Where(inst => inst.RelatedConnections.Exists(conn => conn.Id == selectedConnection.Id))) { if (selectedConnection.ConnectionStatus == MySqlWorkbenchConnection.ConnectionStatusType.Unknown) { Exception ex; selectedConnection.TestConnectionSilently(out ex); } instance.WorkbenchConnection = selectedConnection; connectionAlreadyInInstance = true; foreach (ListViewItem lvi in MonitoredInstancesListView.Items) { MySqlInstance existingInstance = lvi.Tag as MySqlInstance; if (existingInstance != instance) { continue; } lvi.Text = instance.HostIdentifier; lvi.SubItems[1].Text = instance.WorkbenchConnection.ConnectionMethod.GetDescription(); lvi.SubItems[2].Text = instance.ConnectionStatusText; break; } break; } if (!connectionAlreadyInInstance) { MySqlInstance newInstance = new MySqlInstance(selectedConnection); InstancesList.Add(newInstance); AddInstance(newInstance, true); InstancesList.SaveToFile(); } } } // Workbench connections may have been edited so we may need to refresh the items in the list. foreach (ListViewItem lvi in MonitoredInstancesListView.Items) { var existingInstance = lvi.Tag as MySqlInstance; if (existingInstance == null || (selectedConnection != null && existingInstance.WorkbenchConnection.Id == selectedConnection.Id)) { continue; } var connectionInDisk = MySqlWorkbench.Connections.GetConnectionForId(existingInstance.WorkbenchConnection.Id); if (connectionInDisk == null || connectionInDisk.Equals(existingInstance.WorkbenchConnection)) { continue; } lvi.Text = connectionInDisk.HostIdentifier; lvi.SubItems[1].Text = connectionInDisk.ConnectionMethod.GetDescription(); lvi.SubItems[2].Text = connectionInDisk.ConnectionStatusText; } InstancesListChanged = monitorInstancesDialog.InstancesListChanged; } MonitoredServicesListView.EndUpdate(); Cursor.Current = Cursors.Default; }
/// <summary> /// Removes all elements from the list. /// </summary> public void Clear() { InstancesList.Clear(); OnInstancesListChanged(null, ListChangedType.Reset); }
/// <summary> /// Determines whether an element is in the list. /// </summary> /// <param name="item">A <see cref="MySqlInstance"/> object.</param> /// <returns><c>true</c> if <seealso cref="item"/> is found in the list; otherwise, <c>false</c>.</returns> public bool Contains(MySqlInstance item) { return(InstancesList.Contains(item)); }
ProjectInstanceSelection(List <Gamelet> instances) { InitializeComponent(); InstancesList.ItemsSource = instances; InstancesList.Focus(); }
/// <summary> /// Performs logic when clicking the Add button for instances. /// </summary> private void AddInstanceClick() { Cursor.Current = Cursors.WaitCursor; MonitoredServicesListView.BeginUpdate(); MySqlWorkbenchConnection selectedConnection = null; using (var monitorInstancesDialog = new MonitorMySqlServerInstancesDialog(MachinesList, InstancesList)) { if (monitorInstancesDialog.ShowDialog() == DialogResult.OK) { selectedConnection = monitorInstancesDialog.SelectedWorkbenchConnection; var mySqlInstanceAndExistingFlag = InstancesList.AddConnectionToMonitor(selectedConnection); if (mySqlInstanceAndExistingFlag != null) { var instance = mySqlInstanceAndExistingFlag.Item1; var instanceAlreadyExists = mySqlInstanceAndExistingFlag.Item2; if (instanceAlreadyExists) { var correspondingListViewItem = MonitoredInstancesListView.Items.OfType <ListViewItem>().FirstOrDefault(lvi => lvi.Tag is MySqlInstance existingInstance && existingInstance == instance); if (correspondingListViewItem != null) { correspondingListViewItem.Text = instance.DisplayConnectionSummaryText; correspondingListViewItem.SubItems[1].Text = instance.WorkbenchConnection.ConnectionMethod.GetDescription(); correspondingListViewItem.SubItems[2].Text = instance.ConnectionStatusText; } } else { AddInstance(instance, true); } } } // Workbench connections may have been edited so we may need to refresh the items in the list. foreach (ListViewItem lvi in MonitoredInstancesListView.Items) { if (!(lvi.Tag is MySqlInstance existingInstance) || selectedConnection != null && existingInstance.WorkbenchConnection.Id == selectedConnection.Id) { continue; } var connectionInDisk = MySqlWorkbench.Connections.GetConnectionForId(existingInstance.WorkbenchConnection.Id); if (connectionInDisk == null || connectionInDisk.Equals(existingInstance.WorkbenchConnection)) { continue; } lvi.Text = connectionInDisk.HostIdentifier; lvi.SubItems[1].Text = connectionInDisk.ConnectionMethod.GetDescription(); lvi.SubItems[2].Text = connectionInDisk.ConnectionStatusText; } InstancesListChanged = monitorInstancesDialog.InstancesListChanged; } MonitoredServicesListView.EndUpdate(); Cursor.Current = Cursors.Default; }