Exemplo n.º 1
0
 private QLDeviceManager()
 {
     devices.CollectionChanged += (obj, args) =>
     {
         DevicesChanged?.Invoke(_instance, args);
     };
 }
Exemplo n.º 2
0
        public static void Refresh()
        {
            while (true)
            {
                string output = CLI.GetOutput("adb devices");

                if (output != oldOutput)
                {
                    List <string> list = new List <string>();

                    oldOutput = output;

                    foreach (string str in output.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        if (str.StartsWith("List"))
                        {
                            continue;
                        }

                        list.Add(str.Substring(0, str.IndexOf("\t")));

                        Debug.WriteLine("Device added: " + str.Substring(0, str.IndexOf("\t")));
                    }

                    DevicesChanged?.Invoke(null, list);
                }
                Thread.Sleep(refreshInterval);
            }
        }
        void Listen()
        {
            var broadcastEndpoint = new IPEndPoint(IPAddress.Any, Http.DiscoveryBroadcastReceiverPort);

            var bytes = listener.Receive(ref broadcastEndpoint);

            var json = System.Text.Encoding.UTF8.GetString(bytes);

            var newBroadcast = Newtonsoft.Json.JsonConvert.DeserializeObject <DiscoveryBroadcast> (json);

            bool changed = false;

            lock (devices)
            {
                var id = newBroadcast.Id;
                DiscoveryBroadcast oldBroadcast;
                if (devices.TryGetValue(id, out oldBroadcast))
                {
                    if (!oldBroadcast.Equals(newBroadcast))
                    {
                        changed     = true;
                        devices[id] = newBroadcast;
                    }
                }
                else
                {
                    changed     = true;
                    devices[id] = newBroadcast;
                }
            }
            if (changed)
            {
                DevicesChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Exemplo n.º 4
0
        void AddDevice(DiscoveryBroadcast newBroadcast)
        {
            bool changed = false;

            lock (devices)
            {
                if (newBroadcast.Addresses.Length == 0)
                {
                    return;
                }
                DeviceInfo         device = new DeviceInfo(newBroadcast.Id, newBroadcast.Addresses[0].Address, newBroadcast.Addresses[0].Port);
                DiscoveryBroadcast oldBroadcast;
                if (devices.TryGetValue(device, out oldBroadcast))
                {
                    if (!oldBroadcast.Equals(newBroadcast))
                    {
                        changed         = true;
                        devices[device] = newBroadcast;
                    }
                }
                else
                {
                    changed         = true;
                    devices[device] = newBroadcast;
                }
            }
            if (changed)
            {
                DevicesChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Exemplo n.º 5
0
 public void RefreshDevices()
 {
     BuildDeviceList(AudioController.GetActivePlaybackDevices(), _playDevices);
     BuildDeviceList(AudioController.GetActiveRecordingDevices(), _inputDevices);
     FetchSettings();
     SaveSettings();
     DevicesChanged?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 6
0
        public Driver()
        {
            Info.GetDriverInstance = () => this;

            DeviceList.Local.Changed += (sender, e) =>
            {
                var newList = DeviceList.Local.GetHidDevices();
                DevicesChanged?.Invoke(this, new DevicesChangedEventArgs(CurrentDevices, newList));
                CurrentDevices = newList;
            };
        }
Exemplo n.º 7
0
 public HidSharpDeviceRootHub()
 {
     DeviceList.Local.Changed += (sender, e) =>
     {
         var newList = DeviceList.Local.GetHidDevices().Select(d => new HidSharpEndpoint(d));
         var changes = new DevicesChangedEventArgs(hidDevices, newList);
         if (changes.Changes.Any())
         {
             DevicesChanged?.Invoke(this, changes);
             hidDevices = newList;
         }
     };
 }
Exemplo n.º 8
0
 private HidSharpDeviceRootHub()
 {
     DeviceList.Local.Changed += (sender, e) =>
     {
         var newList = DeviceList.Local.GetHidDevices().Select(d => new HidSharpEndpoint(d));
         var changes = new DevicesChangedEventArgs(hidDevices, newList);
         if (changes.Changes.Any())
         {
             Plugin.Log.Debug(nameof(HidSharpDeviceRootHub.Current.DevicesChanged), $"Changes: {changes.Changes.Count()}, Add: {changes.Additions.Count()}, Remove: {changes.Removals.Count()}");
             DevicesChanged?.Invoke(this, changes);
             hidDevices = newList;
         }
     };
 }
Exemplo n.º 9
0
        public void OnPropertyValueChanged(string pwstrDeviceId, PropertyKey key)
        {
            Task.Factory.StartNew(() =>
            {
                if (PropertyKeys.PKEY_DeviceInterface_FriendlyName.formatId != key.formatId &&
                    PropertyKeys.PKEY_AudioEndpoint_GUID.formatId != key.formatId &&
                    PropertyKeys.PKEY_Device_IconPath.formatId != key.formatId &&
                    PropertyKeys.PKEY_Device_FriendlyName.formatId != key.formatId
                    )
                {
                    return;
                }

                DevicesChanged?.Invoke(this, new DeviceChangedEventBase(pwstrDeviceId));
            });
        }
Exemplo n.º 10
0
        /// <summary>
        /// 循环检测设备信息
        /// </summary>
        private void Loop()
        {
            IDevicesGetter        getter = new DevicesGetter();
            IEnumerable <IDevice> last   = getter.GetDevices();

            DevicesChanged?.Invoke(this, new DevicesChangedEventArgs(last));
            IEnumerable <IDevice> _new = null;

            while (!tokenSource.Token.IsCancellationRequested)
            {
                _new = getter.GetDevices();
                if (!_new.DevicesEquals(last))
                {
                    last = _new;
                    DevicesChanged?.Invoke(this, new DevicesChangedEventArgs(last));
                }
                Thread.Sleep(Interval);
            }
        }
Exemplo n.º 11
0
    protected override void OnDevicesChanged(DevicesChanged e)
    {
        if (e.Devices == null)
        {
            return;
        }

        m_devices = e.Devices.OrderBy(x => x.Name).ToList();

        if (m_devices != null && m_devices.Count > 0)
        {
            m_noDevicesUI.SetActive(false);
        }

        // Reorder list to show Active Device at the top of the list
        Device activeDevice = m_devices.FirstOrDefault(x => x.Id == SpotifyService.ActiveDevice.Id);

        m_devices.Remove(activeDevice);
        m_devices.Insert(0, activeDevice);

        UpdateUI(m_devices);
    }
Exemplo n.º 12
0
 /// <summary>
 /// Callback for when the service loads all Spotify playback devices or finds a new device
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnDevicesChanged(DevicesChanged e)
 {
 }
Exemplo n.º 13
0
 internal static void Internal_DevicesChanged()
 {
     devicesVersion++;
     devices = null;
     DevicesChanged?.Invoke();
 }
Exemplo n.º 14
0
 public void OnDeviceRemoved(string deviceId)
 {
     Task.Factory.StartNew(() => { DevicesChanged?.Invoke(this, new DeviceChangedEventBase(deviceId)); });
 }
Exemplo n.º 15
0
 public void OnPropertyValueChanged(string pwstrDeviceId, PropertyKey key)
 {
     DevicesChanged?.Invoke(this, new DeviceChangedEventBase(pwstrDeviceId));
 }
Exemplo n.º 16
0
 public void OnDeviceRemoved(string deviceId)
 {
     DevicesChanged?.Invoke(this, new DeviceChangedEventBase(deviceId));
 }
Exemplo n.º 17
0
 public void OnDeviceAdded(string pwstrDeviceId)
 {
     DevicesChanged?.Invoke(this, new DeviceChangedEventBase(pwstrDeviceId));
 }
Exemplo n.º 18
0
 public void OnDeviceStateChanged(string deviceId, DeviceState newState)
 {
     DevicesChanged?.Invoke(this, new DeviceChangedEventBase(deviceId));
 }
Exemplo n.º 19
0
 internal static void Internal_DevicesChanged()
 {
     DevicesChanged?.Invoke();
 }
 protected virtual void OnDevicesChanged()
 {
     DevicesChanged?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 21
0
 private static void EnumerateDevices()
 {
     DevicesChanged?.Invoke(null, EventArgs.Empty);
 }