static void Main() { if (!ProcessChecker.IsOnlyProcess("ProActive Agent Control")) { return; } // Guest accounts Check if the current user have admin rights WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); if (principal.IsInRole(WindowsBuiltInRole.Guest)) { // report error and exit MessageBox.Show("Guest users cannot run the ProActive Agent Control.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check if this application is already running Process[] alreadyRunningProcesses = Process.GetProcessesByName("AgentForAgent"); if (alreadyRunningProcesses != null && alreadyRunningProcesses.Length > 1) { return; } // Check agent and config locations in the registry (setted during agent installation) // ie check if the agent was correctly installed try { RegistryKey agentKey = Registry.LocalMachine.OpenSubKey(Constants.REG_SUBKEY); if (agentKey == null) { // Cannot continue, report error message box and exit MessageBox.Show("Can not open the following registry subkey (LocalMachine) " + Constants.REG_SUBKEY + ". It appears that the agent might not have been installed properly.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string agentLocation = (string)agentKey.GetValue(Constants.INSTALL_LOCATION_REG_VALUE_NAME); if (agentLocation == null) { // report error and exit MessageBox.Show("Cannot get the agent location in " + Constants.REG_SUBKEY + ". It appears that the agent might not have been installed properly.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); // Close the registry key agentKey.Close(); return; } string configLocation = (string)agentKey.GetValue(Constants.CONFIG_LOCATION_REG_VALUE_NAME); if (configLocation == null) { // report error and exit MessageBox.Show("Cannot get the config location in " + Constants.REG_SUBKEY + ". It appears that the agent might not have been installed properly.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); // Close the registry key agentKey.Close(); return; } string logsDirectory = (string)agentKey.GetValue(Constants.LOGS_DIR_REG_VALUE_NAME); if (logsDirectory == null) { // report error and exit MessageBox.Show("Cannot get the logs directory in " + Constants.REG_SUBKEY + ". It appears that the agent might not have been installed properly.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); // Close the registry key agentKey.Close(); return; } // Close the registry key agentKey.Close(); // Connect to the agent service ServiceController sc = null; try { sc = new ServiceController(Constants.SERVICE_NAME); } catch (Exception e) { MessageBox.Show("Could not connect to the service " + Constants.SERVICE_NAME + ". It appears that the agent might not have been installed properly. " + e.ToString(), "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Launch the GUI Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AgentWindow dialog = new AgentWindow(agentLocation, configLocation, logsDirectory, sc); Application.Run(dialog); } catch (Exception e) { MessageBox.Show("Unable to run the ProActive Agent Control " + e.ToString(), "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//--Constructor public ConfigurationEditor(AgentType conf, string confLocation, string agentLocation, AgentWindow hook) { // First initialize all widgets (gui-generated) InitializeComponent(); this.configuration = conf; this.configurationLocation = confLocation; this.agentLocation = agentLocation; this.hook = hook; // Load the proactive location from the configuration into the gui this.proactiveDirectory.Text = conf.config.proactiveHome; if (conf.config.javaHome.Equals("")) { checkBox1.Checked = true; jvmDirectory.Enabled = false; jvmLocationButton.Enabled = false; } else { jvmDirectory.Text = conf.config.javaHome; } // Load the On Runtime Exit script absolute path this.scriptLocationTextBox.Text = conf.config.onRuntimeExitScript; /////////////////////////////////////////////////// // Load memory management from the configuration // /////////////////////////////////////////////////// // Get total physical memory System.Decimal val = Utils.getAvailablePhysicalMemory(); this.availablePhysicalMemoryValue.Text = val.ToString(); // Set maximums this.memoryLimitNumericUpDown.Maximum = val; // Load memory limit values from the configuration this.memoryLimitNumericUpDown.Value = conf.config.memoryLimit; /////////////////////////////////////// // Load Multi-Runtime related config // /////////////////////////////////////// this.availableCPUsValue.Text = "" + Environment.ProcessorCount; if (conf.config.nbRuntimes == 0) { this.nbRuntimesNumericUpDown.Value = 1; } else { this.nbRuntimesNumericUpDown.Value = conf.config.nbRuntimes; this.nbRuntimesNumericUpDown.Enabled = true; } if (conf.config.nbWorkers == 0) { this.nbWorkersNumericUpDown.Value = Environment.ProcessorCount; } else { this.nbWorkersNumericUpDown.Value = conf.config.nbWorkers; this.nbWorkersNumericUpDown.Enabled = true; } //////////////////////////////////////// // Load events from the configuration // //////////////////////////////////////// // Init default values for list boxes this.weekdayStart.SelectedIndex = 0; // Always available (empty array or see CalendarEventType.isAlwaysAvailable()) if (this.configuration.isAlwaysAvailable()) { this.alwaysAvailableCheckBox.Checked = true; this.processPriorityComboBox.SelectedItem = Enum.GetName(typeof(ProcessPriorityClass), configuration.config.processPriority); this.maxCpuUsageNumericUpDown.Value = configuration.config.maxCpuUsage; } else { // Set default values for the no events selected state this.processPriorityComboBox.SelectedIndex = 0; this.maxCpuUsageNumericUpDown.Value = this.maxCpuUsageNumericUpDown.Maximum; // Load config events in the GUI foreach (CalendarEventType cEv in this.configuration.events) { this.eventsList.Items.Add(cEv); } } // Init default values for ProActive Communication Protocol and Port this.protocolComboBox.SelectedItem = Enum.GetName(typeof(ProActiveCommunicationProtocol), Enum.Parse(typeof(ProActiveCommunicationProtocol), conf.config.protocol)); this.portInitialValueNumericUpDown.Value = conf.config.portRange.first; ///////////////////////////////////////////// // Load the actions from the configuration // ///////////////////////////////////////////// // Iterate through all actions in the configuration then // load them into the gui foreach (ConnectionType con in this.configuration.connections) { if (con.GetType() == typeof(LocalBindConnectionType)) { if (con.enabled) { this.localRegistrationRadioButton.Select(); this.connectionTypeTabControl.SelectedTab = this.localRegistrationTabPage; } if (con.javaStarterClass == null || con.javaStarterClass.Equals("")) { this.rmiRegistrationJavaActionClassTextBox.Text = LocalBindConnectionType.DEFAULT_JAVA_STARTER_CLASS; } else { this.rmiRegistrationJavaActionClassTextBox.Text = con.javaStarterClass; } LocalBindConnectionType localbind = (LocalBindConnectionType)con; this.localRegistrationNodeName.Text = localbind.nodename; } else if (con.GetType() == typeof(ResoureManagerConnectionType)) { if (con.enabled) { this.resourceManagerRegistrationRadioButton.Select(); this.connectionTypeTabControl.SelectedTab = this.resourceManagerRegistrationTabPage; } if (con.javaStarterClass == null || con.javaStarterClass.Equals("")) { this.resourceManagerRegistrationJavaActionClassTextBox.Text = ResoureManagerConnectionType.DEFAULT_JAVA_STARTER_CLASS; } else { this.resourceManagerRegistrationJavaActionClassTextBox.Text = con.javaStarterClass; } ResoureManagerConnectionType rmAction = (ResoureManagerConnectionType)con; this.rmUrl.Text = rmAction.url; this.nodeNameTextBox.Text = rmAction.nodename; this.nodeSourceNameTextBox.Text = rmAction.nodeSourceName; this.credentialLocationTextBox.Text = rmAction.credential; } else if (con.GetType() == typeof(CustomConnectionType)) { if (con.enabled) { this.customRadioButton.Select(); this.connectionTypeTabControl.SelectedTab = this.customTabPage; } if (con.javaStarterClass == null || con.javaStarterClass.Equals("")) { this.customJavaActionClassTextBox.Text = CustomConnectionType.DEFAULT_JAVA_STARTER_CLASS; } else { this.customJavaActionClassTextBox.Text = con.javaStarterClass; } CustomConnectionType customConnection = (CustomConnectionType)con; if (customConnection.args != null) { this.customArgumentsListBox.Items.AddRange(customConnection.args); } } else { // Unknown action } } //--Chart chart = new Chart(); iniConfiguration = new IniFile(this.agentLocation + "\\configuration.ini"); this.internalSave(this.configurationLocation); this.saveConfig.Enabled = false; }