Пример #1
0
 public OpenRgbDevice(OpenRgbData data, ColorService cs) : base(cs)
 {
     Id            = data.Id;
     _data         = data;
     _colorService = cs;
     _client       = cs.ControlService.GetAgent("OpenRgbAgent");
     LoadData();
     _colorService.ColorSendEventAsync += SetColors;
 }
Пример #2
0
        public async Task Discover(CancellationToken ct, int timeout)
        {
            if (_client == null)
            {
                Log.Debug("No client.");
                return;
            }

            try {
                var sd = DataUtil.GetSystemData();
                if (!_client.Connected)
                {
                    try {
                        _client.Connect();
                    } catch (Exception e) {
                        Log.Debug("Error connecting to client, probably it doesn't exist: " + e.Message);
                        return;
                    }
                }

                if (_client.Connected)
                {
                    Log.Debug("Client connected.");
                    var devs     = _client.GetDevices().ToArray();
                    var existing = DataUtil.GetDevices();
                    for (var i = 0; i < devs.Length; i++)
                    {
                        var dev = devs[i];
                        var rd  = new OpenRgbData(dev, i, sd.OpenRgbIp);
                        foreach (var od in from IColorTargetData ex in existing
                                 where ex.Id.Contains("OpenRgb")
                                 select(OpenRgbData) ex
                                 into od
                                 where od.Matches(dev)
                                 select od)
                        {
                            od.UpdateFromDiscovered(rd);
                            rd = od;
                        }

                        await _cs.UpdateDevice(rd).ConfigureAwait(false);
                    }
                }
            } catch (Exception f) {
                Log.Warning("Exception during OpenRGB Discovery: " + f.Message + " at " + f.StackTrace);
            }
        }