static string getSwitchName(ElectricalSwitch sw)
 {
     if (sw.Name != "")
     {
         return(sw.Name);
     }
     return("S" + sw.GetHashCode().ToString());
 }
Example #2
0
 public void RemoveSwitch(ElectricalSwitch sw)
 {
     if (switches.Contains(sw))
     {
         switches.Remove(sw);
     }
     RemoveDevice(sw.FirstContact);
     RemoveDevice(sw.SecondContact);
 }
Example #3
0
        // Switch Management Methods
        public ElectricalSwitch CreateSwitch(string swName = null)
        {
            if (FindSwitchByName(swName) != null)
            {
                return(null);
            }
            var newSwitch = new ElectricalSwitch(swName);

            switches.Add(newSwitch);
            newSwitch.FirstContact  = CreateDevice(swName + "(c1)");
            newSwitch.SecondContact = CreateDevice(swName + "(c2)");
            return(newSwitch);
        }
Example #4
0
        public ElectricalSwitch FindSwitchByName(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            ElectricalSwitch mswitch = null;

            name = name.ToLower();
            var allSwitches = switches;

            // Try to find an exact match first
            foreach (var sw in allSwitches)
            {
                if (sw.Name == name)
                {
                    if (mswitch != null)
                    {
                        return(null); // Not unique
                    }
                    mswitch = sw;
                }
            }
            if (mswitch != null)
            {
                return(mswitch);
            }
            // Otherwise try to find a partial match
            foreach (var sw in allSwitches)
            {
                if (sw.Name.ToLower().IndexOf(name) >= 0)
                {
                    if (mswitch != null)
                    {
                        return(null); // Not unique
                    }
                    mswitch = sw;
                }
            }
            return(mswitch);
        }