BaseTask.cs :  » Build-Systems » NAntContrib » NAnt » Contrib » Tasks » SourceSafe » 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 » SourceSafe » BaseTask.cs
#region GNU General Public License
//
// 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
//

// Jason Reimer, Diversant Inc. (jason.reimer@diversant.net)
#endregion

using System;
using System.ComponentModel;
using System.Globalization;
using System.IO;

using SourceSafeTypeLib;

using NAnt.Core;
using NAnt.Core.Attributes;
using NAnt.Core.Util;

namespace NAnt.Contrib.Tasks.SourceSafe{
    /// <summary>
    /// The base abstract class for all Visual Source Safe Tasks.  
    /// Provides the core attributes, and functionality for opening an item 
    /// in a Visual Source Safe database.
    /// </summary>
    public abstract class BaseTask : Task {
        #region Protected Static Fields

        // Flag required for performing a recursive action
        protected const VSSFlags RecursiveFlag = VSSFlags.VSSFLAG_RECURSYES | 
            VSSFlags.VSSFLAG_FORCEDIRNO;

        #endregion Protected Static Fields

        #region Private Instance Fields

        private VSSDatabase _database;
        private IVSSItem _item;
        private FileInfo _dbPath;
        private string _path;
        private string _password = string.Empty;
        private string _userName = string.Empty;
        private string _version;

        #endregion Private Instance Fields

        #region Public Instance Properties

        /// <summary>
        /// The path to the folder that contains "srcsafe.ini".
        /// </summary>
        [TaskAttribute("dbpath", Required=true)]
        public FileInfo DBPath { 
            get { return _dbPath; }
            set { _dbPath = value; }
        }
        
        /// <summary>
        /// The Visual SourceSafe project or file path you wish the perform the
        /// action on (starting with "$/").
        /// </summary>
        [TaskAttribute("path", Required=true)]
        [StringValidator(AllowEmpty=false)]
        public string Path { 
            get { return _path; }
            set { _path = value; }
        }

        /// <summary>
        /// The password to use to login to the SourceSafe database.
        /// </summary>
        [TaskAttribute("password")]
        public string Password {
            get { return _password; }
            set { _password = value; }
        }

        /// <summary>
        /// The name of the user needed to access the Visual SourceSafe database.
        /// When no <see cref="UserName" /> is specified and &quot;Use network
        /// name for automatic user log in&quot; is enabled for the Visual SourceSafe
        /// database, then the current Windows username will be used to log in.
        /// </summary>
        [TaskAttribute("username", Required=false)]
        public string UserName { 
            get { return _userName; } 
            set { _userName = value; }
        }

        /// <summary>
        /// The name of the user needed to access the Visual SourceSafe database.
        /// When no <see cref="UserName" /> is specified and &quot;Use network
        /// name for automatic user log in&quot; is enabled, then the current
        /// Windows username will be used to log in.
        /// </summary>
        [TaskAttribute("user", Required=false)]
        [Obsolete("Use \"username\" attribute instead.", false)]
        public virtual string Login { 
            get { return UserName; } 
            set { UserName = value; }
        }

        /// <summary>
        /// A version of the path to reference. Accepts multiple forms, 
        /// including the label, version number, or date of the version. 
        /// If omitted, the latest version is used.
        /// </summary>
        [TaskAttribute("version")]
        public virtual string Version {
            get { return _version; } 
            set { _version = StringUtils.ConvertEmptyToNull(value); }
        }

        public VSSDatabase Database {
            get { return _database; }
            set { _database = value; }
        }

        public IVSSItem Item {
            get { return _item; }
            set { _item = value; }
        }

        #endregion Public Instance Properties

        #region Protected Instance Methods

        /// <summary>
        /// Opens the Source Safe database and sets the reference to the specified
        /// item and version.
        /// </summary>
        protected void Open() {
            try {
                _database = new VSSDatabase();
                _database.Open(DBPath.FullName, UserName, Password);
            } catch (Exception ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    "Failed to open database \"{0}\".", DBPath.FullName),
                    Location, ex);
            }

            try {
                // get the reference to the specified project item 
                // and version
                _item = _database.get_VSSItem(Path, false);
                if (Version != null) {
                    _item = _item.get_Version(Version);
                }
            } catch (Exception ex) {
                throw new BuildException("The \"path\" and/or \"version\" is not valid.", 
                    Location, ex);
            }
        }

        /// <summary>
        /// Gets the <see cref="VSSFlags" /> value corresponding with the 
        /// specified <see cref="FileTimestamp" />.
        /// </summary>
        /// <param name="timestamp">A <see cref="FileTimestamp" />.</param>
        /// <returns>
        /// An <see cref="int" /> representing the <see cref="VSSFlags" /> value
        /// for the <paramref name="timestamp" />.
        /// </returns>
        protected int GetFileTimestampFlags(FileTimestamp timestamp) {
            switch (timestamp) {
                case FileTimestamp.Current:
                    return Convert.ToInt32(VSSFlags.VSSFLAG_TIMENOW);
                case FileTimestamp.Modified:
                    return Convert.ToInt32(VSSFlags.VSSFLAG_TIMEMOD);
                case FileTimestamp.Updated:
                    return Convert.ToInt32(VSSFlags.VSSFLAG_TIMEUPD);
                default:
                    throw new InvalidEnumArgumentException("timestamp",
                        (int) timestamp, typeof(FileTimestamp));
            }
        }

        #endregion Protected Instance Methods
    }

    /// <summary>
    /// Defines how the local timestamp of files retrieved from a SourceSafe
    /// database should be set.
    /// </summary>
    public enum FileTimestamp {
        /// <summary>
        /// The timestamp of the local file is set to the current date and time.
        /// </summary>
        Current = 1,

        /// <summary>
        /// The timestamp of the local file is set to the file's last 
        /// modification date and time. 
        /// </summary>
        Modified = 2,

        /// <summary>
        /// The timestamp of the local file is set to the date and time that 
        /// the file was last checked in to the database.
        /// </summary>
        Updated = 3
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.