/// <summary> /// Creates a new PlanetLab manager node event arguments instance. /// </summary> /// <param name="state">The manager state.</param> /// <param name="node">The PlanetLab node.</param> /// <param name="command">The PlanetLab command.</param> /// <param name="set">The PlanetLab command parameter set.</param> public PlManagerCommandEventArgs(PlManagerState state, PlNode node, PlCommand command, int set) { this.State = state; this.Node = node; this.Command = command; this.Set = set; }
/// <summary> /// Creates a new PlanetLab manager node event arguments instance. /// </summary> /// <param name="state">The manager state.</param> /// <param name="node">The PlanetLab node.</param> /// <param name="command">The PlanetLab command.</param> /// <param name="set">The PlanetLab command parameter set.</param> /// <param name="exception">The command exception.</param> public PlManagerSubcommandEventArgs(PlManagerState state, PlNode node, PlCommand command, int set, Exception exception) { this.State = state; this.Node = node; this.Command = command; this.Set = set; this.Exception = exception; }
// Public methods. /// <summary> /// Shows the add PlanetLab command dialog. /// </summary> /// <returns>The dialog result.</returns> public new DialogResult ShowDialog() { // Create a new empty command. this.control.Command = new PlCommand(); // Show the dialog. return base.ShowDialog(); }
/// <summary> /// Creates a new PlanetLab manager node event arguments instance. /// </summary> /// <param name="state">The manager state.</param> /// <param name="node">The PlanetLab node.</param> /// <param name="command">The PlanetLab command.</param> /// <param name="set">The PlanetLab command parameter set.</param> /// <param name="success">The number of successful subcommands.</param> /// <param name="failed">The number of failed subcommands.</param> public PlManagerCommandEventArgs(PlManagerState state, PlNode node, PlCommand command, int set, int success, int failed) { this.State = state; this.Node = node; this.Command = command; this.Set = set; this.Success = success; this.Failed = failed; }
// Public methods. /// <summary> /// Adds a new item to the image list box. /// </summary> /// <param name="text">The item text.</param> /// <param name="image">The item image.</param> public void AddItem(PlCommand command) { // Create a new command list box item. CommandListBoxItem item = new CommandListBoxItem(command); // Add the item to the list box. this.Items.Add(item); }
/// <summary> /// Runs a command on the specified PlanetLab node. /// </summary> /// <param name="state">The manager state.</param> /// <param name="node">The PlanetLab node state.</param> /// <param name="command">The PlanetLab command.</param> /// <param name="set">The command parameter set.</param> /// <param name="sshClient">The SSH client.</param> private void OnRunCommand(PlManagerState state, PlManagerNodeState node, PlCommand command, int set, SshClient sshClient) { // Raise the command started event. if (null != this.CommandStarted) this.CommandStarted(this, new PlManagerCommandEventArgs(state, node.Node, command, set)); try { // Compute the command text. string commandText = set >= 0 ? command.GetCommand(set) : command.Command; // The number of subcommands. int success = 0; int fail = 0; // Divide the command into subcommands. string[] subcommands = commandText.Split(PlManager.subcommandSeparators, StringSplitOptions.RemoveEmptyEntries); // For all subcommands. foreach (string subcommand in subcommands) { // If the operation has been paused, wait for resume. if (state.IsPaused) { state.WaitPause(); } // If the operation has been canceled, return. if (state.IsStopped) { // Raise the canceled event. if (null != this.CommandCanceled) this.CommandCanceled(this, new PlManagerCommandEventArgs(state, node.Node, command, set)); // Return. return; } // If the subcommand is empty, continue to the next subcommand. if (string.IsNullOrWhiteSpace(subcommand)) continue; // Create a new SSH command. using (SshCommand sshCommand = sshClient.CreateCommand(subcommand)) { try { // The command duration. TimeSpan duration; // The retry count. int retry = 0; do { // The start time. DateTime startTime = DateTime.Now; // Execute the command. sshCommand.Execute(); // Compute the command duration. duration = DateTime.Now - startTime; } while ((retry++ < state.Slice.CommandRetries) && (sshCommand.ExitStatus != 0)); // Create a new command state. PlManagerSubcommandState subcommandState = new PlManagerSubcommandState(node, sshCommand, duration, retry - 1); // Increment the number of successful subcommands. success++; // Add the subcommand. node.AddSubcommand(subcommandState); // Raise a subcommand success event. if (null != this.SubcommandSuccess) this.SubcommandSuccess(this, new PlManagerSubcommandEventArgs(state, node.Node, command, set, subcommandState)); } catch (Exception exception) { // Create a new subcommand state. PlManagerSubcommandState subcommandState = new PlManagerSubcommandState(node, sshCommand, exception); // Increment the number of failed subcommands. fail++; // Add the subcommand. node.AddSubcommand(subcommandState); // Raise a subcommand fail event. if (null != this.SubcommandFail) this.SubcommandFail(this, new PlManagerSubcommandEventArgs(state, node.Node, command, set, exception)); } } } // Raise a command completed event. if (null != this.CommandFinishedSuccess) this.CommandFinishedSuccess(this, new PlManagerCommandEventArgs(state, node.Node, command, set, success, fail)); } catch (Exception exception) { // Raise a command completed event. if (null != this.CommandFinishedFail) this.CommandFinishedFail(this, new PlManagerCommandEventArgs(state, node.Node, command, set, exception)); } }
/// <summary> /// Sets the current PlanetLab command. /// </summary> /// <param name="command">The command,</param> private void OnSetCommand(PlCommand command) { // Set the command. this.command = command; // Disable the buttons. this.buttonAddParameters.Enabled = false; this.buttonRemoveParameter.Enabled = false; // Clear the command parameters. this.dataParameters.Rows.Clear(); this.dataParameters.Columns.Clear(); // If the command is not null. if (null != this.command) { // Enable the control. this.Enable(); // Update the command information. this.textBox.Text = this.command.Command; // Refresh the text box. this.textBox.Refresh(); // Call the command changed. this.OnCommandChanged(this, EventArgs.Empty); // Update the number of parameter sets. this.dataParameters.Rows.Clear(); // If the command has a positive number of parameters sets. if (this.command.SetsCount > 0) { this.dataParameters.Rows.Add(this.command.SetsCount); } // Load the command parameters. for (int column = 0; column < this.dataParameters.Columns.Count; column++) { for (int row = 0; row < this.dataParameters.Rows.Count; row++) { this.dataParameters[column, row].Value = this.command[column, row]; } } } else { // Disable the control. this.Disable(); // Clear the command text. this.textBox.Clear(); // Set the status. this.OnSetStatus("No PlanetLab command selected.", Resources.Warning_16); } // Disable the save and undo buttons. this.buttonSave.Enabled = false; this.buttonUndo.Enabled = false; }
/// <summary> /// Creates a new event arguments instance. /// </summary> /// <param name="command">The PlanetLab command.</param> public PlCommandEventArgs(PlCommand command) { this.Command = command; }
/// <summary> /// Creates a new image list box item. /// </summary> /// <param name="command">The PlanetLab command.</param> public CommandListBoxItem(PlCommand command) { this.command = command; }