コード例 #1
0
        /// <summary>
        /// Retreives a list of available IR Server plugins.
        /// </summary>
        /// <returns>Array of plugin instances.</returns>
        public static PluginBase[] AvailablePlugins()
        {
            List <PluginBase> plugins = new List <PluginBase>();

            string path = Path.Combine(Application.StartupPath, "Plugins");

            string[] files = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);

            // TODO: Return a Type[], don't instantiate unless required

            foreach (string file in files)
            {
                try
                {
                    Assembly assembly = Assembly.LoadFrom(file);

                    Type[] types = assembly.GetExportedTypes();

                    foreach (Type type in types)
                    {
                        if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(PluginBase)))
                        {
                            PluginBase plugin = (PluginBase)assembly.CreateInstance(type.FullName);

                            if (plugin != null && plugin.Detect() != PluginBase.DetectionResult.DeviceDisabled)
                            {
                                plugins.Add(plugin);
                            }
                        }
                    }
                }
                catch (BadImageFormatException)
                {
                } // Ignore Bad Image Format Exceptions, just keep checking for IR Server Plugins
                catch (TypeLoadException)
                {
                } // Ignore Type Load Exceptions, just keep checking for IR Server Plugins
                catch (FileNotFoundException)
                {
                } // Ignore File Not Found Exceptions, just keep checking for IR Server Plugins
            }

            return(plugins.ToArray());
        }
コード例 #2
0
ファイル: IR Server.cs プロジェクト: Azzuro/IR-Server-Suite
    private void StartPlugins()
    {
      bool transmitPluginAlreadyStarted = false;

      #region Start receive plugins

      if (_receivePlugins != null)
      {
        List<PluginBase> removePlugins = new List<PluginBase>();

        foreach (PluginBase plugin in _receivePlugins)
        {
          try
          {
            plugin.Start();

            IRemoteReceiver remoteReceiver = plugin as IRemoteReceiver;
            if (remoteReceiver != null)
              remoteReceiver.RemoteCallback += RemoteHandlerCallback;

            IKeyboardReceiver keyboardReceiver = plugin as IKeyboardReceiver;
            if (keyboardReceiver != null)
              keyboardReceiver.KeyboardCallback += KeyboardHandlerCallback;

            IMouseReceiver mouseReceiver = plugin as IMouseReceiver;
            if (mouseReceiver != null)
              mouseReceiver.MouseCallback += MouseHandlerCallback;

            if (plugin.Name.Equals(Settings.PluginNameTransmit, StringComparison.OrdinalIgnoreCase))
            {
              transmitPluginAlreadyStarted = true;
              IrssLog.Info("Transmit and Receive plugin started: \"{0}\"", plugin.Name);
            }
            else
            {
              IrssLog.Info("Receiver plugin started: \"{0}\"", plugin.Name);
            }
          }
          catch (Exception ex)
          {
            IrssLog.Error("Failed to start receive plugin: \"{0}\"", plugin.Name);
            IrssLog.Error(ex);

            removePlugins.Add(plugin);
          }
        }

        if (removePlugins.Count > 0)
          foreach (PluginBase plugin in removePlugins)
            _receivePlugins.Remove(plugin);

        if (_receivePlugins.Count == 0)
          _receivePlugins = null;
      }

      #endregion

      #region Start transmit plugin

      if (_transmitPlugin != null && !transmitPluginAlreadyStarted)
      {
        try
        {
          _transmitPlugin.Start();

          IrssLog.Info("Transmit plugin started: \"{0}\"", Settings.PluginNameTransmit);
        }
        catch (Exception ex)
        {
          IrssLog.Error("Failed to start transmit plugin: \"{0}\"", Settings.PluginNameTransmit);
          IrssLog.Error(ex);

          _transmitPlugin = null;
        }
      }

      #endregion
    }
コード例 #3
0
ファイル: IR Server.cs プロジェクト: Azzuro/IR-Server-Suite
    private void StopPlugins()
    {
      bool transmitPluginAlreadyStopped = false;

      #region Stop receive plugins

      if (_receivePlugins != null && _receivePlugins.Count > 0)
      {
        foreach (PluginBase plugin in _receivePlugins)
        {
          try
          {
            IRemoteReceiver remoteReceiver = plugin as IRemoteReceiver;
            if (remoteReceiver != null)
              remoteReceiver.RemoteCallback -= RemoteHandlerCallback;

            IKeyboardReceiver keyboardReceiver = plugin as IKeyboardReceiver;
            if (keyboardReceiver != null)
              keyboardReceiver.KeyboardCallback -= KeyboardHandlerCallback;

            IMouseReceiver mouseReceiver = plugin as IMouseReceiver;
            if (mouseReceiver != null)
              mouseReceiver.MouseCallback -= MouseHandlerCallback;

            plugin.Stop();

            if (plugin == _transmitPlugin)
            {
              transmitPluginAlreadyStopped = true;
              IrssLog.Info("Transmit and Receive plugin stopped: \"{0}\"", plugin.Name);
            }
            else
            {
              IrssLog.Info("Receiver plugin stopped: \"{0}\"", plugin.Name);
            }
          }
          catch (Exception ex)
          {
            IrssLog.Error(ex);
          }
        }
      }

      _receivePlugins = null;

      #endregion

      #region Stop transmit plugin

      try
      {
        if (_transmitPlugin != null && !transmitPluginAlreadyStopped)
          _transmitPlugin.Stop();
      }
      catch (Exception ex)
      {
        IrssLog.Error(ex);
      }
      finally
      {
        _transmitPlugin = null;
      }

      #endregion
    }
コード例 #4
0
ファイル: IR Server.cs プロジェクト: Azzuro/IR-Server-Suite
    private void LoadPlugins()
    {
      _receivePlugins = null;
      _transmitPlugin = null;

      if (Settings.PluginNameReceive == null && String.IsNullOrEmpty(Settings.PluginNameTransmit))
      {
        IrssLog.Warn("No transmit or receive plugins loaded");
        return;
      }

      #region Load receive plugins

      if (Settings.PluginNameReceive == null)
      {
        IrssLog.Warn("No receiver plugins loaded");
      }
      else
      {
        _receivePlugins = new List<PluginBase>(Settings.PluginNameReceive.Length);

        for (int index = 0; index < Settings.PluginNameReceive.Length; index++)
        {
          try
          {
            string pluginName = Settings.PluginNameReceive[index];

            PluginBase plugin = Program.GetPlugin(pluginName);

            if (plugin == null)
            {
              IrssLog.Warn("Receiver plugin not found: {0}", pluginName);
            }
            else
            {
              _receivePlugins.Add(plugin);

              if (!String.IsNullOrEmpty(Settings.PluginNameTransmit) &&
                  plugin.Name.Equals(Settings.PluginNameTransmit, StringComparison.OrdinalIgnoreCase))
                _transmitPlugin = plugin;
            }
          }
          catch (Exception ex)
          {
            IrssLog.Error(ex);
          }
        }

        if (_receivePlugins.Count == 0)
          _receivePlugins = null;
      }

      #endregion

      #region Load transmit plugin

      if (String.IsNullOrEmpty(Settings.PluginNameTransmit))
      {
        IrssLog.Warn("No transmit plugin loaded");
      }
      else if (_transmitPlugin == null)
      {
        try
        {
          _transmitPlugin = Program.GetPlugin(Settings.PluginNameTransmit);
        }
        catch (Exception ex)
        {
          IrssLog.Error(ex);
        }
      }

      #endregion
    }