RuleViolation.cs :  » Development » devAdvantage » AnticipatingMinds » Genesis » KnowledgeManagement » 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 » Development » devAdvantage 
devAdvantage » AnticipatingMinds » Genesis » KnowledgeManagement » RuleViolation.cs
using System;
using System.Collections;
using AnticipatingMinds.Genesis.CodeDOM;

namespace AnticipatingMinds.Genesis.KnowledgeManagement{
  /// <summary>
  /// Represents a rule violation found in the code.
  /// </summary>
  public class RuleViolation
  {
    /// <summary>
    /// Represents a severity of the violation.
    /// </summary>
    public enum ViolationSeverity
    {
      /// <summary>
      /// Error
      /// </summary>
      Error,
      /// <summary>
      /// Warning
      /// </summary>
      Warning,
      /// <summary>
      /// Suggestion
      /// </summary>
      Suggestion
    }

    /// <summary>
    /// Represents a degree of violation correctability.
    /// </summary>
    public enum ViolationCorrectability
    {
      /// <summary>
      /// No automatic correction is possible.
      /// </summary>
      None,
      /// <summary>
      /// Fully automatic correction is possible.
      /// </summary>
      Auto,
      /// <summary>
      /// Correction is possible but requires user input.
      /// </summary>
      Interactive
    }

    /// <summary>
    /// Initializes new instance of the <see cref="RuleViolation"/> class.
    /// </summary>
    /// <param name="violatedRule">An instance of the rule that raised violation.</param>
    /// <param name="locationAnchor">A code element that represents where rule occured. (Position of violation)</param>
    public RuleViolation(Rule violatedRule,CodeElement locationAnchor):this(violatedRule,string.Empty, locationAnchor)
    {
    }

    /// <summary>
    /// Initializes new instance of the <see cref="RuleViolation"/> class.
    /// </summary>
    /// <param name="violatedRule">An instance of the rule that raised violation.</param>
    /// <param name="description">Violation description.</param>
    /// <param name="locationAnchor">A code element that represents where rule occured. (Position of violation)</param>
    public RuleViolation(Rule violatedRule , string description,CodeElement locationAnchor)
    {
      this.violatedRule = violatedRule;
      this.locationAnchor = locationAnchor;
      this.description = description;
    }

    /// <summary>
    /// Gets or sets flag whether the rule is fixed.
    /// </summary>
    public bool IsFixed
    {
      get
      {
        return isFixed;
      }
      set
      {
        isFixed = value;
      }
    }

    /// <summary>
    /// Gets an instance of the rule that has raised the violation.
    /// </summary>
    public Rule ViolatedRule
    {
      get
      {
        return violatedRule;
      }
    }

    /// <summary>
    /// Gets or sets violation severity.
    /// </summary>
    public ViolationSeverity Severity
    {
      get
      {
        return severity;
      }
      set
      {
        severity= value;
      }
    }

    /// <summary>
    /// Gets violation correctability.
    /// </summary>
    /// <remarks>
    /// Correctability returned by this property is the best correctability found
    /// in all possible corrections.
    /// </remarks>
    public ViolationCorrectability Correctability
    {
      get
      {
        if(Corrections.Count == 0)
          return ViolationCorrectability.None;

        //Return ability to correct base on the default correction.
        //User will use default correction in case of correcting multiple
        //violations and correctability should correspond to one promissed.
        
        foreach(RuleViolationCorrection correction in Corrections)
          if(correction.IsDefault)
            if(!correction.IsInteractive)
              return ViolationCorrectability.Auto;
            else
              return ViolationCorrectability.Interactive;

        return ViolationCorrectability.Interactive;
      }
    }

    /// <summary>
    /// Adds possible correction description.
    /// </summary>
    /// <param name="name">Name of the correction</param>
    /// <param name="isDefault">Is it a default correction.</param>
    /// <param name="isInteractive">Is correction interactive.</param>
    /// <returns>A new instance of <see cref="RuleViolationCorrection"/> class that 
    /// describes possible violation correction.</returns>
    public RuleViolationCorrection AddCorrection(string name,bool isDefault,bool isInteractive)
    {
      return AddCorrection(name,isDefault,isInteractive,string.Empty);
    }
    
    /// <summary>
    /// Adds possible correction description.
    /// </summary>
    /// <param name="name">Name of the correction</param>
    /// <param name="isDefault">Is it a default correction.</param>
    /// <param name="isInteractive">Is correction interactive.</param>
    /// <param name="helpUrl">Correction help url.</param>
    /// <returns>A new instance of <see cref="RuleViolationCorrection"/> class that 
    /// describes possible violation correction.</returns>
    public RuleViolationCorrection AddCorrection(string name,bool isDefault,bool isInteractive,string helpUrl)
    {
      //Verify that there is no more than one default correction
      if(isDefault)
      {
        foreach(RuleViolationCorrection violationCorrection in corrections)
          if(violationCorrection.IsDefault)
            throw new InvalidOperationException("Corrections collection already contains default correction. Only one default correction is allowed per violation");
      }

      RuleViolationCorrection correction = new RuleViolationCorrection(this,name,isDefault,isInteractive,helpUrl);
      corrections.Add(correction);
      return correction;
    }

    /// <summary>
    /// Gets a collection of possible violation corrections.
    /// </summary>
    public RuleViolationCorrectionCollection Corrections
    {
      get
      {
        return corrections;
      }
    }

    /// <summary>
    /// Gets violation line number.
    /// </summary>
    public int Line
    {
      get
      {
        return locationAnchor == null ? -1:locationAnchor.SourcePosition.Line;
      }
    }

    /// <summary>
    /// Get violation column.
    /// </summary>
    public int Column 
    {
      get
      {
        return locationAnchor == null ? -1:locationAnchor.SourcePosition.Column;
      }
    }
    /// <summary>
    /// Get violation absolute position in characters from the begining of the file.
    /// </summary>
    public int Position
    {
      get
      {
        return locationAnchor == null ? -1:locationAnchor.SourcePosition.Position;
      }
    }

    /// <summary>
    /// Get violation position file name.
    /// </summary>
    public string FileName
    {
      get
      {
        return locationAnchor == null ? string.Empty : locationAnchor.SourcePosition.FileName;
      }
    }
            
    /// <summary>
    /// Gets or sets violation description.
    /// </summary>
    /// <value>Violation description.</value>
    public string Description
    {
      get
      {
        return description;
      }
      set
      {
        description = value == null ? string.Empty:value;
      }
    }

    /// <summary>
    /// Code Element that is serving as violation location anchor
    /// </summary>
    public CodeElement LocationAnchor
    {
      get
      {
        return locationAnchor;
      }
      set
      {
        locationAnchor = value;
      }
    }

    /// <summary>
    /// Holds data associated with violation.
    /// </summary>
    public IDictionary ViolationData
    {
      get
      {
        return violationData;
      }
    }

    private Hashtable violationData = new Hashtable();
    private Rule violatedRule;
    private ViolationSeverity severity;
    private string description;
    private CodeElement locationAnchor;
    private RuleViolationCorrectionCollection corrections = new RuleViolationCorrectionCollection();

    bool isFixed = false;
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.