TableCollection.cs :  » Installers-Generators » WiX » Microsoft » Deployment » WindowsInstaller » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Installers Generators » WiX 
WiX » Microsoft » Deployment » WindowsInstaller » TableCollection.cs
//---------------------------------------------------------------------
// <copyright file="TableCollection.cs" company="Microsoft">
//    Copyright (c) Microsoft Corporation.  All rights reserved.
//    
//    The use and distribution terms for this software are covered by the
//    Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
//    which can be found in the file CPL.TXT at the root of this distribution.
//    By using this software in any fashion, you are agreeing to be bound by
//    the terms of this license.
//    
//    You must not remove this notice, or any other, from this software.
// </copyright>
// <summary>
// Part of the Deployment Tools Foundation project.
// </summary>
//---------------------------------------------------------------------

namespace Microsoft.Deployment.WindowsInstaller{
    using System;
    using System.Collections.Generic;
    using System.Text;

    /// <summary>
    /// Contains information about all the tables in a Windows Installer database.
    /// </summary>
    public class TableCollection : ICollection<TableInfo>
    {
        private Database db;

        internal TableCollection(Database db)
        {
            this.db = db;
        }

        /// <summary>
        /// Gets the number of tables in the database.
        /// </summary>
        public int Count
        {
            get
            {
                return this.GetTables().Count;
            }
        }

        /// <summary>
        /// Gets a boolean value indicating whether the collection is read-only.
        /// A TableCollection is read-only when the database is read-only.
        /// </summary>
        /// <value>read-only status of the collection</value>
        public bool IsReadOnly
        {
            get
            {
                return this.db.IsReadOnly;
            }
        }

        /// <summary>
        /// Gets information about a given table.
        /// </summary>
        /// <param name="table">case-sensitive name of the table</param>
        /// <returns>information about the requested table, or null if the table does not exist in the database</returns>
        public TableInfo this[string table]
        {
            get
            {
                if (String.IsNullOrEmpty(table))
                {
                    throw new ArgumentNullException("table");
                }

                if (!this.Contains(table))
                {
                    return null;
                }

                return new TableInfo(this.db, table);
            }
        }

        /// <summary>
        /// Adds a new table to the database.
        /// </summary>
        /// <param name="item">information about the table to be added</param>
        /// <exception cref="InvalidOperationException">a table with the same name already exists in the database</exception>
        public void Add(TableInfo item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (this.Contains(item.Name))
            {
                throw new InvalidOperationException();
            }

            this.db.Execute(item.SqlCreateString);
        }

        /// <summary>
        /// Removes all tables (and all data) from the database.
        /// </summary>
        public void Clear()
        {
            foreach (string table in this.GetTables())
            {
                this.Remove(table);
            }
        }

        /// <summary>
        /// Checks if the database contains a table with the given name.
        /// </summary>
        /// <param name="item">case-sensitive name of the table to search for</param>
        /// <returns>True if the table exists, false otherwise.</returns>
        public bool Contains(string item)
        {
            if (String.IsNullOrEmpty(item))
            {
                throw new ArgumentNullException("item");
            }
            uint ret = RemotableNativeMethods.MsiDatabaseIsTablePersistent((int) this.db.Handle, item);
            if (ret == 3)  // MSICONDITION_ERROR
            {
                throw new InstallerException();
            }
            return ret != 2;  // MSICONDITION_NONE
        }

        bool ICollection<TableInfo>.Contains(TableInfo item)
        {
            return this.Contains(item.Name);
        }

        /// <summary>
        /// Copies the table information from this collection into an array.
        /// </summary>
        /// <param name="array">destination array to be filed</param>
        /// <param name="arrayIndex">offset into the destination array where copying begins</param>
        public void CopyTo(TableInfo[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            foreach (string table in this.GetTables())
            {
                array[arrayIndex++] = new TableInfo(this.db, table);
            }
        }

        /// <summary>
        /// Removes a table from the database.
        /// </summary>
        /// <param name="item">case-sensitive name of the table to be removed</param>
        /// <returns>true if the table was removed, false if the table did not exist</returns>
        public bool Remove(string item)
        {
            if (String.IsNullOrEmpty(item))
            {
                throw new ArgumentNullException("item");
            }

            if (!this.Contains(item))
            {
                return false;
            }
            this.db.Execute("DROP TABLE `{0}`", item);
            return true;
        }

        bool ICollection<TableInfo>.Remove(TableInfo item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return this.Remove(item.Name);
        }

        /// <summary>
        /// Enumerates the tables in the database.
        /// </summary>
        public IEnumerator<TableInfo> GetEnumerator()
        {
            foreach (string table in this.GetTables())
            {
                yield return new TableInfo(this.db, table);
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        private IList<string> GetTables()
        {
            return this.db.ExecuteStringQuery("SELECT `Name` FROM `_Tables`");
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.