Example #1
0
    private static void ClickSetup(object sender, EventArgs e)
    {
      IrssLog.Info("Setup");

      _inConfiguration = true;

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

      if (Configure())
        ChangeSkin();

      try
      {
        _webServer = new WebServer(_webPort);
        _webServer.Run();
      }
      catch (Exception ex)
      {
        IrssLog.Error(ex);
        MessageBox.Show(ex.Message, "Web Remote - Setup Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }

      _inConfiguration = false;
    }
Example #2
0
    private static void Main()
    {
      // Check for multiple instances.
      if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length != 1)
        return;

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

      IrssLog.LogLevel = IrssLog.Level.Debug;
      IrssLog.Open("Web Remote.log");

      Application.ThreadException += Application_ThreadException;

      LoadSettings();

      if (String.IsNullOrEmpty(_serverHost))
      {
        ServerAddress serverAddress = new ServerAddress();
        serverAddress.ShowDialog();

        _serverHost = serverAddress.ServerHost;
      }

      bool clientStarted = false;

      IPAddress serverIP = Network.GetIPFromName(_serverHost);
      IPEndPoint endPoint = new IPEndPoint(serverIP, Server.DefaultPort);

      try
      {
        clientStarted = StartClient(endPoint);
      }
      catch (Exception ex)
      {
        IrssLog.Error(ex);
        clientStarted = false;
      }

      if (clientStarted)
      {
        ContextMenuStrip contextMenu = new ContextMenuStrip();
        contextMenu.Items.Add(new ToolStripMenuItem("&Setup", null, new EventHandler(ClickSetup)));
        contextMenu.Items.Add(new ToolStripMenuItem("&Quit", null, new EventHandler(ClickQuit)));

        _container = new Container();
        _notifyIcon = new NotifyIcon(_container);
        _notifyIcon.ContextMenuStrip = contextMenu;
        _notifyIcon.DoubleClick += ClickSetup;
        _notifyIcon.Icon = Resources.Icon;
        _notifyIcon.Text = "Web Remote";

        ChangeSkin();

        try
        {
          _webServer = new WebServer(_webPort);
          _webServer.Run();
        }
        catch (Exception ex)
        {
          IrssLog.Error(ex);
        }

        _notifyIcon.Visible = true;

        Application.Run();

        _notifyIcon.Visible = false;

        if (_webServer != null)
          _webServer.Stop();
      }

      SaveSettings();

      StopClient();

      Application.ThreadException -= Application_ThreadException;

      IrssLog.Close();
    }