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); }
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); }
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); } }
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); } }
protected virtual void DeviceRemoved(UpnpDevice device) { }
public static IEnumerable <UpnpDevice> FindByUdn(this UpnpDevice device, string udn) { return(device.EnumerateDevices().Where(d => d.UDN == udn)); }
protected virtual void DeviceAdded(UpnpDevice parent, UpnpDevice device) { }
protected internal void OnChildDeviceRemoved(UpnpDevice child) { var handler = ChildDeviceRemoved; if (handler != null) handler(this, new EventArgs<UpnpDevice>(child)); }
public static IEnumerable <UpnpService> EnumerateServices(this UpnpDevice @this) { return(@this.EnumerateDevices().SelectMany(device => device.Services)); }
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; }
public static IEnumerable <UpnpDevice> EnumerateDevices(this UpnpDevice @this) { return(new[] { @this }.Concat(@this.Devices.SelectMany(d => d.EnumerateDevices()))); }
protected virtual UpnpDevice FindMatchFor(UpnpDevice device, IEnumerable<UpnpDevice> fromChildren) { return fromChildren.FirstOrDefault(child => device.Type == child.Type); }
protected virtual void ServicesAdded(UpnpDevice device, List<UpnpService> services) { }
protected virtual UpnpDevice FindMatchFor(UpnpDevice device, IEnumerable <UpnpDevice> fromChildren) { return(fromChildren.FirstOrDefault(child => device.Type == child.Type)); }
protected virtual void ServiceRemoved(UpnpDevice device, UpnpService service) { }
public static IEnumerable <UpnpService> FindByServiceType(this UpnpDevice device, UpnpType type) { return(device.EnumerateServices().Where(service => service.Type.Equals(type))); }
public static IEnumerable <UpnpService> FindByServiceId(this UpnpDevice device, string id) { return(device.EnumerateServices().Where(s => s.Id == id)); }
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); } }
protected virtual void ServicesAdded(UpnpDevice device, List <UpnpService> services) { }
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); }
public static IEnumerable <UpnpDevice> FindByDeviceType(this UpnpDevice @this, UpnpType type) { return(@this.EnumerateDevices().Where(d => d.Type.Equals(type))); }