static string getDeviceName(ElectricalDevice dev)
 {
     if (dev.Name != "")
     {
         return(dev.Name);
     }
     return("D" + dev.GetHashCode().ToString());
 }
Exemplo n.º 2
0
        // 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);
        }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
 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);
         }
     }
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 // Constructor
 public ElectricalRelaySPST(string name_c = null)
     : base(name_c)
 {
     relayCoil      = new ElectricalDevice();
     normallyClosed = false;
 }