/// <summary>
 /// Shows the form as a dialog and the specified tool.
 /// </summary>
 /// <param name="owner">The owner window.</param>
 /// <param name="tool">The tool.</param>
 /// <returns>The dialog result.</returns>
 public DialogResult ShowDialog(IWin32Window owner, Tool tool)
 {
     // Set the tool.
     this.tool.Tool = tool;
     // Set the title.
     this.Text = "{0} Properties".FormatWith(this.tool.Title);
     // Open the dialog.
     return base.ShowDialog(owner);
 }
        /// <summary>
        /// Creates a new tool instance.
        /// </summary>
        /// <param name="tool">The tool for this tool item.</param>
        /// <param name="api">The tool API.</param>
        public ToolMercuryAnalytics(Tool tool, IToolApi api)
            : base(tool, api)
        {
            // Create the configuration.
            this.config = new MercuryConfig(api);

            // Create the control.
            this.control = new ControlMercuryAnalytics(this.config);
        }
        /// <summary>
        /// Createa a new tool method instance.
        /// </summary>
        /// <param name="tool">The tool.</param>
        /// <param name="id">The tool method identifier.</param>
        /// <param name="name">The method name.</param>
        /// <param name="description">The method description.</param>
        /// <param name="action">The action.</param>
        public ToolMethod(Tool tool, Guid id, string name, string description, ToolMethodAction action)
        {
            // Validate the arguments.
            if (null == tool) throw new ArgumentNullException("tool");
            if (null == action) throw new ArgumentNullException("action");

            this.tool = tool;
            this.id = new ToolMethodId(tool.Info.Id.Guid, tool.Info.Id.Version, id);
            this.name = name;
            this.description = description;
            this.action = action;
        }
        /// <summary>
        /// Creates a new tool instance.
        /// </summary>
        /// <param name="tool">The tool for this tool item.</param>
        /// <param name="api">The tool API.</param>
        public ToolMercuryClient(Tool tool, IToolApi api)
            : base(tool, api)
        {
            // Create the configuration.
            this.config = new MercuryConfig(api);

            // Create the control.
            this.control = new ControlMercuryClient(this.config);

            // Create the tool methods.
            this.Tool.AddMethod(
                new Guid("24FDC1EC-FA12-4A42-B410-3A868B9576D9"),
                Resources.ToolMercuryClientMethodUploadSessionFromPlanetLabName,
                Resources.ToolMercuryClientMethodUploadSessionFromPlanetLabDescription,
                this.UploadSessionFromPlanetLab);
            this.Tool.AddMethod(
                new Guid("5AD386C4-EA86-4C31-A0A1-DCD6CF1107B2"),
                Resources.ToolMercuryClientMethodUploadTracerouteFromPlanetLabName,
                Resources.ToolMercuryClientMethodUploadTracerouteFromPlanetLabDescription,
                this.UploadTracerouteFromPlanetLab);
        }
 /// <summary>
 /// Creates a new toolbox information instance.
 /// </summary>
 /// <param name="tool">The tool.</param>
 /// <param name="node">The tree node.</param>
 public ToolboxInfo(Tool tool, TreeNode node)
     : this()
 {
     this.Tool = tool;
     this.Node = node;
     this.Control = tool.Control;
 }
        /// <summary>
        /// Removes a new tool to the toolbox.
        /// </summary>
        /// <param name="tool">The tool.</param>
        private void OnRemoveTool(Tool tool)
        {
            // Find the list view item corresponding to the tool.
            ListViewItem item = this.listView.Items.FirstOrDefault((ListViewItem it) =>
                {
                    // Return true if the tool matches.
                    return object.ReferenceEquals(tool, ((ToolboxInfo)it.Tag).Tool);
                });

            // Get the toolbox information.
            ToolboxInfo info = (ToolboxInfo)item.Tag;

            // Remove the tree node.
            this.treeNode.Nodes.Remove(info.Node);

            // Remove the control.
            this.controls.Remove(info.Control);

            // Remove the list view item.
            this.listView.Items.Remove(item);

            // Call the selection changed event handler.
            this.OnSelectedChanged(this, EventArgs.Empty);
        }
        /// <summary>
        /// Adds a new tool to the toolbox.
        /// </summary>
        /// <param name="tool">The tool.</param>
        private void OnAddTool(Tool tool)
        {
            // If the tool has a custom icon.
            if (tool.Icon != null)
            {
                // Add the custom icon to the image list.
                this.imageList.Images.Add(tool.Info.Id.ToString(), tool.Icon);
            }

            // Create a new tree node.
            TreeNode node = new TreeNode(tool.Info.Name);
            node.ImageKey = tool.Icon != null ? tool.Info.Id.ToString() : "ToolboxPickAxe";
            node.SelectedImageKey = tool.Icon != null ? tool.Info.Id.ToString() : "ToolboxPickAxe";
            // Add the node to the nodes list.
            this.treeNode.Nodes.Add(node);
            // Expand the tree nodes.
            this.treeNode.ExpandAll();

            // Create the toolbox information.
            ToolboxInfo info = new ToolboxInfo(tool, node);

            // Add the tool to the toolbox list.
            ListViewItem item = new ListViewItem(new string[] {
                tool.Info.Name,
                tool.Toolset.Name,
                tool.Toolset.Author,
                tool.Toolset.Product,
                tool.Toolset.Id.Version.ToString(),
                tool.Info.Id.Version.ToString()
            });
            item.ImageKey = tool.Icon != null ? tool.Info.Id.ToString() : "ToolboxPickAxe";
            item.Tag = info;
            // Add the item to the list.
            this.listView.Items.Add(item);

            // If the tool control is not null.
            if (null != info.Control)
            {
                // Set the control properties.
                info.Control.Dock = DockStyle.Fill;
                info.Control.Visible = false;

                // Add the control.
                this.controls.Add(info.Control);
                node.Tag = info.Control;
            }
        }
        /// <summary>
        /// Creates a new tool configuration instance.
        /// </summary>
        /// <param name="config">The application configuration.</param>
        /// <param name="toolset">The toolset.</param>
        /// <param name="rootKey">The root registry key.</param>
        /// <param name="id">The tool identifier.</param>
        public ToolConfig(IDbApplication config, Toolset toolset, RegistryKey rootKey, ToolId id)
        {
            // Validate the arguments.
            if (null == config) throw new ArgumentNullException("config");
            if (null == toolset) throw new ArgumentNullException("toolset");
            if (null == rootKey) throw new ArgumentNullException("rootKey");

            // Set the parameters.
            this.config = config;
            this.toolset = toolset;

            // Get the tool type.
            Type type = this.toolset[id];

            // Check the type is not null.
            if (null == type) throw new ToolException("Cannot create a tool because the tool identifier {0} was not found in the toolset {1}.".FormatWith(id, this.toolset.Info.Id), this.toolset.Info);

            // Open or create the registry key for this tool.
            if (null == (this.key = rootKey.OpenSubKey(id.ToString(), RegistryKeyPermissionCheck.ReadWriteSubTree)))
            {
                this.key = rootKey.CreateSubKey(id.ToString(), RegistryKeyPermissionCheck.ReadWriteSubTree);
            }

            // Get the tool info.
            ToolInfoAttribute info = Tool.GetToolInfo(type);

            // Create the tool API.
            ToolApi toolApi = new ToolApi(this.config, this.toolset.Info, info, this.key);

            try
            {
                // Create the tool instance.
                this.tool = Activator.CreateInstance(type, new object[] { toolApi, this.toolset.Info }) as Tool;
            }
            catch (Exception exception)
            {
                // Log the exception.
                this.config.Log.Add(
                    LogEventLevel.Important,
                    LogEventType.Error,
                    ToolConfig.logSourceTool.FormatWith(toolset.Info.Id, id),
                    "Loading the tool of type {0} from the toolset {1} failed.",
                    new object[] { type.FullName, this.toolset.Info.Id },
                    exception);

                // Close the registry key.
                this.key.Close();

                // Throw an exception.
                throw new ToolException("Cannot create an instance of the tool {0} from the toolset {1}.".FormatWith(id, this.toolset.Info.Id), exception, this.toolset.Info, info);
            }
        }
 /// <summary>
 /// Creates a new event arguments instance.
 /// </summary>
 /// <param name="tool">The tool.</param>
 public ToolEventArgs(Tool tool)
 {
     this.Tool = tool;
 }
        // Protected methods.
        /// <summary>
        /// An event handler called when a new tool has been set.
        /// </summary>
        /// <param name="oldTool">The old tool.</param>
        /// <param name="newTool">The new tool.</param>
        protected virtual void OnToolSet(Tool oldTool, Tool newTool)
        {
            // Set the title to empty.
            this.Title = string.Empty;

            // If the tool has not changed, do nothing.
            if (oldTool == newTool) return;

            if (null == newTool)
            {
                this.labelTitle.Text = "No tool selected";
                this.tabControl.Visible = false;
            }
            else
            {
                this.labelTitle.Text = newTool.Info.Name;
                this.textBoxName.Text = newTool.Info.Name;
                this.textBoxId.Text = newTool.Info.Id.Guid.ToString();
                this.textBoxVersion.Text = newTool.Info.Id.Version.ToString();
                this.textBoxDescription.Text = newTool.Info.Description;

                this.textBoxToolsetName.Text = newTool.Toolset.Name;
                this.textBoxToolsetId.Text = newTool.Toolset.Id.Guid.ToString();
                this.textBoxToolsetVersion.Text = newTool.Toolset.Id.Version.ToString();
                this.textBoxToolsetProduct.Text = newTool.Toolset.Product;
                this.textBoxToolsetAuthor.Text = newTool.Toolset.Author;
                this.textBoxToolsetDescription.Text = newTool.Toolset.Description;

                this.Title = newTool.Info.Name;

                this.tabControl.Visible = true;
            }

            this.tabControl.SelectedTab = this.tabPageGeneral;
            if (this.Focused)
            {
                this.textBoxName.Select();
                this.textBoxName.SelectionStart = 0;
                this.textBoxName.SelectionLength = 0;
            }
        }
 /// <summary>
 /// Creates a new tool item instance.
 /// </summary>
 /// <param name="tool">The tool.</param>
 /// <param name="api">The tool API.</param>
 public ToolItem(Tool tool, IToolApi api)
 {
     this.tool = tool;
     this.api = api;
 }