VersionStringTable.cs :  » Installers-Generators » WiX » Microsoft » Deployment » Resources » 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 » Resources » VersionStringTable.cs
//---------------------------------------------------------------------
// <copyright file="VersionStringTable.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.Resources{
    using System;
    using System.IO;
    using System.Text;
    using System.Reflection;
    using System.Collections;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Diagnostics.CodeAnalysis;

    /// <summary>
    /// Represents a string table of a file version resource.
    /// </summary>
    [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
    public sealed class VersionStringTable : IDictionary<string, string>
    {
        private VersionResource parent;
        private VersionInfo rawStringVersionInfo;

        internal VersionStringTable(VersionResource parent, VersionInfo rawStringVersionInfo)
        {
            this.parent = parent;
            this.rawStringVersionInfo = rawStringVersionInfo;
        }

        /// <summary>
        /// Gets the locale (LCID) of the string table.
        /// </summary>
        public int Locale
        {
            get
            {
                return UInt16.Parse(rawStringVersionInfo.Key.Substring(0, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
            }
            set
            {
                rawStringVersionInfo.Key = ((ushort) value).ToString("x4", CultureInfo.InvariantCulture) + rawStringVersionInfo.Key.Substring(4, 4);
                this.parent.dirty = true;
            }
        }

        /// <summary>
        /// Gets or sets a string value.
        /// </summary>
        /// <param name="key">Name of the string.</param>
        public string this[string key]
        {
            get
            {
                VersionInfo verValue = this.rawStringVersionInfo[key];
                if (verValue == null)
                {
                    return null;
                }
                else
                {
                    return Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2);
                }
            }
            set
            {
                if (value == null)
                {
                    rawStringVersionInfo.Remove(key);
                }
                else
                {
                    VersionInfo verValue = rawStringVersionInfo[key];
                    if (verValue == null)
                    {
                        verValue = new VersionInfo(key);
                        verValue.IsString = true;
                        rawStringVersionInfo.Add(verValue);
                    }
                    verValue.Data = new byte[Encoding.Unicode.GetByteCount(value) + 2];
                    Encoding.Unicode.GetBytes(value, 0, value.Length, verValue.Data, 0);
                }
                this.parent.dirty = true;
            }
        }

        bool ICollection<KeyValuePair<string, string>>.IsReadOnly
        {
            get
            {
                return false;
            }
        }

        bool IDictionary<string, string>.TryGetValue(string key, out string value)
        {
            value = this[key];
            return value != null;
        }


        void ICollection<KeyValuePair<string, string>>.Add(KeyValuePair<string, string> item)
        {
            this[item.Key] = item.Value;
        }

        bool ICollection<KeyValuePair<string, string>>.Remove(KeyValuePair<string, string> item)
        {
            string value = this[item.Key];
            if (value == item.Value)
            {
                this[item.Key] = null;
                return true;
            }
            else
            {
                return false;
            }
        }

        bool ICollection<KeyValuePair<string, string>>.Contains(KeyValuePair<string, string> item)
        {
            string value = this[item.Key];
            if (value == item.Value)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        bool IDictionary<string, string>.ContainsKey(string key)
        {
            return this[key] != null;
        }

        void IDictionary<string, string>.Add(string key, string value)
        {
            this[key] = value;
        }

        bool IDictionary<string, string>.Remove(string key)
        {
            if (this[key] != null)
            {
                this[key] = null;
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Removes all strings from the string table.
        /// </summary>
        public void Clear()
        {
            this.rawStringVersionInfo.Clear();
        }

        /// <summary>
        /// Gets a collection of all the names of the strings in the table.
        /// </summary>
        public ICollection<string> Keys
        {
            get
            {
                List<string> keys = new List<string>(this.rawStringVersionInfo.Count);
                foreach (VersionInfo verValue in this.rawStringVersionInfo)
                {
                    keys.Add(verValue.Key);
                }
                return keys;
            }
        }

        /// <summary>
        /// Gets a collection of all the values in the table.
        /// </summary>
        public ICollection<string> Values
        {
            get
            {
                List<string> values = new List<string>(this.rawStringVersionInfo.Count);
                foreach (VersionInfo verValue in this.rawStringVersionInfo)
                {
                    values.Add(Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2));
                }
                return values;
            }
        }

        /// <summary>
        /// Gets the number of strings in the table.
        /// </summary>
        public int Count
        {
            get
            {
                return this.rawStringVersionInfo.Count;
            }
        }

        void ICollection<KeyValuePair<string, string>>.CopyTo(KeyValuePair<string, string>[] array, int index)
        {
            foreach (VersionInfo verValue in this.rawStringVersionInfo)
            {
                array[index++] = new KeyValuePair<string, string>(verValue.Key, Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2));
            }
        }

        /// <summary>
        /// Gets an enumeration over all strings in the table.
        /// </summary>
        /// <returns>Enumeration of string name and value pairs</returns>
        public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
        {
            foreach (VersionInfo verValue in this.rawStringVersionInfo)
            {
                yield return new KeyValuePair<string, string>(verValue.Key, Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2));
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.