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
        /// <summary>
        /// Creates a new tool API instance.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="toolset">The toolset information.</param>
        /// <param name="tool">The tool information.</param>
        /// <param name="key">The registry key for this tool.</param>
        public ToolApi(IDbApplication application, ToolsetInfoAttribute toolset, ToolInfoAttribute tool, RegistryKey key)
        {
            // Check the arguments.
            if (null == application) throw new ArgumentNullException("application");
            if (null == toolset) throw new ArgumentNullException("toolset");
            if (null == tool) throw new ArgumentNullException("tool");
            if (null == key) throw new ArgumentNullException("key");

            // Set the parameters.
            this.application = application;
            this.toolset = toolset;
            this.tool = tool;
            this.key = key;
        }
Esempio n. 3
0
 public MiniRedisController(IDbApplication application)
 {
     //dependency injection
     _application = application;
 }
Esempio n. 4
0
 /// <summary>
 /// Creates a new configuration instance.
 /// </summary>
 /// <param name="config">The configuration.</param>
 /// <param name="rootKey">The root registry key.</param>
 /// <param name="rootPath">The registry path.</param>
 public DbConfig(IDbApplication config, RegistryKey rootKey, string rootPath)
 {
     // Create the SQL database configuration.
     this.dbSql = new DbConfigSql(config, rootKey, rootPath + @"\Sql");
 }