Example #1
0
        public void Compare(UpnpDevice to, UpnpDevice from)
        {
            if(from == null)
                return;

            var fromChildren = from.EnumerateDevices().ToList();
            var toChildren = to.EnumerateDevices().ToList();

            foreach (var toChild in toChildren)
            {
                var fromChild = FindMatchFor(toChild, fromChildren);
                if (fromChild == null)
                {
                    //fromChild doesnt exist so was removed
                    DeviceRemoved(toChild);
                    continue;
                }

                // remove the child so we can see if there are any new ones at the end.
                fromChildren.Remove(fromChild);
                CompareDevices(toChild, fromChild);
            }

            //these devices were not found in the 'to' device so they are new
            if (fromChildren.Count > 0)
                ProcessAddedDevices(to, fromChildren);
        }
Example #2
0
        protected virtual void CompareDevices(UpnpDevice to, UpnpDevice from)
        {
            var fromServices = from.Services.ToList();
            var toServices = to.Services.ToList();

            foreach (var toService in toServices)
            {
                var fromService = FindMatchFor(toService, fromServices);
                if (fromService == null)
                {
                    ServiceRemoved(to, toService);
                    continue;
                }

                fromServices.Remove(fromService);
                CompareService(toService, fromService);
            }

            if(fromServices.Count > 0)
                ServicesAdded(to, fromServices);
        }
Example #3
0
        protected virtual void CompareDevices(UpnpDevice to, UpnpDevice from)
        {
            var fromServices = from.Services.ToList();
            var toServices   = to.Services.ToList();

            foreach (var toService in toServices)
            {
                var fromService = FindMatchFor(toService, fromServices);
                if (fromService == null)
                {
                    ServiceRemoved(to, toService);
                    continue;
                }

                fromServices.Remove(fromService);
                CompareService(toService, fromService);
            }

            if (fromServices.Count > 0)
            {
                ServicesAdded(to, fromServices);
            }
        }
Example #4
0
        private void ProcessAddedDevices(UpnpDevice to, List <UpnpDevice> addedDevices)
        {
            var toChildren = to.EnumerateDevices().ToList();

            foreach (var device in addedDevices)
            {
                //cant update root device
                if (device.Parent == null)
                {
                    continue;
                }

                //find the original 'to' parent
                var toChild = FindMatchFor(device.Parent, toChildren);
                if (toChild == null)
                {
                    continue;
                }


                DeviceAdded(toChild, device);
            }
        }
Example #5
0
 protected virtual void DeviceRemoved(UpnpDevice device)
 {
 }
Example #6
0
 public static IEnumerable <UpnpDevice> FindByUdn(this UpnpDevice device, string udn)
 {
     return(device.EnumerateDevices().Where(d => d.UDN == udn));
 }
Example #7
0
 protected virtual void DeviceAdded(UpnpDevice parent, UpnpDevice device)
 {
 }
Example #8
0
 protected internal void OnChildDeviceRemoved(UpnpDevice child)
 {
     var handler = ChildDeviceRemoved;
     if (handler != null)
         handler(this, new EventArgs<UpnpDevice>(child));
 }
Example #9
0
 public static IEnumerable <UpnpService> EnumerateServices(this UpnpDevice @this)
 {
     return(@this.EnumerateDevices().SelectMany(device => device.Services));
 }
Example #10
0
        private void SetupOnRemovedHandler(UpnpDevice device, ISsdpAnnouncer ad1, ISsdpAnnouncer ad2)
        {
            EventHandler<EventArgs<UpnpDevice>> onRemoved = null;
            onRemoved = (sender, args) =>
            {
                ad1.Shutdown();
                ad2.Shutdown();

                this.SsdpServer.RemoveAnnouncer(ad1);
                this.SsdpServer.RemoveAnnouncer(ad2);

                device.Removed -= onRemoved;
            };

            device.Removed += onRemoved;
        }
Example #11
0
 public static IEnumerable <UpnpDevice> EnumerateDevices(this UpnpDevice @this)
 {
     return(new[] { @this }.Concat(@this.Devices.SelectMany(d => d.EnumerateDevices())));
 }
Example #12
0
 protected virtual UpnpDevice FindMatchFor(UpnpDevice device, IEnumerable<UpnpDevice> fromChildren)
 {
     return fromChildren.FirstOrDefault(child => device.Type == child.Type);
 }
Example #13
0
 protected virtual void ServicesAdded(UpnpDevice device, List<UpnpService> services)
 {
 }
Example #14
0
 protected virtual UpnpDevice FindMatchFor(UpnpDevice device, IEnumerable <UpnpDevice> fromChildren)
 {
     return(fromChildren.FirstOrDefault(child => device.Type == child.Type));
 }
Example #15
0
 protected virtual void DeviceRemoved(UpnpDevice device)
 {
 }
Example #16
0
 protected virtual void ServiceRemoved(UpnpDevice device, UpnpService service)
 {
 }
Example #17
0
 public static IEnumerable <UpnpService> FindByServiceType(this UpnpDevice device, UpnpType type)
 {
     return(device.EnumerateServices().Where(service => service.Type.Equals(type)));
 }
Example #18
0
 public static IEnumerable <UpnpService> FindByServiceId(this UpnpDevice device, string id)
 {
     return(device.EnumerateServices().Where(s => s.Id == id));
 }
Example #19
0
 protected virtual void ServiceRemoved(UpnpDevice device, UpnpService service)
 {
 }
Example #20
0
 protected virtual void DeviceAdded(UpnpDevice parent, UpnpDevice device)
 {
 }
Example #21
0
        private void ProcessAddedDevices(UpnpDevice to, List<UpnpDevice> addedDevices)
        {
            var toChildren = to.EnumerateDevices().ToList();

            foreach (var device in addedDevices)
            {
                //cant update root device
                if(device.Parent == null)
                    continue;

                //find the original 'to' parent
                var toChild = FindMatchFor(device.Parent, toChildren);
                if(toChild == null)
                    continue;

                DeviceAdded(toChild, device);
            }
        }
Example #22
0
 protected virtual void ServicesAdded(UpnpDevice device, List <UpnpService> services)
 {
 }
Example #23
0
        private void BuildAdvertisementsForDevice(UpnpDevice device)
        {
            var notificationType = device.UDN;
            var type = device.Type.ToString();

            var ad1 = CreateAdvertisement(notificationType, notificationType);
            var ad2 = CreateAdvertisement(type, string.Format("{0}::{1}", device.UDN, type));

            SetupOnRemovedHandler(device, ad1, ad2);

            foreach (var service in device.Services)
                BuildAdvertisementForService(service);

            foreach (var child in device.Devices)
                BuildAdvertisementsForDevice(child);
        }
Example #24
0
 public static IEnumerable <UpnpDevice> FindByDeviceType(this UpnpDevice @this, UpnpType type)
 {
     return(@this.EnumerateDevices().Where(d => d.Type.Equals(type)));
 }