Click here to Skip to main content
15,895,833 members
Articles / Programming Languages / C#

NAnt Task to Capture Out of Bounds Source Monitor Metrics

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
12 Jun 2009CPOL5 min read 22.2K   61   6  
NAnt user task that adds alarms on top of Source Monitor metrics to highlight source code that does not follow coding rules.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace NAnt.SMAnalyzerTasks
{
    /// <summary>
    /// Class that contains the list of Threshold objects for a given file.
    /// </summary>
    class FileThresholds
    {
        private string m_sFileName= "";
        private Hashtable m_Thresholds = new Hashtable(15);

        #region Constructors

        public FileThresholds()
        {
        }

        public FileThresholds(string sFileName)
        {
            m_sFileName = sFileName;
        }

        /// <summary>
        /// Copy constructor.
        /// </summary>
        public FileThresholds(FileThresholds oOther)
        {
            m_sFileName = oOther.FileName;
            m_Thresholds = (Hashtable)oOther.Thresholds.Clone();
        }

        #endregion

        /// <summary>
        /// Add a new Threshold to the given object.
        /// <br>If a Threshold with the same id already exist it will be overwritten</br>
        /// </summary>
        public void AddThreshold(Threshold oThreshold)
        {
            _AddThreshold(oThreshold);
        }

        /// <summary>
        /// Remove the Threshold having the given ID intot the current object.
        /// </summary>
        public void RemoveThreshold(string sId)
        {
            if (null != m_Thresholds)
            {
                if(m_Thresholds.ContainsKey(sId))
                {
                    m_Thresholds.Remove(sId);
                }
            }
        }

        public string FileName
        {
            get { return m_sFileName; }
            set { m_sFileName = value; }
        }

        public Hashtable Thresholds
        {
            get
            {
                return m_Thresholds;
            }
        }


        /// <summary>
        /// Add the given Threshold to the current object.
        /// <br>Check if it already exist to overwrite</br>
        /// </summary>
        private void _AddThreshold(Threshold oThreshold)
        {
            if (null != m_Thresholds)
            {
                if(true==m_Thresholds.ContainsKey(oThreshold.ID))
                {
                    //object already exist
                    //destroy 
                    m_Thresholds.Remove(oThreshold.ID);
                    //overwrite it 
                    m_Thresholds.Add(oThreshold.ID, oThreshold);
                }
                else
                {
                    m_Thresholds.Add(oThreshold.ID, oThreshold);
                }
            }
        }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Schlumberger
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions