Example #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);
            }
        }
Example #2
0
        /// <summary>
        /// Try and parse the specified string into a tool identifier.
        /// </summary>
        /// <param name="value">The string value.</param>
        /// <param name="id">The tool identifier.</param>
        /// <returns><b>True</b> if the parsing was successful, <b>false</b> otherwise.</returns>
        public static bool TryParse(string value, out ToolId id)
        {
            // Split the tool information between identifier and version.
            string[] str = value.Split(',');

            id = default(ToolId);

            // If the information does not have exactly two parameters, throw an exception.
            if (2 != str.Length) return false;

            Guid guid;
            Version version;

            // Try parse the GUID.
            if (!Guid.TryParse(str[0], out guid)) return false;
            // Try parse the version.
            if (!Version.TryParse(str[1], out version)) return false;

            // Create the new tool identifier.
            id = new ToolId(guid, version);

            return true;
        }
Example #3
0
 // Public properties.
 /// <summary>
 /// Returns the tool type for the specified identifier and version.
 /// </summary>
 /// <param name="id">The tool identifier.</param>
 /// <returns>The tool type or null, if the tool does not exist.</returns>
 public Type this[ToolId id]
 {
     get { return this.GetTool(id); }
 }
Example #4
0
 // Public methods.
 /// <summary>
 /// Returns the tool type for the specified identifier and version. The method does not throw an exception.
 /// </summary>
 /// <param name="strId">The tool identifier.</param>
 /// <returns>The type or <b>null</b>, if the tool does not exist.</returns>
 public Type GetTool(ToolId id)
 {
     Type type;
     if (this.tools.TryGetValue(id, out type)) return type;
     else return null;
 }