Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #5
0
 protected virtual void DeviceRemoved(UpnpDevice device)
 {
 }
Beispiel #6
0
 public static IEnumerable <UpnpDevice> FindByUdn(this UpnpDevice device, string udn)
 {
     return(device.EnumerateDevices().Where(d => d.UDN == udn));
 }
Beispiel #7
0
 protected virtual void DeviceAdded(UpnpDevice parent, UpnpDevice device)
 {
 }
Beispiel #8
0
 protected internal void OnChildDeviceRemoved(UpnpDevice child)
 {
     var handler = ChildDeviceRemoved;
     if (handler != null)
         handler(this, new EventArgs<UpnpDevice>(child));
 }
Beispiel #9
0
 public static IEnumerable <UpnpService> EnumerateServices(this UpnpDevice @this)
 {
     return(@this.EnumerateDevices().SelectMany(device => device.Services));
 }
Beispiel #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;
        }
Beispiel #11
0
 public static IEnumerable <UpnpDevice> EnumerateDevices(this UpnpDevice @this)
 {
     return(new[] { @this }.Concat(@this.Devices.SelectMany(d => d.EnumerateDevices())));
 }
Beispiel #12
0
 protected virtual UpnpDevice FindMatchFor(UpnpDevice device, IEnumerable<UpnpDevice> fromChildren)
 {
     return fromChildren.FirstOrDefault(child => device.Type == child.Type);
 }
Beispiel #13
0
 protected virtual void ServicesAdded(UpnpDevice device, List<UpnpService> services)
 {
 }
Beispiel #14
0
 protected virtual UpnpDevice FindMatchFor(UpnpDevice device, IEnumerable <UpnpDevice> fromChildren)
 {
     return(fromChildren.FirstOrDefault(child => device.Type == child.Type));
 }
Beispiel #15
0
 protected virtual void DeviceRemoved(UpnpDevice device)
 {
 }
Beispiel #16
0
 protected virtual void ServiceRemoved(UpnpDevice device, UpnpService service)
 {
 }
Beispiel #17
0
 public static IEnumerable <UpnpService> FindByServiceType(this UpnpDevice device, UpnpType type)
 {
     return(device.EnumerateServices().Where(service => service.Type.Equals(type)));
 }
Beispiel #18
0
 public static IEnumerable <UpnpService> FindByServiceId(this UpnpDevice device, string id)
 {
     return(device.EnumerateServices().Where(s => s.Id == id));
 }
Beispiel #19
0
 protected virtual void ServiceRemoved(UpnpDevice device, UpnpService service)
 {
 }
Beispiel #20
0
 protected virtual void DeviceAdded(UpnpDevice parent, UpnpDevice device)
 {
 }
Beispiel #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);
            }
        }
Beispiel #22
0
 protected virtual void ServicesAdded(UpnpDevice device, List <UpnpService> services)
 {
 }
Beispiel #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);
        }
Beispiel #24
0
 public static IEnumerable <UpnpDevice> FindByDeviceType(this UpnpDevice @this, UpnpType type)
 {
     return(@this.EnumerateDevices().Where(d => d.Type.Equals(type)));
 }