static string getDeviceName(ElectricalDevice dev) { if (dev.Name != "") { return(dev.Name); } return("D" + dev.GetHashCode().ToString()); }
// Device Management Methods public ElectricalDevice CreateDevice(string deviceName = null) { if (FindDeviceByName(deviceName) != null) { return(null); } var newDevice = new ElectricalDevice(deviceName); devices.Add(newDevice); return(newDevice); }
public void ConnectDevices(ElectricalDevice first, ElectricalDevice second) { if (devices.Contains(first) && devices.Contains(second)) { if (!first.ConnectedDevices.Contains(second)) { first.ConnectedDevices.Add(second); } if (!second.ConnectedDevices.Contains(first)) { second.ConnectedDevices.Add(first); } } }
public void DisconnectDevices(ElectricalDevice first, ElectricalDevice second) { if (devices.Contains(first) && devices.Contains(second)) { if (first.ConnectedDevices.Contains(second)) { first.ConnectedDevices.Remove(second); } if (second.ConnectedDevices.Contains(first)) { second.ConnectedDevices.Remove(first); } } }
public void RemoveDevice(ElectricalDevice device) { if (devices.Contains(device)) { devices.Remove(device); foreach (var dev in device.ConnectedDevices) { if (dev.ConnectedDevices.Contains(device)) { dev.ConnectedDevices.Remove(device); } } } }
// constructor public ElectricalSwitch(string name_c = null) { if (!string.IsNullOrEmpty(name_c)) { name = name_c; } else { name = "S" + this.GetHashCode().ToString("00000000"); } firstContact = new ElectricalDevice(); secondContact = new ElectricalDevice(); switchState = false; }
public ElectricalDevice FindDeviceByName(string name) { if (string.IsNullOrEmpty(name)) { return(null); } ElectricalDevice device = null; name = name.ToLower(); var allDevices = devices; // Try to find an exact match first foreach (var d in allDevices) { if (d.Name == name) { if (device != null) { return(null); // Not unique } device = d; } } if (device != null) { return(device); } // Otherwise try to find a partial match foreach (var d in allDevices) { if (d.Name.ToLower().IndexOf(name) >= 0) { if (device != null) { return(null); // Not unique } device = d; } } return(device); }
// Constructor public ElectricalRelaySPST(string name_c = null) : base(name_c) { relayCoil = new ElectricalDevice(); normallyClosed = false; }