HxCompTask.cs :  » Build-Systems » NAntContrib » NAnt » Contrib » Tasks » 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 » Build Systems » NAntContrib 
NAntContrib » NAnt » Contrib » Tasks » HxCompTask.cs
//
// NAntContrib
// Copyright (C) 2001-2003 Gerry Shaw
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
//
// Jayme C. Edwards (jedwards@wi.rr.com)

using System;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Xml;

using Microsoft.Win32;

using NAnt.Core;
using NAnt.Core.Attributes;
using NAnt.Core.Tasks;

namespace NAnt.Contrib.Tasks{
    /// <summary>
    /// Compiles a Microsoft HTML Help 2.0 Project.
    /// </summary>
    /// <example>
    ///   <para>Compile a help file.</para>
    ///   <code>
    ///     <![CDATA[
    /// <hxcomp contents="MyContents.HxC" output="MyHelpFile.HxS" projectroot="HelpSourceFolder" />
    ///     ]]>
    ///   </code>
    /// </example>
    [TaskName("hxcomp")]
    public class HxCompTask : ExternalProgramBase {
        #region Private Instance Fields

        private string _args;
        private string _contents;
        private string _logfile;
        private string _unicodelogfile;
        private string _projectroot;
        private string _outputFile;
        private bool _noinformation;
        private bool _noerrors;
        private bool _nowarnings;
        private string _uncompilefile;
        private string _uncompileoutputdir;

        #endregion Private Instance Fields

        #region Public Instance Properties

        /// <summary>
        /// The name of the contents (.HxC) file.
        /// </summary>
        [TaskAttribute("contents")]
        public string Contents {
            get { return _contents; }
            set { _contents = value; }
        }

        /// <summary>
        /// ANSI/DBCS log filename.
        /// </summary>
        [TaskAttribute("logfile")]
        public string LogFile {
            get { return _logfile; }
            set { _logfile = value; }
        }

        /// <summary>
        /// Unicode log filename.
        /// </summary>
        [TaskAttribute("unicodelogfile")]
        public string UnicodeLogFile {
            get { return _unicodelogfile; }
            set { _unicodelogfile = value; }
        }

        /// <summary>
        /// Root directory containing Help 2.0 project files.
        /// </summary>
        [TaskAttribute("projectroot")]
        public string ProjectRoot {
            get { return _projectroot; }
            set { _projectroot = value; }
        }

        /// <summary>
        /// Output (.HxS) filename.
        /// </summary>
        [TaskAttribute("output")] 
        public string OutputFile {
            get { return _outputFile; }
            set { _outputFile = value; }
        }

        /// <summary>
        /// Generate no informational messages.
        /// </summary>
        [TaskAttribute("noinformation")]
        [BooleanValidator()]
        public bool NoInformation {
            get { return _noinformation; }
            set { _noinformation = value; }
        }
        
        /// <summary>
        /// Generate no error messages.
        /// </summary>
        [TaskAttribute("noerrors")]
        [BooleanValidator()]
        public bool NoErrors {
            get { return _noerrors; }
            set { _noerrors = value; }
        }

        /// <summary>
        /// Generate no warning messages.
        /// </summary>
        [TaskAttribute("nowarnings")]
        [BooleanValidator()]
        public bool NoWarnings {
            get { return _nowarnings; }
            set { _nowarnings = value; }
        }
        
        /// <summary>
        /// File to be decompiled.
        /// </summary>
        [TaskAttribute("uncompilefile")] 
        public string UncompileFile {
            get { return _uncompilefile; }
            set { _uncompilefile = value; }
        }

        /// <summary>
        /// Directory to place decompiled files into.
        /// </summary>
        [TaskAttribute("uncompileoutputdir")] 
        public string UncompileOutputDir {
            get { return _uncompileoutputdir; }
            set { _uncompileoutputdir = value; }
        }

        #endregion Public Instance Properties

        #region Override implementation of ExternalProgramBase

