Пример #1
0
        void ClientServiceEvent(Mono.Ssdp.ServiceArgs args,
                                Action <DeviceAnnouncement> deviceHandler,
                                Action <ServiceAnnouncement> serviceHandler)
        {
            if (!args.Usn.StartsWith("uuid:"))
            {
                return;
            }

            var colon = args.Usn.IndexOf(':', 5);
            var usn   = colon == -1 ? args.Usn : args.Usn.Substring(0, colon);

            if (args.Usn.Contains(":device:"))
            {
                var type   = DeviceType.Parse(args.Service.ServiceType);
                var device = new DeviceAnnouncement(this, type, usn, args.Service.Locations);
                deviceHandler(device);
            }
            else if (args.Usn.Contains(":service:"))
            {
                var type    = ServiceType.Parse(args.Service.ServiceType);
                var service = new ServiceAnnouncement(this, type, usn, args.Service.Locations);
                serviceHandler(service);
            }
        }
Пример #2
0
        private void OnDeviceDetected(DeviceAnnouncement device)
        {
            var location = device.Locations.FirstOrDefault();

            var success = _provider.IsWeMoDevice(location);

            if (!success)
            {
                return;
            }

            var newDevice = !_provider.Exists(device.Udn);

            var updatedDevice = _provider.Exists(device.Udn)
                               && _provider.Get(device.Udn).Location != location;

            var existingDevice = _provider.Exists(device.Udn);

            if (newDevice)
            {
                var weMoDevice = _provider.Create(location);
                Console.WriteLine($"Found new WeMo: {weMoDevice.FriendlyName} @ {weMoDevice.Host}");
            }
            else if (updatedDevice)
            {
                var weMoDevice = _provider.Update(device.Udn, location);
                Console.WriteLine($"Found updated WeMo: {weMoDevice.FriendlyName} @ {weMoDevice.Host}");
            }
            else if (existingDevice)
            {
                var weMoDevice = _provider.Update(device.Udn, location);
                Console.WriteLine($"Found existing WeMo: {weMoDevice.FriendlyName} @ {weMoDevice.Host}");
            }
        }
Пример #3
0
 internal DeviceDescription GetDescription(DeviceAnnouncement announcement)
 {
     foreach (var uri in announcement.Locations)
     {
         if (descriptions.ContainsKey(uri))
         {
             var description = GetDescription(announcement, descriptions[uri]);
             if (description != null && !description.IsDisposed)
             {
                 return(description);
             }
         }
         try {
             var deserializer = deserializer_factory.CreateDeserializer();
             var rootDevice   = deserializer.DeserializeDescription(new Uri(uri));
             if (rootDevice == null)
             {
                 continue;
             }
             descriptions[uri] = rootDevice;
             return(GetDescription(announcement, rootDevice));
         } catch (Exception e) {
             Log.Exception(string.Format("There was a problem fetching the description at {0}.", uri), e);
         }
     }
     return(null);
 }
Пример #4
0
 DeviceDescription GetDescription(DeviceAnnouncement announcement, DeviceDescription device)
 {
     if (device.Type == announcement.Type && device.Udn == announcement.Udn)
     {
         return(device);
     }
     foreach (var childDevice in device.Devices)
     {
         var description = GetDescription(announcement, childDevice);
         if (description != null)
         {
             return(description);
         }
     }
     return(null);
 }
Пример #5
0
 internal Device GetDevice(DeviceAnnouncement announcement)
 {
     return(GetDescription <DeviceAnnouncement, Device> (announcement.Locations, announcement, GetDevice));
 }
Пример #6
0
 internal DeviceEventArgs(DeviceAnnouncement device, UpnpOperation operation)
 {
     this.device    = device;
     this.operation = operation;
 }
Пример #7
0
 internal DeviceEventArgs (DeviceAnnouncement device, UpnpOperation operation)
 {
     this.device = device;
     this.operation = operation;
 }