//--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; }
private void internalSave(string internalLocation) { // Copy all jvm options from listbox into the cofiguration string[] values = new string[this.jvmOptionsListBox.Items.Count]; if (this.jvmOptionsListBox.Items.Count > 0) { this.jvmOptionsListBox.Items.CopyTo(values, 0); this.configuration.config.jvmParameters = values; } else { // The schema does not support empty <jvmParameters/> element this.configuration.config.jvmParameters = null; } // Set the on runtime exit script this.configuration.config.onRuntimeExitScript = this.scriptLocationTextBox.Text; // Save memory management configuration ushort memoryLimit = Convert.ToUInt16(memoryLimitNumericUpDown.Value); if (memoryLimit > 0) { this.configuration.config.memoryLimit = memoryLimit; } // Save multi process related config this.configuration.config.nbRuntimes = Convert.ToUInt16(this.nbRuntimesNumericUpDown.Value); this.configuration.config.nbWorkers = Convert.ToUInt16(this.nbWorkersNumericUpDown.Value); //--Events list this.internalCopyEventsList(); // Save ProActive Communication Protocol and Port initial value this.configuration.config.protocol = (string)this.protocolComboBox.SelectedItem; this.configuration.config.portRange.first = Convert.ToUInt16(this.portInitialValueNumericUpDown.Value); // Save all defined actions if (this.configuration.connections == null || this.configuration.connections.Length < 3) { this.configuration.connections = new ConfigParser.ConnectionType[3]; } // Save rmi registration action definition LocalBindConnectionType localbind = new LocalBindConnectionType(); if (!"".Equals(localRegistrationNodeName.Text)) { localbind.nodename = localRegistrationNodeName.Text; } localbind.javaStarterClass = this.rmiRegistrationJavaActionClassTextBox.Text; localbind.enabled = this.localRegistrationRadioButton.Checked; this.configuration.connections[0] = localbind; // Save resource manager registration action definition ResoureManagerConnectionType rmConnection = new ResoureManagerConnectionType(); if (!"".Equals(rmUrl.Text)) { rmConnection.url = rmUrl.Text; } if (!"".Equals(nodeNameTextBox.Text)) { rmConnection.nodename = nodeNameTextBox.Text; } if (!"".Equals(nodeSourceNameTextBox.Text)) { rmConnection.nodeSourceName = nodeSourceNameTextBox.Text; } if (!"".Equals(credentialLocationTextBox.Text)) { rmConnection.credential = credentialLocationTextBox.Text; } if (!"".Equals(this.resourceManagerRegistrationJavaActionClassTextBox.Text)) { rmConnection.javaStarterClass = this.resourceManagerRegistrationJavaActionClassTextBox.Text; } rmConnection.enabled = this.resourceManagerRegistrationRadioButton.Checked; this.configuration.connections[1] = rmConnection; // Save custom action definition CustomConnectionType customAction = new CustomConnectionType(); if (this.customArgumentsListBox.Items.Count > 0) { string[] arguments = new string[this.customArgumentsListBox.Items.Count]; customArgumentsListBox.Items.CopyTo(arguments, 0); customAction.args = arguments; } customAction.javaStarterClass = this.customJavaActionClassTextBox.Text; customAction.enabled = this.customRadioButton.Checked; this.configuration.connections[2] = customAction; // Save the configuration into a file try { ConfigurationParser.saveXml(internalLocation, this.configuration); } catch (Exception exception) { MessageBox.Show("Could not save the configuration file: " + exception.ToString()); } this.hook.askAndRestart(); }