/// <summary> /// Creates a new configuration slice instance. /// </summary> /// <param name="slice">The slice.</param> /// <param name="rootKey">The root registry key.</param> public PlConfigSlice(PlSlice slice, RegistryKey rootKey) { // Check the arguments. if (null == slice) throw new ArgumentNullException("slice"); // Set the slice. this.slice = slice; // Set the slice event handler. this.slice.Changed += this.OnSliceChanged; // Open or create the subkey for the current slice. if (null == (this.key = rootKey.OpenSubKey(this.slice.Id.Value.ToString(), RegistryKeyPermissionCheck.ReadWriteSubTree))) { // If the key does not exist, create the key. this.key = rootKey.CreateSubKey(this.slice.Id.Value.ToString()); } // Check the commands directory exists. if (!Directory.Exists(CrawlerConfig.Static.PlanetLabSlicesFolder)) { // If the directory does not exist, create it. Directory.CreateDirectory(CrawlerConfig.Static.PlanetLabSlicesFolder); } // Create the slice log. this.log = new Logger(CrawlerConfig.Static.PlanetLabSlicesLogFileName.FormatWith(this.slice.Id, "{0}", "{1}", "{2}")); // Create the slice commands configuration. this.commands = new PlConfigSliceCommands(this.key, this.slice.Id.Value); }
// Public methods. /// <summary> /// Opens the modal dialog to remove a slice from one or more PlanetLab nodes. /// </summary> /// <param name="slice">The PlanetLab slice.</param> /// <returns>The dialog result.</returns> public DialogResult ShowDialog(PlSlice slice) { // Reset the result. this.Result = null; // Refresh the results list. this.control.Refresh(slice); // Show the dialog. return base.ShowDialog(); }
/// <summary> /// Creates a new PlanetLab manager history instance for the specified folder. /// </summary> /// <param name="slice">The PlanetLab slice.</param> public PlManagerHistory(PlSlice slice) { // Validate the arguments. if (null == slice) throw new ArgumentNullException("slice"); try { // If the file exists. if (File.Exists(CrawlerConfig.Static.PlanetLabHistoryFileName)) { // Load from file the list of runs. using (FileStream file = new FileStream(CrawlerConfig.Static.PlanetLabHistoryFileName, FileMode.Open)) { file.Deserialize<PlManagerHistory>(this); } } } catch { // Catch all exceptions. } }
/// <summary> /// An event handler called when the user renewes a PlanetLab slice. /// </summary> /// <param name="sender">The sender object.</param> /// <param name="e">The event arguments.</param> private void OnRenewed(object sender, PlObjectEventArgs<PlSlice> e) { // Set the result. this.Result = e.Object; // Set the dialog result. this.DialogResult = DialogResult.OK; }
/// <summary> /// Returns the configuration for the specified slice. /// </summary> /// <param name="slice">The slice.</param> /// <returns>The slice configuration.</returns> public PlConfigSlice GetSliceConfiguration(PlSlice slice) { // Validate the arguments. if (null == slice) throw new ArgumentNullException("slice"); // If the slice does not have a valid identifier, throw an exception. if (!slice.Id.HasValue) throw new CrawlerException("The slice does not have a valid identifier."); // Return the configuration. PlConfigSlice configSlice; // Try and get the configuration. if (!this.configSlices.TryGetValue(slice.Id.Value, out configSlice)) { // If the configuration does not exist, throw an exception. throw new CrawlerException("The specified slice does not have a configuration."); } return configSlice; }
// Public methods. /// <summary> /// Refreshes the control using the specified PlanetLab slice. /// </summary> /// <param name="slice">The slice.</param> public void Refresh(PlSlice slice) { // Set the current slice. this.slice = slice; // Reset the buttons. this.buttonRefresh.Enabled = true; this.buttonCancel.Enabled = false; this.buttonSelect.Enabled = false; this.buttonClose.Enabled = true; // Clear the list of nodes. this.nodes.Clear(); // Update the list of nodes. this.OnUpdateNodes(); }
/// <summary> /// Refreshes the information of the specified slice. /// </summary> /// <param name="slice">The slice.</param> private void OnRefreshSlice(PlSlice slice) { // Create the request state. SliceRequestState requestState = new SliceRequestState( this.OnRefreshSliceRequestStarted, this.OnRefreshSliceRequestResult, null, null, this.OnRefreshSliceRequestFinished, slice); // Begin an asynchronous PlanetLab request. this.BeginRequest( this.requestGetSlices, this.crawler.PlanetLab.Username, this.crawler.PlanetLab.Password, PlSlice.GetFilter(PlSlice.Fields.SliceId, slice.Id), requestState); }
// Public methods. /// <summary> /// Initializes the control with a crawler object. /// </summary> /// <param name="crawler">The crawler object.</param> /// <param name="slice">The slice.</param> /// <param name="controls">The controls collection.</param> /// <param name="treeNode">The tree node corresponding to this control.</param> public void Initialize(Crawler crawler, PlSlice slice, Control.ControlCollection controls, TreeNode treeNode) { // Save the parameters. this.crawler = crawler; // Get the status handler. this.status = this.crawler.Status.GetHandler(this); // Set the slice. this.slice = slice; this.slice.Changed += this.OnSliceChanged; // Set the controls. this.controls = controls; // Set the tree node. this.treeNodeSlice = treeNode; // Set the slice configuration. this.config = this.crawler.PlanetLab.GetSliceConfiguration(this.slice); // Set the title. this.panelSlice.Title = "PlanetLab Slice ({0})".FormatWith(this.slice.Name); // Enable the control. this.Enabled = true; // Update the information of the PlanetLab slice. this.OnUpdateSlice(); // Create the run option. this.OnCreateRun(); // Create the log option. this.OnCreateLog(); }
/// <summary> /// Adds a slice to the current control. /// </summary> /// <param name="slice">The slice.</param> private void OnAddSlice(PlSlice slice) { // Create a new tree node. TreeNode node = new TreeNode("Slice ({0})".FormatWith(slice.Name)); node.ImageKey = "GlobeObject"; node.SelectedImageKey = "GlobeObject"; this.treeNode.Nodes.Add(node); this.treeNode.ExpandAll(); // Create a new control. ControlSlice control = new ControlSlice(); control.Initialize(this.crawler, slice, this.controls, node); this.controls.Add(control); // Set the node tag. node.Tag = control; // Create the list view item. ListViewItem item = new ListViewItem(new string[] { slice.Id.HasValue ? slice.Id.Value.ToString() : string.Empty, slice.Name, slice.Created.ToString(), slice.Expires.ToString(), slice.NodeIds != null ? slice.NodeIds.Length.ToString() : "0", slice.MaxNodes.ToString() }, 0); item.Tag = new SliceInfo(slice, node, control); // Add the item to the list view. this.listViewSlices.Items.Add(item); // Add the slice changed event handler. slice.Changed += this.OnSliceChanged; }
/// <summary> /// An event handler called when adding a slice to PlanetLab nodes. /// </summary> /// <param name="slice">The slice.</param> /// <param name="ids">The list of node IDs.</param> private void OnAddSliceToNodes(PlSlice slice, int[] ids) { // If the slice does not have an ID, show an error message and return. if (!slice.Id.HasValue) { MessageBox.Show(this, "The selected slice does not have an identifier.", "Add Slice to Nodes", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Update the status. this.status.Send( ApplicationStatus.StatusType.Busy, "Showing {0} PlanetLab slices.".FormatWith(this.crawler.PlanetLab.LocalSlices.Count), "Adding slice {0} to {1} PlanetLab node{2}...".FormatWith(slice.Id, ids.Length, ids.Length.PluralSuffix()), Resources.GlobeLab_16, Resources.GlobeClock_16); // Log this.controlLog.Add(this.crawler.Log.Add( LogEventLevel.Verbose, LogEventType.Information, ControlSlices.logSource, "Adding slice {0} to {1} PlanetLab node{2}.", new object[] { slice.Id, ids.Length, ids.Length.PluralSuffix() })); // Create the request state. SliceIdsRequestState requestState = new SliceIdsRequestState( this.OnAddSliceToNodesRequestStarted, this.OnAddSliceToNodesRequestResult, this.OnAddSliceToNodesRequestCanceled, this.OnAddSliceToNodesRequestException, this.OnAddSliceToNodesRequestFinished, slice, ids); // Begin an asynchronous PlanetLab request. this.BeginRequest( this.requestAddSliceToNodes, this.crawler.PlanetLab.Username, this.crawler.PlanetLab.Password, new object[] { slice.Id.Value, ids }, requestState); }
/// <summary> /// Creates a new request state instance. /// </summary> /// <param name="actionRequestStarted">The request started action.</param> /// <param name="actionRequestResult">The request result action.</param> /// <param name="actionRequestCanceled">The request canceled action.</param> /// <param name="actionRequestException">The request exception action.</param> /// <param name="actionRequestFinished">The request finished action.</param> /// <param name="slice">The slice.</param> public SliceRequestState( Action<RequestState> actionRequestStarted, Action<XmlRpcResponse, RequestState> actionRequestResult, Action<RequestState> actionRequestCanceled, Action<Exception, RequestState> actionRequestException, Action<RequestState> actionRequestFinished, PlSlice slice ) : base(actionRequestStarted, actionRequestResult, actionRequestCanceled, actionRequestException, actionRequestFinished) { this.Slice = slice; }
/// <summary> /// Creates a new request state instance. /// </summary> /// <param name="actionRequestStarted">The request started action.</param> /// <param name="actionRequestResult">The request result action.</param> /// <param name="actionRequestCanceled">The request canceled action.</param> /// <param name="actionRequestException">The request exception action.</param> /// <param name="actionRequestFinished">The request finished action.</param> /// <param name="slice">The slice.</param> /// <param name="ids">The IDs.</param> public SliceIdsRequestState( Action<RequestState> actionRequestStarted, Action<XmlRpcResponse, RequestState> actionRequestResult, Action<RequestState> actionRequestCanceled, Action<Exception, RequestState> actionRequestException, Action<RequestState> actionRequestFinished, PlSlice slice, int[] ids ) : base(actionRequestStarted, actionRequestResult, actionRequestCanceled, actionRequestException, actionRequestFinished, slice) { this.Ids = ids; }
/// <summary> /// Creates a new slice information variable. /// </summary> /// <param name="slice">The PlanetLab slice.</param> /// <param name="node">The tree node.</param> /// <param name="control">The control.</param> public SliceInfo(PlSlice slice, TreeNode node, ControlSlice control) : this() { this.Slice = slice; this.Node = node; this.Control = control; }
/// <summary> /// Opens the modal dialog to select a PlanetLab object. /// </summary> /// <param name="owner">The window owner.</param> /// <param name="slice">The PlanetLab slice.</param> /// <returns>The dialog result.</returns> public DialogResult ShowDialog(IWin32Window owner, PlSlice slice) { // Reset the result. this.Result = null; // Refresh the results list. this.control.Refresh(slice); // Show the dialog. return base.ShowDialog(owner); }
// Public methods. /// <summary> /// Opens the modal dialog to select a PlanetLab object. /// </summary> /// <param name="crawler">The crawler configuration.</param> /// <returns>The dialog result.</returns> public DialogResult ShowDialog(Crawler crawler) { // Reset the result. this.Result = null; // Refresh the results list. this.control.Refresh(crawler); // Show the dialog. return base.ShowDialog(); }
// Public methods. /// <summary> /// Refreshes the current slice information. /// </summary> /// <param name="crawler">The crawler configuration.</param> /// <param name="slice">The current slice.</param> public void Refresh(Crawler crawler, PlSlice slice) { // Set the slices database. this.slices = crawler.PlanetLab.DbSlices; // Set the slice. this.slice = slice; // Clear the buttons state. this.buttonRefresh.Enabled = true; this.buttonCancel.Enabled = false; this.buttonRenew.Enabled = false; this.buttonClose.Enabled = true; // Clear the status. this.labelStatus.Text = "Ready."; // Update the slice information. this.OnUpdateSlice(); }
// Public methods. /// <summary> /// Initializes the control with a crawler object. /// </summary> /// <param name="crawler">The crawler object.</param> /// <param name="slice">The slice.</param> /// <param name="config">The slice configuration.</param> /// <param name="treeNode">The tree node.</param> public void Initialize(Crawler crawler, PlSlice slice, PlConfigSlice config, TreeNode treeNode) { // Save the parameters. this.crawler = crawler; // Get the status handler. this.status = this.crawler.Status.GetHandler(this); // Set the slice. this.slice = slice; this.slice.Changed += this.OnSliceChanged; // Set the slice configuration. this.config = config; // Set the commands event handlers. this.config.Commands.CommandAdded += this.OnCommandAdded; this.config.Commands.CommandRemoved += this.OnCommandRemoved; // Create the manager. this.manager = new PlManager(this.crawler); // Add the PlanetLab manager event handlers. this.manager.Starting += this.OnRunStarting; this.manager.Started += this.OnRunStarted; this.manager.Pausing += this.OnRunPausing; this.manager.Paused += this.OnRunPaused; this.manager.Resuming += this.OnRunResuming; this.manager.Resumed += this.OnRunResumed; this.manager.Stopping += this.OnRunStopping; this.manager.Stopped += this.OnRunStopped; this.manager.NodesUpdateStarted += this.OnNodesUpdateStarted; this.manager.NodesUpdateCanceled += this.OnNodesUpdateCanceled; this.manager.NodesUpdateFinishedSuccess += this.OnNodesUpdateFinishedSuccess; this.manager.NodesUpdateFinishedFail += this.OnNodesUpdateFinishedFail; this.manager.NodeEnabled += this.OnNodeEnabled; this.manager.NodeDisabled += this.OnNodeDisabled; this.manager.NodeSkipped += this.OnNodeSkipped; this.manager.NodeStarted += this.OnNodeStarted; this.manager.NodeCanceled += this.OnNodeCanceled; this.manager.NodeFinishedSuccess += this.OnNodeFinishedSuccess; this.manager.NodeFinishedFail += this.OnNodeFinishedFail; this.manager.CommandStarted += this.OnCommandStarted; this.manager.CommandCanceled += this.OnCommandCanceled; this.manager.CommandFinishedSuccess += this.OnCommandFinishedSuccess; this.manager.CommandFinishedFail += this.OnCommandFinishedFail; this.manager.SubcommandSuccess += this.OnSubcommandSuccess; this.manager.SubcommandFail += this.OnSubcommandFail; // Create the manager history. this.managerHistory = new PlManagerHistory(slice); // Set the tree node. this.treeNode = treeNode; // Set the title. this.panelRun.Title = "Run on PlanetLab Slice ({0})".FormatWith(this.slice.Name); // Enable the control. this.Enabled = true; // Initialize the tools control. this.controlMethods.Initialize(this.crawler.Toolbox, this.config.ToolMethods, ControlSliceRun.toolTriggers); // Load the configuration. this.OnLoadConfiguration(this, EventArgs.Empty); // Update the information of the PlanetLab slice. this.OnUpdateSlice(); // Update the information of the PlanetLab commands. this.OnUpdateCommands(); // Update the information of the PlanetLab history. this.OnUpdateHistory(); }