Record.cs :  » Installers-Generators » WiX » Microsoft » Tools » WindowsInstallerXml » Msi » 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 » Tools » WindowsInstallerXml » Msi » Record.cs
//-------------------------------------------------------------------------------------------------
// <copyright file="Record.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>
// Wrapper class around msi.dll interop for a record.
// </summary>
//-------------------------------------------------------------------------------------------------

namespace Microsoft.Tools.WindowsInstallerXml.Msi{
    using System;
    using System.ComponentModel;
    using System.Text;
    using Microsoft.Tools.WindowsInstallerXml.Msi.Interop;

    /// <summary>
    /// Wrapper class around msi.dll interop for a record.
    /// </summary>
    public sealed class Record : MsiHandle
    {
        /// <summary>
        /// Creates a record with the specified number of fields.
        /// </summary>
        /// <param name="fieldCount">Number of fields in record.</param>
        public Record(int fieldCount)
        {
            this.Handle = MsiInterop.MsiCreateRecord(fieldCount);
            if (0 == this.Handle)
            {
                throw new OutOfMemoryException();
            }
        }

        /// <summary>
        /// Creates a record from a handle.
        /// </summary>
        /// <param name="handle">Handle to create record from.</param>
        internal Record(uint handle)
        {
            this.Handle = handle;
        }

        /// <summary>
        /// Gets a string value at specified location.
        /// </summary>
        /// <param name="field">Index into record to get string.</param>
        public string this[int field]
        {
            get { return this.GetString(field); }
            set { this.SetString(field, (string)value); }
        }

        /// <summary>
        /// Determines if the value is null at the specified location.
        /// </summary>
        /// <param name="field">Index into record of the field to query.</param>
        /// <returns>true if the value is null, false otherwise.</returns>
        public bool IsNull(int field)
        {
            int error = MsiInterop.MsiRecordIsNull(this.Handle, field);

            switch (error)
            {
                case 0:
                    return false;
                case 1:
                    return true;
                default:
                    throw new Win32Exception(error);
            }
        }

        /// <summary>
        /// Gets integer value at specified location.
        /// </summary>
        /// <param name="field">Index into record to get integer</param>
        /// <returns>Integer value</returns>
        public int GetInteger(int field)
        {
            return MsiInterop.MsiRecordGetInteger(this.Handle, field);
        }

        /// <summary>
        /// Sets integer value at specified location.
        /// </summary>
        /// <param name="field">Index into record to set integer.</param>
        /// <param name="value">Value to set into record.</param>
        public void SetInteger(int field, int value)
        {
            int error = MsiInterop.MsiRecordSetInteger(this.Handle, field, value);
            if (0 != error)
            {
                throw new Win32Exception(error);
            }
        }

        /// <summary>
        /// Gets string value at specified location.
        /// </summary>
        /// <param name="field">Index into record to get string.</param>
        /// <returns>String value</returns>
        public string GetString(int field)
        {
            int bufferSize = 255;
            StringBuilder buffer = new StringBuilder(bufferSize);
            int error = MsiInterop.MsiRecordGetString(this.Handle, field, buffer, ref bufferSize);
            if (234 == error)
            {
                buffer.EnsureCapacity(++bufferSize);
                error = MsiInterop.MsiRecordGetString(this.Handle, field, buffer, ref bufferSize);
            }

            if (0 != error)
            {
                throw new Win32Exception(error);
            }

            return (0 < buffer.Length ? buffer.ToString() : null);
        }

        /// <summary>
        /// Set string value at specified location
        /// </summary>
        /// <param name="field">Index into record to set string.</param>
        /// <param name="value">Value to set into record</param>
        public void SetString(int field, string value)
        {
            int error = MsiInterop.MsiRecordSetString(this.Handle, field, value);
            if (0 != error)
            {
                throw new Win32Exception(error);
            }
        }

        /// <summary>
        /// Get stream at specified location.
        /// </summary>
        /// <param name="field">Index into record to get stream.</param>
        /// <param name="buffer">buffer to receive bytes from stream.</param>
        /// <param name="requestedBufferSize">Buffer size to read.</param>
        /// <returns>Stream read into string.</returns>
        public int GetStream(int field, byte[] buffer, int requestedBufferSize)
        {
            int bufferSize = 255;
            if (requestedBufferSize > 0)
            {
                bufferSize = requestedBufferSize;
            }

            int error = MsiInterop.MsiRecordReadStream(this.Handle, field, buffer, ref bufferSize);
            if (0 != error)
            {
                throw new Win32Exception(error);
            }

            return bufferSize;
        }

        /// <summary>
        /// Sets a stream at a specified location.
        /// </summary>
        /// <param name="field">Index into record to set stream.</param>
        /// <param name="path">Path to file to read into stream.</param>
        public void SetStream(int field, string path)
        {
            int error = MsiInterop.MsiRecordSetStream(this.Handle, field, path);
            if (0 != error)
            {
                throw new Win32Exception(error);
            }
        }

        /// <summary>
        /// Gets the number of fields in record.
        /// </summary>
        /// <returns>Count of fields in record.</returns>
        public int GetFieldCount()
        {
            int size = MsiInterop.MsiRecordGetFieldCount(this.Handle);
            if (0 > size)
            {
                throw new Win32Exception();
            }

            return size;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.