Example #1
0
        public void AddDevice(Device device)
        {
            if (device == null)
                throw new ArgumentNullException("device");

            lock (devices)
            {
                if (devices.Any(p => Object.Equals(p.MACAddress, device.MACAddress)))
                {
                    throw new ArgumentException("device already exists");
                }
                devices.Add(device);
            }
        }
Example #2
0
 public void RemoveDevice(Device device)
 {
     lock (devices)
     {
         devices.Remove(device);
     }
 }
Example #3
0
        private IPAddress GetIpForDevice(string macAddress)
        {
            PhysicalAddress mac = PhysicalAddress.Parse(macAddress);

            lock (dhcpServer)
            {
                Device device = Current.Devices.FirstOrDefault(p => Object.Equals(mac, p.MACAddress));
                if (device == null)
                {
                    device = new Device();
                    device.MACAddress = mac;
                    device.IPAddress = IPAddress.None;
                    device.Name = "Autodetect-" + mac;
                    Current.AddDevice(device);
                }
                else
                {
                    if (!Object.Equals(device.IPAddress, IPAddress.None))
                    {
                        return device.IPAddress;
                    }
                }

                device.IPAddress = GetNextIp();

                return device.IPAddress;
            }
        }