Beispiel #1
0
        private void InitKeyboardDriver(KeyboardDriverConfig config)
        {
            if (string.IsNullOrEmpty(config.Type))
            {
                throw new ApplicationException("Не определен тип драйвера клавиатуры");
            }
            var driverType = Type.GetType(config.Type);

            if (driverType == null)
            {
                throw new ApplicationException("Не найден тип драйвера клавиатуры " + config.Type);
            }
            if (!driverType.IsImplementInterface(typeof(IKeyboardDriver)))
            {
                throw new ApplicationException(String.Format(
                                                   "Тип драйвера клавиатуры {0} не реализует интерфейс IKeyboardDriver", config.Type));
            }
            if (_driver != null)
            {
                _driver.Dispose();
                _driver = null;
            }
            IKeyboardDriver newDriver;

            try
            {
                newDriver = (IKeyboardDriver)Activator.CreateInstance(driverType);
                newDriver.Init(config, Logger);
                Logger.LogInfo(Message.KeyboardDriverCreated, config.Type);
            }
            catch (Exception ex)
            {
                Logger.LogInfo(Message.KeyboardDriverCreationFailed, config.Type, ex);
                throw;
            }
            _driver             = newDriver;
            _driver.KeyPressed += (sender, e) => OnNewDataReady(e.ScanCode, e.TimeStamp);
            _driver.Start();
        }
Beispiel #2
0
 private void InitKeyboardDriver(KeyboardDriverConfig config)
 {
     if (string.IsNullOrEmpty(config.Type))
         throw new ApplicationException("Не определен тип драйвера клавиатуры");
     var driverType = Type.GetType(config.Type);
     if (driverType == null)
         throw new ApplicationException("Не найден тип драйвера клавиатуры " + config.Type);
     if (!driverType.IsImplementInterface(typeof (IKeyboardDriver)))
         throw new ApplicationException(String.Format(
             "Тип драйвера клавиатуры {0} не реализует интерфейс IKeyboardDriver", config.Type));
     if (_driver != null)
     {
         _driver.Dispose();
         _driver = null;
     }
     IKeyboardDriver newDriver;
     try
     {
         newDriver = (IKeyboardDriver) Activator.CreateInstance(driverType);
         newDriver.Init(config, Logger);
         Logger.LogInfo(Message.KeyboardDriverCreated, config.Type);
     }
     catch (Exception ex)
     {
         Logger.LogInfo(Message.KeyboardDriverCreationFailed, config.Type, ex);
         throw;
     }
     _driver = newDriver;
     _driver.KeyPressed += (sender, e) => OnNewDataReady(e.ScanCode, e.TimeStamp);
     _driver.Start();
 }