/// <summary> /// Registers the type of input device available. /// </summary> /// <param name="match"></param> /// <param name="creator"></param> public void RegisterInputDeviceType(MatchFunc match, CreatorFunc creator) { if (match == null) { throw new ArgumentNullException(nameof(match)); } if (creator == null) { throw new ArgumentNullException(nameof(creator)); } _specialDeviceCreators.Add(new SpecialDeviceCreator { Match = match, Creator = creator }); // Reconnect any existing devices matching the predicate // List<string> matchingDevices = (from device in _inputDevices.Values where device.DeviceImp != null && match(device.DeviceImp) select device.Id).ToList(); List <string> matchingDevices = new List <string>(); foreach (var device in _inputDevices.Values) { if (device.DeviceImp != null && match(device.DeviceImp)) { matchingDevices.Add(device.Id); } } foreach (var devId in matchingDevices) { InputDevice dev = _inputDevices[devId]; // Set device to disconnected state dev.Disconnect(); // Inform interested users about disconnection InputDeviceDisconnected?.Invoke(this, new DeviceConnectionArgs { InputDevice = dev }); IInputDeviceImp inputDeviceImp = dev.DeviceImp; // Remove device from the list _inputDevices.Remove(devId); dev = creator(inputDeviceImp); _inputDevices[devId] = dev; // no need to call reconnect since device is constructed from scratch // Inform interested users about the newly connected device. InputDeviceConnected?.Invoke(this, new DeviceConnectionArgs { InputDevice = dev }); } }
/// <summary> /// コンストラクタ /// </summary> public CacheManager(CreatorFunc creator, long capacity, IEqualityComparer <TKey> comparer) { if (comparer == null) { throw new ArgumentNullException("comparer"); } if (creator == null) { throw new ArgumentNullException("creator"); } if (capacity < 0) { throw new ArgumentException("capacity"); } this.usageList = new LinkedList <CacheData>(); this.dic = new Dictionary <TKey, LinkedListNode <CacheData> >(comparer); this.comparer = comparer; this.creator = creator; this.capacity = capacity; }
/// <summary> /// コンストラクタ /// </summary> public CacheManager(CreatorFunc creator, long capacity) : this(creator, capacity, EqualityComparer <TKey> .Default) { }