/// <summary> /// Attaches to each device to handle removal /// </summary> /// <param name="sender"></param> protected void DeviceRequestsRemoval(object sender) { try { // Attempt to cast the entry DeviceEntry deviceEntry = sender as DeviceEntry; // Get the index int entryIndex = DeviceListBox.Children.IndexOf(deviceEntry); // Kill the thread and remove the device _analysis.RemoveDeviceAt(entryIndex); // Detatch the Delegate deviceEntry.RemoveEntry -= DeviceRequestsRemoval; // Remove the Entry DeviceListBox.Children.Remove(deviceEntry); // Release the Entry Resources deviceEntry.Dispose(); // Release the Entry deviceEntry = null; } catch (Exception exception) { Console.WriteLine(Tag + ": " + exception.Message); } }
/// <summary> /// Remopves the DeviceEntry from the specified index /// </summary> /// <param name="index"></param> protected void RemoveDeviceEntryAt(int index) { try { // Attempt to cast as a DeviceEntry DeviceEntry deviceEntry = (DeviceEntry)DeviceListBox.Children[index]; RemoveDeviceEntry(deviceEntry); }catch (Exception exception) { Console.WriteLine(Tag + ": " + exception.Message); } }
/// <summary> /// Raised when the Device Entry has had its' button toggled /// </summary> /// <param name="sender"></param> /// <param name="toggleStatus"></param> protected virtual void DeviceEntryToggled(object sender, bool toggleStatus) { try { DeviceEntry deviceEntry = sender as DeviceEntry; int entryIndex = DeviceListBox.Children.IndexOf(deviceEntry); if (toggleStatus) { _analysis.StartDeviceAt(entryIndex); } else { _analysis.StopDeviceAt(entryIndex); } }catch (Exception exception) { Console.WriteLine(Tag + ": " + exception.Message); } }
/// <summary> /// Removes the specified Device Entry /// </summary> /// <param name="deviceEntry"></param> protected void RemoveDeviceEntry(DeviceEntry deviceEntry) { // Make sure it's a valid instance if (deviceEntry == null) { return; } // Detatch the Delegate deviceEntry.RemoveEntry -= DeviceRequestsRemoval; deviceEntry.Toggle -= DeviceEntryToggled; // Remove from the list DeviceListBox.Children.Remove(deviceEntry); // Dispose deviceEntry.Dispose(); // Release the Entry deviceEntry = null; }