/// <summary> /// Initialize Devel79 Tray. /// </summary> /// <param name="configurationFile">Configuration file</param> /// <param name="runServers">Servers name to run</param> public void Initialize(string configurationFile, string[] runServers) { if (IsAlreadyRunning()) { throw new ProgramException("Only one instance of Devel79 Tray is allowed."); } vboxServer = new VirtualBoxServer(); ConfigurationReader configurationReader = new ConfigurationReader(this, vboxServer, configurationFile); servers = configurationReader.GetServers(); if (servers.Count == 0) { throw new ProgramException("No server is defined in \"" + configurationReader.GetConfigurationFile() + "\"."); } miServers = new Dictionary <Server, ToolStripMenuItem>(); int position = trayMenu.Items.IndexOf(separatorShowDefaultConsole); foreach (Server server in servers.Values) { ToolStripMenuItem miServer = server.GetMenuServer(); // because server.GetMenuServer().Visible = true/false not working... miServers.Add(server, miServer); trayMenu.Items.Insert(++position, miServer); miStartServers.DropDownItems.Add(server.GetMenuStartServer()); } trayIcon.Visible = true; try { // Initialize VirtualBox servers vboxServer.Initialize(servers); if (runServers.Length > 0) { foreach (string runServer in runServers) { if (servers.ContainsKey(runServer.ToLower())) { servers[runServer.ToLower()].StartServer(); } else { throw new ProgramException("Server to run \"" + runServer + "\" is not specified in configuration file \"" + configurationReader.GetConfigurationFile() + "\"."); } } } } catch (ProgramException e) { trayIcon.Visible = false; throw e; } UpdateTray(); }
/// <summary> /// Class constructor. /// </summary> /// <param name="tray">Main program</param> /// <param name="vboxServer">VirtualBox wrapper</param> /// <param name="configurationFile">Absolute path to configuration file</param> public ConfigurationReader(Devel79Tray tray, VirtualBoxServer vboxServer, string configurationFile) { this.tray = tray; this.vboxServer = vboxServer; this.configurationFile = configurationFile; this.servers = new Dictionary <string, Server>(); }
/// <summary> /// Class constructor. /// </summary> /// <param name="tray">Main program</param> /// <param name="vboxServer">VirtualBox wrapper</param> /// <param name="configurationFile">Absolute path to configuration file</param> public ConfigurationReader(Devel79Tray tray, VirtualBoxServer vboxServer, string configurationFile) { this.tray = tray; this.vboxServer = vboxServer; this.configurationFile = configurationFile; this.servers = new Dictionary<string, Server>(); }
/// <summary> /// Create new server. /// </summary> public Server(Devel79Tray tray, VirtualBoxServer vboxServer) { this.tray = tray; this.vboxServer = vboxServer; this.watchingDirectories = new Dictionary <string, DirectoryMonitor>(); this.commands = new Dictionary <string, string>(); this.menuGenerated = false; this.running = false; this.status = VirtualBoxServer.Status.POWEREDOFF; }
/// <summary> /// Initialize VirtualBox event listener. /// </summary> /// <param name="vboxServer">VirtualBox server</param> public VirtualBoxEventListener(VirtualBoxServer vboxServer) { this.vboxServer = vboxServer; }
/// <summary> /// Create Devel79Tray. /// </summary> /// <param name="runServerAtStartup">Run server at startup.</param> /// <param name="configurationReader">Configuration read from file.</param> public Devel79Tray(bool runServerAtStartup, ConfigurationReader configurationReader) { // Test only one instace is running... if (IsAlreadyRunning()) { throw new Exception("Only one instance of Devel79 Tray is allowed."); } // Read configuration... if (!configurationReader.Read()) { throw new Exception("Configuration file \"" + configurationReader.GetConfigurationFile() + "\" doesn't exist or can't be read."); } // Create VirtualBox machine vboxServer = new VirtualBoxServer(this, configurationReader.GetName(), configurationReader.GetMachine(), configurationReader.GetIp()); // Prepare menu miShowConsole = new ToolStripMenuItem("Show &console"); miShowConsole.Font = new Font(miShowConsole.Font, miShowConsole.Font.Style | FontStyle.Bold); miShowConsole.Visible = false; miShowConsole.Click += MenuShowConsole; miHideConsole = new ToolStripMenuItem("Hide &console"); miHideConsole.Font = new Font(miShowConsole.Font, miShowConsole.Font.Style | FontStyle.Bold); miHideConsole.Visible = false; miHideConsole.Click += MenuHideConsole; miStartServer = new ToolStripMenuItem("&Start server"); miStartServer.Visible = false; miStartServer.Click += MenuStartServer; miStopServer = new ToolStripMenuItem("S&top server"); miStopServer.Visible = false; miStopServer.Click += MenuStopServer; miRestartServer = new ToolStripMenuItem("&Restart server"); miRestartServer.Visible = false; miRestartServer.Click += MenuRestartServer; miPingServer = new ToolStripMenuItem("&Ping server"); miPingServer.Visible = false; miPingServer.Click += MenuPingServer; ToolStripMenuItem miExit = new ToolStripMenuItem("E&xit"); miExit.Click += MenuExit; trayMenu = new ContextMenuStrip(); trayMenu.Items.Add(miShowConsole); trayMenu.Items.Add(miHideConsole); trayMenu.Items.Add(miStartServer); trayMenu.Items.Add(miStopServer); trayMenu.Items.Add(miRestartServer); trayMenu.Items.Add(miPingServer); trayMenu.Items.Add("-"); trayMenu.Items.Add(miExit); trayIcon = new NotifyIcon(); trayIcon.Text = configurationReader.GetName(); trayIcon.Icon = Properties.Resources.IconServer; // Add menu to tray icon and show it. trayIcon.MouseDoubleClick += ToggleConsole; trayIcon.ContextMenuStrip = trayMenu; trayIcon.Visible = true; // Load icons iconRun = Properties.Resources.IconServerRun; iconStop = Properties.Resources.IconServerStop; // Initialize VirtualBox machine try { vboxServer.Initialize(runServerAtStartup); } catch (Exception e) { throw e; } }
/// <summary> /// Set server status. /// </summary> /// <param name="status">Server status</param> /// <param name="initializing">True if is seting status during application initializing, false otherwise</param> public void SetStatus(VirtualBoxServer.Status status, bool initializing) { this.status = status; if (status == VirtualBoxServer.Status.POWEREDOFF) { SetPoweredOff(); } else if (status == VirtualBoxServer.Status.RUNNING) { SetRunning(initializing); } }
/// <summary> /// Create new server. /// </summary> public Server(Devel79Tray tray, VirtualBoxServer vboxServer) { this.tray = tray; this.vboxServer = vboxServer; this.watchingDirectories = new Dictionary<string, DirectoryMonitor>(); this.commands = new Dictionary<string, string>(); this.menuGenerated = false; this.running = false; this.status = VirtualBoxServer.Status.POWEREDOFF; }
/// <summary> /// Initialize Devel79 Tray. /// </summary> /// <param name="configurationFile">Configuration file</param> /// <param name="runServers">Servers name to run</param> public void Initialize(string configurationFile, string[] runServers) { if (IsAlreadyRunning()) { throw new ProgramException("Only one instance of Devel79 Tray is allowed."); } vboxServer = new VirtualBoxServer(); ConfigurationReader configurationReader = new ConfigurationReader(this, vboxServer, configurationFile); servers = configurationReader.GetServers(); if (servers.Count == 0) { throw new ProgramException("No server is defined in \"" + configurationReader.GetConfigurationFile() + "\"."); } miServers = new Dictionary<Server, ToolStripMenuItem>(); int position = trayMenu.Items.IndexOf(separatorShowDefaultConsole); foreach (Server server in servers.Values) { ToolStripMenuItem miServer = server.GetMenuServer(); // because server.GetMenuServer().Visible = true/false not working... miServers.Add(server, miServer); trayMenu.Items.Insert(++position, miServer); miStartServers.DropDownItems.Add(server.GetMenuStartServer()); } trayIcon.Visible = true; try { // Initialize VirtualBox servers vboxServer.Initialize(servers); if (runServers.Length > 0) { foreach (string runServer in runServers) { if (servers.ContainsKey(runServer.ToLower())) { servers[runServer.ToLower()].StartServer(); } else { throw new ProgramException("Server to run \"" + runServer + "\" is not specified in configuration file \"" + configurationReader.GetConfigurationFile() + "\"."); } } } } catch (ProgramException e) { trayIcon.Visible = false; throw e; } UpdateTray(); }