FirewallDecompiler.cs :  » Installers-Generators » WiX » Microsoft » Tools » WindowsInstallerXml » Extensions » 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 » Extensions » FirewallDecompiler.cs
//-------------------------------------------------------------------------------------------------
// <copyright file="FirewallDecompiler.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>
// The decompiler for the Windows Installer XML Toolset Firewall Extension.
// </summary>
//-------------------------------------------------------------------------------------------------

namespace Microsoft.Tools.WindowsInstallerXml.Extensions{
    using System;
    using System.Collections;
    using System.Diagnostics;
    using System.Globalization;

    using Firewall = Microsoft.Tools.WindowsInstallerXml.Extensions.Serialize.Firewall;
    using Wix = Microsoft.Tools.WindowsInstallerXml.Serialize;

    /// <summary>
    /// The decompiler for the Windows Installer XML Toolset Firewall Extension.
    /// </summary>
    public sealed class FirewallDecompiler : DecompilerExtension
    {
        /// <summary>
        /// Decompiles an extension table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        public override void DecompileTable(Table table)
        {
            switch (table.Name)
            {
                case "WixFirewallException":
                    this.DecompileWixFirewallExceptionTable(table);
                    break;
                default:
                    base.DecompileTable(table);
                    break;
            }
        }

        /// <summary>
        /// Decompile the WixFirewallException table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileWixFirewallExceptionTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                Firewall.FirewallException fire = new Firewall.FirewallException();
                fire.Id = (string)row[0];
                fire.Name = (string)row[1];

                string[] addresses = ((string)row[2]).Split(',');
                if (1 == addresses.Length)
                {
                    // special-case the Scope attribute values
                    if ("*" == addresses[0])
                    {
                        fire.Scope = Firewall.FirewallException.ScopeType.any;
                    }
                    else if ("LocalSubnet" == addresses[0])
                    {
                        fire.Scope = Firewall.FirewallException.ScopeType.localSubnet;
                    }
                    else
                    {
                        FirewallDecompiler.AddRemoteAddress(fire, addresses[0]);
                    }
                }
                else
                {
                    foreach (string address in addresses)
                    {
                        FirewallDecompiler.AddRemoteAddress(fire, address);
                    }
                }

                if (!row.IsColumnEmpty(3))
                {
                    fire.Port = (string)row[3];
                }

                // from icftypes.h
                const int NET_FW_IP_PROTOCOL_TCP = 6;
                const int NET_FW_IP_PROTOCOL_UDP  = 17;

                if (!row.IsColumnEmpty(4))
                {
                    switch (Convert.ToInt32(row[4]))
                    {
                        case NET_FW_IP_PROTOCOL_TCP:
                            fire.Protocol = Firewall.FirewallException.ProtocolType.tcp;
                            break;
                        case NET_FW_IP_PROTOCOL_UDP:
                            fire.Protocol = Firewall.FirewallException.ProtocolType.udp;
                            break;
                    }
                }

                if (!row.IsColumnEmpty(5))
                {
                    fire.Program = (string)row[5];
                }

                if (!row.IsColumnEmpty(6))
                {
                    int attr = Convert.ToInt32(row[6]);
                    if (0x1 == (attr & 0x1)) // feaIgnoreFailures
                    {
                        fire.IgnoreFailure = Firewall.YesNoType.yes;
                    }
                }

                Wix.Component component = (Wix.Component)this.Core.GetIndexedElement("Component", (string)row[7]);
                if (null != component)
                {
                    component.AddChild(fire);
                }
                else
                {
                    this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerCore.PrimaryKeyDelimiter), "Component_", (string)row[6], "Component"));
                }
            }
        }

        private static void AddRemoteAddress(Firewall.FirewallException fire, string address)
        {
            Firewall.RemoteAddress remote = new Firewall.RemoteAddress();
            remote.Content = address;
            fire.AddChild(remote);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.