public void SelectDevice(DeviceInfo deviceInfo) { _currentDevice?.Dispose(); _deviceChannels.Clear(); ChannelListChanged?.Invoke(this, null); _currentDevice = new Device(deviceInfo); _currentDevice.Connect(); if (_currentDevice.ReadParam <DeviceState>(Parameter.State) != DeviceState.Connected) { _currentDevice.ParameterChanged += (sender, parameter) => { if (parameter == Parameter.State) { if (_currentDevice.ReadParam <DeviceState>(Parameter.State) == DeviceState.Connected) { OnDeviceConnected(); } } }; } else { OnDeviceConnected(); } }
private void OnDeviceConnected() { var deviceChannels = _currentDevice.Channels; foreach (var deviceChannel in deviceChannels) { if (deviceChannel.Type == ChannelType.Signal) { _deviceChannels.Add(new SignalChannel(_currentDevice, deviceChannel)); } } ChannelListChanged?.Invoke(this, null); }
private CollectionService() { #if DEBUG // 在调试状态下每次都清空收藏 if (_container.Values.ContainsKey(channelCollectionKey)) { _container.Values[channelCollectionKey] = string.Empty; } if (_container.Values.ContainsKey(programCollectionKey)) { _container.Values[programCollectionKey] = string.Empty; } #endif // 建立频道收藏列表 if (!_container.Values.ContainsKey(channelCollectionKey)) { _container.Values.Add(channelCollectionKey, string.Empty); ChannelList = new ObservableCollection <Channel>(); } else { ChannelList = new ObservableCollection <Channel>((_container.Values[channelCollectionKey] as string) .Split(splitChar).Where(id => !string.IsNullOrWhiteSpace(id)).Select(id => Channel.GetChannel(id))); } ChannelList.CollectionChanged += SyncChannelList; ChannelList.CollectionChanged += (sender, e) => ChannelListChanged?.Invoke(sender, e); // 建立节目收藏列表 if (!_container.Values.ContainsKey(programCollectionKey)) { _container.Values.Add(programCollectionKey, string.Empty); ProgramList = new ObservableCollection <string>(); } else { ProgramList = new ObservableCollection <string>((_container.Values[programCollectionKey] as string) .Split(splitChar).Where(name => !string.IsNullOrWhiteSpace(name))); } ProgramList.CollectionChanged += SyncProgramList; ProgramList.CollectionChanged += (sender, e) => ProgramListChanged?.Invoke(sender, e); }