Exemple #1
0
        private void Provider_ServiceJoined(DeviceProviders.IProvider sender, DeviceProviders.ServiceJoinedEventArgs args)
        {
            var svc = args.Service;
            List <DeviceClient> clients = new List <DeviceClient>();

            foreach (var interfaceName in devicesCreators)
            {
                if (svc.ImplementsInterface(interfaceName.Key))
                {
                    clients.Add(interfaceName.Value(args.Service));
                }
            }
            if (TrackUnknownDevices && !clients.Any())
            {
                clients.Add(new UnknownClient(svc));
            }
            if (clients.Any())
            {
                //Device found
                lock (devicesLock)
                {
                    devices.Add(svc.Name, clients.ToArray());
                }
                svc.JoinSession();
                foreach (var client in clients)
                {
                    DeviceJoined?.Invoke(this, client);
                }
            }
        }
Exemple #2
0
        private void Provider_ServiceDropped(DeviceProviders.IProvider sender, DeviceProviders.ServiceDroppedEventArgs args)
        {
            var svc = args.Service.Name;

            DeviceClient[] clients = null;
            lock (devicesLock)
            {
                if (devices.ContainsKey(svc))
                {
                    clients = devices[svc];
                    devices.Remove(svc);
                }
            }
            if (clients != null)
            {
                foreach (var client in clients)
                {
                    client.DeviceLost();
                    DeviceDropped?.Invoke(this, client);
                }
            }
        }
        private void Provider_ServiceJoined(DeviceProviders.IProvider sender, DeviceProviders.ServiceJoinedEventArgs args)
        {
            var svc = args.Service;

            svc.JoinSession();
            System.Diagnostics.Debug.WriteLine($"Service Joined: {svc?.AboutData?.DeviceName ?? "<UNKNOWN>"} ({svc?.AboutData?.DeviceId} - {svc.Name})");
            List <DeviceClient> clients = new List <DeviceClient>();

            foreach (var interfaceName in devicesCreators)
            {
                if (svc.ImplementsInterface(interfaceName.Key))
                {
                    clients.Add(interfaceName.Value(args.Service));
                    break;
                }
            }

            if (TrackUnknownDevices && !clients.Any())
            {
                clients.Add(new UnknownClient(svc));
            }

            if (clients.Any())
            {
                // Device found
                lock (devicesLock)
                {
                    devices.Add(svc.Name, clients.ToArray());
                }

                foreach (var client in clients)
                {
                    DeviceJoined?.Invoke(this, client);
                }
            }
        }
        private void Provider_ServiceDropped(DeviceProviders.IProvider sender, DeviceProviders.ServiceDroppedEventArgs args)
        {
            var svc = args.Service.Name;

            System.Diagnostics.Debug.WriteLine($"Service Joined: {svc ?? "<UNKNOWN>"}");
            DeviceClient[] clients = null;
            lock (devicesLock)
            {
                if (devices.ContainsKey(svc))
                {
                    clients = devices[svc];
                    devices.Remove(svc);
                }
            }

            if (clients != null)
            {
                foreach (var client in clients)
                {
                    client.ServiceDropped();
                    DeviceDropped?.Invoke(this, client);
                }
            }
        }