/// <summary>
        /// Creates a new table relationship template.
        /// </summary>
        /// <param name="leftTable">The left table template.</param>
        /// <param name="rightTable">The right table template.</param>
        /// <param name="leftField">The left field name.</param>
        /// <param name="rightField">The right field name.</param>
        /// <param name="readOnly">Indicates if the relationship is read-only.</param>
        public DbRelationshipTemplate(DbTableTemplate leftTable, DbTableTemplate rightTable, string leftField, string rightField, bool readOnly)
        {
            // Validate the arguments.
            if (null == leftTable) throw new ArgumentNullException("leftTable");
            if (null == rightTable) throw new ArgumentNullException("rightTable");
            if (null == leftField) throw new ArgumentNullException("leftField");
            if (null == rightField) throw new ArgumentNullException("rightField");

            // Set the properties.
            this.LeftTable = leftTable;
            this.RightTable = rightTable;
            this.LeftField = leftField;
            this.RightField = rightField;
        }
        /// <summary>
        /// Creates a new tool instance.
        /// </summary>
        /// <param name="api">The tool API.</param>
        /// <param name="toolset">The toolset information.</param>
        public ToolAlexaTopSites(IToolApi api, ToolsetInfoAttribute toolset)
            : base(api, toolset)
        {
            // Create the control.
            this.control = new ControlAlexaTopSites(api);

            // Create the Alexa ranking database table.
            this.dbTableRanking = new DbTableTemplate<AlexaRankDbObject>(new Guid("7D65B301-C4C9-4823-9D64-0EB4E2CA43F4"), "Alexa ranking");
            this.dbTableHistory = new DbTableTemplate<AlexaHistoryDbObject>(new Guid("BD058EA2-0D75-4671-80A0-5A94A979B7E9"), "Alexa history");

            // Add the tables to the database.
            this.Api.DatabaseAddTable(this.dbTableRanking);
            this.Api.DatabaseAddTable(this.dbTableHistory);

            this.Api.DatabaseAddRelationship(this.dbTableHistory, this.dbTableRanking, "Timestamp", "Timestamp", true);
            this.Api.DatabaseAddRelationship(this.dbTableHistory, this.dbTableRanking, "Global", "Global", true);
            this.Api.DatabaseAddRelationship(this.dbTableHistory, this.dbTableRanking, "Country", "Country", true);
        }
 /// <summary>
 /// Removes the table template to the database.
 /// </summary>
 /// <param name="table">The database table template.</param>
 public void DatabaseRemoveTable(DbTableTemplate table)
 {
     this.application.Database.Sql.Tables.Remove(table);
 }
 // Database.
 /// <summary>
 /// Adds the table template to the database.
 /// </summary>
 /// <param name="table">The database table template.</param>
 public void DatabaseAddTable(DbTableTemplate table)
 {
     this.application.Database.Sql.Tables.Add(table);
 }
 /// <summary>
 /// Adds the table relationship to the database.
 /// </summary>
 /// <param name="leftTable">The left table template.</param>
 /// <param name="rightTable">The right table template.</param>
 /// <param name="leftField">The left field.</param>
 /// <param name="rightField">The right field.</param>
 /// <param name="readOnly">Indicates if the relationship is read-only.</param>
 public void DatabaseAddRelationship(DbTableTemplate leftTable, DbTableTemplate rightTable, string leftField, string rightField, bool readOnly)
 {
     this.application.Database.Sql.Relationships.Add(new DbRelationshipTemplate(leftTable, rightTable, leftField, rightField, readOnly));
 }
        /// <summary>
        /// Creates a new table instance for the specified table template.
        /// </summary>
        /// <param name="template">The table template.</param>
        /// <returns></returns>
        public static ITable Create(DbTableTemplate template)
        {
            // Check the arguments.
            if (null == template) throw new ArgumentNullException("template");

            // Check the type.
            if (!template.Type.IsSubclassOf(typeof(DbObject))) throw new DbException("Cannot create a database table because the table type if not a database object.");

            // Create the table type.
            Type tableType = typeof(DbTable<>).MakeGenericType(template.Type);

            // Create and return a table instance.
            return Activator.CreateInstance(tableType, template.Id, template.LocalName) as ITable;
        }
        /// <summary>
        /// Removes the specified table based on the table template.
        /// </summary>
        /// <param name="template">The table template.</param>
        public void RemoveTable(DbTableTemplate template)
        {
            // Validate the arguments.
            if (null == template) throw new ArgumentNullException("template");

            // Remove the table.
            this.tables.Remove(template.Id);

            // Remove any relationship with the specified table.
            this.relationships.Remove(template.Id);
        }
        /// <summary>
        /// Adds a table to the database server based on the specified table template.
        /// </summary>
        /// <param name="template">The table template.</param>
        public void AddTable(DbTableTemplate template)
        {
            // Validate the arguments.
            if (null == template) throw new ArgumentNullException("template");

            // Create the table and add it to the tables list.
            this.tables.Add(DbTable.Create(template));
        }
 /// <summary>
 /// Creates a new table template event arguments instance.
 /// </summary>
 /// <param name="template">The table template.</param>
 public DbTableTemplateEventArgs(DbTableTemplate template)
 {
     this.Template = template;
 }