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);
            }
        }
示例#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);
            }
        }
示例#3
0
 private QLDeviceManager()
 {
     devices.CollectionChanged += (obj, args) =>
     {
         DevicesChanged?.Invoke(_instance, args);
     };
 }
        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);
            }
        }
示例#5
0
 public void RefreshDevices()
 {
     BuildDeviceList(AudioController.GetActivePlaybackDevices(), _playDevices);
     BuildDeviceList(AudioController.GetActiveRecordingDevices(), _inputDevices);
     FetchSettings();
     SaveSettings();
     DevicesChanged?.Invoke(this, EventArgs.Empty);
 }
示例#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;
            };
        }
 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;
         }
     };
 }
 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;
         }
     };
 }
        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));
            });
        }
示例#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);
            }
        }
 public void OnDeviceStateChanged(string deviceId, DeviceState newState)
 {
     DevicesChanged?.Invoke(this, new DeviceChangedEventBase(deviceId));
 }
示例#12
0
 internal static void Internal_DevicesChanged()
 {
     devicesVersion++;
     devices = null;
     DevicesChanged?.Invoke();
 }
 public void OnDeviceRemoved(string deviceId)
 {
     Task.Factory.StartNew(() => { DevicesChanged?.Invoke(this, new DeviceChangedEventBase(deviceId)); });
 }
 public void OnPropertyValueChanged(string pwstrDeviceId, PropertyKey key)
 {
     DevicesChanged?.Invoke(this, new DeviceChangedEventBase(pwstrDeviceId));
 }
 public void OnDeviceRemoved(string deviceId)
 {
     DevicesChanged?.Invoke(this, new DeviceChangedEventBase(deviceId));
 }
 public void OnDeviceAdded(string pwstrDeviceId)
 {
     DevicesChanged?.Invoke(this, new DeviceChangedEventBase(pwstrDeviceId));
 }
示例#17
0
 private static void EnumerateDevices()
 {
     DevicesChanged?.Invoke(null, EventArgs.Empty);
 }
 protected virtual void OnDevicesChanged()
 {
     DevicesChanged?.Invoke(this, EventArgs.Empty);
 }
示例#19
0
 internal static void Internal_DevicesChanged()
 {
     DevicesChanged?.Invoke();
 }