        public override string ProgramFileName {
            get {
                RegistryKey helpPackageKey = Registry.LocalMachine.OpenSubKey(
                    @"Software\Microsoft\VisualStudio\7.0\" + 
                    @"Packages\{7D57F111-B9F3-11d2-8EE0-00C04F5E0C38}",
                    false);

                if (helpPackageKey != null) {
                    string helpPackageVal = (string)helpPackageKey.GetValue("InprocServer32", null);
                    if (helpPackageVal != null) {
                        string helpPackageDir = Path.GetDirectoryName(helpPackageVal);
                        if (helpPackageDir != null) {
                            if (Directory.Exists(helpPackageDir)) {
                                DirectoryInfo parentDir = Directory.GetParent(helpPackageDir);
                                if (parentDir != null) {
                                    helpPackageKey.Close();
                                    return Path.Combine(parentDir.FullName, "hxcomp.exe");
                                }
                            }
                        }
                    }
                    helpPackageKey.Close();
                }

                throw new BuildException(
                    "Unable to locate installation directory of " + 
                    "Microsoft Help 2.0 SDK in the registry.", Location);
            }
        }

        /// <summary>
        /// Arguments of program to execute
        /// </summary>
        public override string ProgramArguments {
            get {
                return _args;
            }
        }

        protected override void InitializeTask(XmlNode taskNode) {
            base.InitializeTask (taskNode);

            if (OutputFile == null && UncompileFile == null) {
                throw new BuildException(
                    "Either the \"uncompilefile\" or \"output\" attribute"
                    + " should be specified.", Location);
            }
        }

        protected override void ExecuteTask() {
            // If the user wants to see the actual command the -verbose flag
            // will cause ExternalProgramBase to display the actual call.
            if (OutputFile != null ) {
                Log(Level.Info, "Compiling HTML Help 2.0 File '{0}'.", OutputFile);
            } else if (UncompileFile != null) {
                Log(Level.Info, "Decompiling HTML Help 2.0 File '{0}'.", UncompileFile);
            }

            try {
                StringBuilder arguments = new StringBuilder();
                   
                if (NoInformation) {
                    arguments.Append("-i ");
                }
                if (NoErrors) {
                    arguments.Append("-e ");
                }
                if (NoWarnings) {
                    arguments.Append("-w ");
                }
                if (!Verbose) {
                    arguments.Append("-q ");
                }
                if (Contents != null) {
                    arguments.Append("-p ");
                    arguments.Append('\"' + Contents + '\"');
                    arguments.Append(" ");
                }
                if (LogFile != null) {
                    arguments.Append("-l ");
                    arguments.Append('\"' + LogFile + '\"');
                    arguments.Append(" ");
                }
                if (UnicodeLogFile != null) {
                    arguments.Append("-n ");
                    arguments.Append('\"' + UnicodeLogFile + '\"');
                    arguments.Append(" ");
                }
                if (Output != null) {
                    arguments.Append("-o ");
                    arguments.Append('\"' + OutputFile + '\"');
                    arguments.Append(" ");
                }
                if (ProjectRoot != null) {
                    arguments.Append("-r ");
                    arguments.Append('\"' + ProjectRoot + '\"');
                    arguments.Append(" ");
                }
                if (UncompileFile != null) {
                    arguments.Append("-u ");
                    arguments.Append('\"' + UncompileFile + '\"');
                    arguments.Append(" ");
                }
                if (UncompileOutputDir != null) {
                    arguments.Append("-d ");
                    arguments.Append('\"' + UncompileOutputDir + '\"');
                    arguments.Append(" ");
                }

                _args = arguments.ToString();

                base.ExecuteTask();
            } catch (Exception ex) {
                throw new BuildException(
                    "Microsoft HTML Help 2.0 Project could not be compiled.", 
                    Location, ex);
            }
        }

        #endregion Override implementation of ExternalProgramBase
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.