Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
 // Public methods.
 /// <summary>
 /// Opens the modal dialog to select a PlanetLab object.
 /// </summary>
 /// <param name="owner">The window owner.</param>
 /// <param name="toolbox">The toolbox.</param>
 /// <returns>The dialog result.</returns>
 public DialogResult ShowDialog(IWin32Window owner, Toolset toolbox)
 {
     // Refresh the results list.
     if (this.control.Refresh(toolbox))
     {
         // Show the dialog.
         return base.ShowDialog(owner);
     }
     else
     {
         return DialogResult.Abort;
     }
 }
        // Public methods.
        /// <summary>
        /// Refreshes the control with the information from the specified toolset.
        /// </summary>
        /// <param name="toolset">The toolset.</param>
        public bool Refresh(Toolset toolset)
        {
            // Reset the buttons.
            this.buttonAdd.Enabled = false;
            this.buttonSelectAll.Enabled = toolset.Tools.Count > 0;
            this.buttonClearAll.Enabled = false;

            // Clear the list.
            this.listView.Items.Clear();

            // Clear the result.
            this.Result = null;

            // Set the toolset information.
            this.textBoxName.Text = toolset.Info.Name;
            this.textBoxVersion.Text = toolset.Info.Id.Version.ToString();
            this.textBoxProduct.Text = toolset.Info.Product;
            this.textBoxVendor.Text = toolset.Info.Author;

            // List all tools.
            foreach (Type type in toolset.Tools)
            {
                // Get the tool information.
                ToolInfoAttribute info = Tool.GetToolInfo(type);

                // If the info is not null.
                if (null != info)
                {
                    // Create a new item.
                    ListViewItem item = new ListViewItem(new string[] { info.Name, info.Id.Version.ToString(), info.Description });
                    // Set the item tag.
                    item.Tag = info;
                    // Set the item as not checked.
                    item.Checked = false;
                    // Add the item.
                    this.listView.Items.Add(item);
                }
            }

            // Return true.
            return true;
        }