Esempio n. 1
0
    static void Main()
    {
      if (ProcessHelper.IsProcessAlreadyRunning())
        return;

      Thread.CurrentThread.Name = "Main Thread";
      IrssLog.Open("IR Server Tray.log");

      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);

      _notifyIcon = new NotifyIcon();
      _notifyIcon.ContextMenuStrip = new ContextMenuStrip();
      _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripLabel("IR Server Tray"));
      _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());

      if (File.Exists(_configExe))
      _notifyIcon.ContextMenuStrip.Items.Add("&Configuration", Win32.GetImageFromFile(_configExe), ClickConfiguration);

      if (File.Exists(_translatorExe))
        _notifyIcon.ContextMenuStrip.Items.Add("&Translator", Win32.GetImageFromFile(_translatorExe), ClickTranslator);
      
      if (File.Exists(_debugClientExe))
        _notifyIcon.ContextMenuStrip.Items.Add("&Debug Client", Win32.GetImageFromFile(_debugClientExe), ClickDebugClient);
      
      _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
      _notifyIcon.ContextMenuStrip.Items.Add("&Exit", null, ClickExit);
      //_notifyIcon.DoubleClick += new EventHandler(OpenConfiguration);
      _notifyIcon.Icon = new System.Drawing.Icon(Resources.iconGray, new System.Drawing.Size(16, 16));
      _notifyIcon.Text = Shared.ServerDisplayName;
      _notifyIcon.Visible = true;

      Settings.LoadSettings();
      if (Settings.RestartOnUSBChangesTray)
      {
        _hardwareMonitor = new HardwareMonitor();
        _hardwareMonitor.DeviceConnected += new HardwareMonitor.HardwareMonitorEvent(OnDeviceConnected);
        _hardwareMonitor.Start();
      }

      thread = new Thread(new ThreadStart(UpdateIcon));
      thread.IsBackground = true;
      thread.Start();

      Application.Run();
      thread.Abort();

      if (Settings.RestartOnUSBChangesTray)
      {
        _hardwareMonitor.Stop();
        _hardwareMonitor = null;
      }

      _notifyIcon.Visible = false;
      _notifyIcon = null;

      IrssLog.Close();
    }
Esempio n. 2
0
    /// <summary>
    /// Called when the service is stopped.
    /// </summary>
    protected override void OnStop()
    {
      IrssLog.Info("Stopping IR Server ...");

      if (_hardwareMonitor != null)
      {
        _hardwareMonitor.Stop();
        _hardwareMonitor = null;
      }

      if (Settings.Mode == IRServerMode.ServerMode)
      {
        try
        {
          IrssMessage message = new IrssMessage(MessageType.ServerShutdown, MessageFlags.Notify);
          SendToAll(message);
        }
        catch (Exception ex)
        {
          IrssLog.Error(ex);
        }
      }

      StopPlugins();

      // Stop Service
      try
      {
        switch (Settings.Mode)
        {
          case IRServerMode.ServerMode:
            StopServer();
            break;

          case IRServerMode.RelayMode:
            StopRelay();
            break;

          case IRServerMode.RepeaterMode:
            StopRepeater();
            break;
        }
      }
      catch (Exception ex)
      {
        IrssLog.Error(ex);
      }
    }
Esempio n. 3
0
    /// <summary>
    /// Called when the service is started.
    /// </summary>
    /// <param name="args">The arguments.</param>
    protected override void OnStart(string[] args)
    {
      IrssLog.Info("Starting IR Server ...");

      Settings.LoadSettings();

      #region Process Priority Adjustment

      if (!Settings.ProcessPriority.Equals("No Change", StringComparison.OrdinalIgnoreCase))
      {
        try
        {
          ProcessPriorityClass priority =
            (ProcessPriorityClass)Enum.Parse(typeof(ProcessPriorityClass), Settings.ProcessPriority, true);
          Process.GetCurrentProcess().PriorityClass = priority;

          IrssLog.Info("Process priority set to: {0}", Settings.ProcessPriority);
        }
        catch (Exception ex)
        {
          IrssLog.Error(ex);
        }
      }

      #endregion Process Priority Adjustment

      LoadPlugins();

      #region Mode select

      try
      {
        switch (Settings.Mode)
        {
          case IRServerMode.ServerMode:
            StartServer();
            IrssLog.Info("Started in Server Mode");
            break;

          case IRServerMode.RelayMode:
            if (StartRelay())
              IrssLog.Info("Started in Relay Mode");
            else
              IrssLog.Error("Failed to start in Relay Mode");
            break;

          case IRServerMode.RepeaterMode:
            if (StartRepeater())
              IrssLog.Info("Started in Repeater Mode");
            else
              IrssLog.Error("Failed to start in Repeater Mode");
            break;
        }
      }
      catch (Exception ex)
      {
        IrssLog.Error("Failed to start IR Server Communications");
        IrssLog.Error(ex);
      }

      #endregion Mode select

      StartPlugins();

      #region Setup Abstract Remote Model processing

      if (Settings.AbstractRemoteMode)
      {
        IrssLog.Info("IR Server is running in Abstract Remote mode");

        _abstractRemoteButtons = new DataSet("AbstractRemoteButtons");
        _abstractRemoteButtons.CaseSensitive = true;

        if (_receivePlugins != null)
          foreach (PluginBase plugin in _receivePlugins)
            if (plugin is IRemoteReceiver)
              LoadAbstractDeviceFiles(plugin.Name);
      }

      #endregion Setup Abstract Remote Model processing

      #region Setup Hardware Monitoring

      if (Settings.RestartOnUSBChanges)
      {
        _hardwareMonitor = new HardwareMonitor();
        _hardwareMonitor.DeviceConnected += new HardwareMonitor.HardwareMonitorEvent(OnDeviceConnected);
        _hardwareMonitor.Start();
      }

      #endregion

      IrssLog.Info("IR Server started");
    }