MetricClasses.cs :  » Development » devAdvantage » AnticipatingMinds » KnowledgePack » Design » 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 » KnowledgePack » Design » MetricClasses.cs
using System;
using System.Runtime.Serialization;
using AnticipatingMinds.PlatformServices.Configuration;
using AnticipatingMinds.Genesis.CodeDOM;
using AnticipatingMinds.Genesis.CodeDOM.Utilities;



namespace AnticipatingMinds.KnowledgePack.Design{
  public class MethodElementMetricsExceededRuleUtils
  {
    public static string GetMemberName(CodeTypeMemberDeclaration member)
    {
      string memberName = "";
      if(member is CodeTypeMethodDeclaration)
      {
        CodeTypeMethodDeclaration methodDeclaration = member as CodeTypeMethodDeclaration;
        
        memberName = (methodDeclaration.Name == ".ctor") ? CodeTypeReferenceUtils.GetShortestTypeNameReference(methodDeclaration.DeclaringType, methodDeclaration.DeclaringType.FullName) + "." + methodDeclaration.DeclaringType.Name : CodeTypeReferenceUtils.GetShortestTypeNameReference(methodDeclaration.DeclaringType, methodDeclaration.DeclaringType.FullName) + "." + methodDeclaration.Name ;
      }
      else if(member is CodeTypeIndexerDeclaration)
      {
        CodeTypeIndexerDeclaration indexerDeclaration = member as CodeTypeIndexerDeclaration;
        memberName = CodeTypeReferenceUtils.GetShortestTypeNameReference(indexerDeclaration.DeclaringType, indexerDeclaration.DeclaringType.FullName)+".this";
      }
      else if(member is CodeTypePropertyDeclaration)
      {
        CodeTypePropertyDeclaration propertyDeclaration = member as CodeTypePropertyDeclaration;
        memberName = CodeTypeReferenceUtils.GetShortestTypeNameReference(propertyDeclaration.DeclaringType, propertyDeclaration.DeclaringType.FullName) + "." + propertyDeclaration.Name;

      }
      else if(member is CodeTypeEventDeclaration)
      {
        CodeTypeEventDeclaration eventDeclaration = member as CodeTypeEventDeclaration;
        memberName = CodeTypeReferenceUtils.GetShortestTypeNameReference(eventDeclaration.DeclaringType, eventDeclaration.DeclaringType.FullName)+ "." + eventDeclaration.Name;
      }
      return memberName;
    }
  }
  
  /// <summary>
  /// Several classes for metric
  /// ( statements, local variables , method arguments, return points )
  /// </summary>
  
  
  public class MetricClasses
  {
    const string CONFIG_UI_ROOT = @"SOFTWARE\Anticipating Minds\DevAdvantage\Appearance\Rules\MethodElementMetricsExceededRuleTemplate";
    private RegistryConfiguration config = new RegistryConfiguration(CONFIG_UI_ROOT, RegistryConfiguration.RegistryTarget.LocalMachine);
    
    #region Default Values
    public virtual int MaximumDefault{get{return 0;}}
    public virtual int MinimumDefault{get{return 0;}}
    public virtual int LargeChangeDefault{get{return 1;}}
    public virtual int SmallChangeDefault{get{return 1;}}
    public virtual int Increment{ get{return 1;}}
    public virtual int TickFrequency{ get{return 1;}}
    public MetricDefaultValue MetricDefaultValue;
    public int DefaultValue
    {
      get
      {
        return this.MetricDefaultValue.GetValue(this.MetricType);
      }
    }
    #endregion
    public string MetricObjectName;
    public MetricClasses(MetricDefaultValue metricDefaultValue, string name)
    {
      MetricDefaultValue = metricDefaultValue;
      this.Init(name);
    }
    public void Update()
    {
      config.SetValue(this.MetricType, "Maximum", this.maximum);
      config.SetValue(this.MetricType, "Minimum", this.minimum);
      config.SetValue(this.MetricObjectName, "Value", this.localvalue);
      this.MetricDefaultValue.SetValue(this.MetricType, this.localvalue);
      config.SetValue(this.MetricType, "SmallChange", this.smallChange);
      config.SetValue(this.MetricType, "LargeChange", this.largeChange);
    }
    public void Init(string name)
    {
      this.MetricObjectName = this.MetricType + ":" + name;
      this.maximum = this.Maximum;
      this.minimum = this.Minimum;
      this.localvalue = this.Value;
      this.smallChange = this.SmallChange;
      this.largeChange = this.LargeChange;
    }
    public string MetricName
    {
      get{ return ResourceManager.GetLocalizedString("MethodElementMetricsExceeded|"+this.MetricType);}
    }
    public virtual string MetricType{get{ return "";}}
    
    private int maximum; 
    public int Maximum{ 
      get{
        if(config.GetInt32(this.MetricType, "Maximum", -1) == -1)
        {
          config.SetValue(this.MetricType, "Maximum", this.MaximumDefault);
        }
        return config.GetInt32(this.MetricType, "Maximum");
      } 
      set{
        this.maximum = value;
      }
    }
    private int minimum;
    public int Minimum
    { 
      get
      {
        if(config.GetInt32(this.MetricType, "Minimum", -1) == -1)
        {
          config.SetValue(this.MetricType, "Minimum", this.MinimumDefault);
        }
        return config.GetInt32(this.MetricType, "Minimum");
      } 
      set
      {
        this.minimum = value;
      }
    }
    private int localvalue;
    public int Value
    { 
      get
      {
        if(config.GetInt32(this.MetricObjectName, "Value", -1) == -1)
        {
          config.SetValue(this.MetricObjectName, "Value", this.DefaultValue);
        }
        return config.GetInt32(this.MetricObjectName, "Value");
      } 
      set
      {
        this.localvalue = value;
      }
    }
    
    private int smallChange;
    public int SmallChange
    { 
      get
      {
        if(config.GetInt32(this.MetricType, "SmallChange", -1) == -1)
        {
          config.SetValue(this.MetricType, "SmallChange", this.SmallChangeDefault);
        }
        return config.GetInt32(this.MetricType, "SmallChange");
      } 
      set
      {
        this.smallChange = value;
      }
    }
    private int largeChange;
    public int LargeChange
    { 
      get
      {
        if(config.GetInt32(this.MetricType, "LargeChange", -1) == -1)
        {
          config.SetValue(this.MetricType, "LargeChange", this.LargeChangeDefault);
        }
        return config.GetInt32(this.MetricType, "LargeChange");
      } 
      set
      {
        this.largeChange = value;
      }
    }
  }

  public class StatementsMetricClass : MetricClasses
  {
    #region Default Values
    public override int MaximumDefault{ get{return 100;}}
    public override int MinimumDefault{ get{return 0;}}
    public override int Increment{ get{ return 10; }}
    public override int TickFrequency{ get{return 10;}}
    
    public override int LargeChangeDefault{ get{return 10;}}
    public override int SmallChangeDefault{ get{return 10;}}
    #endregion
    public override  string MetricType{get{return "Statements";}}

    public StatementsMetricClass(MetricDefaultValue metricDefaultValue, string metricRuleName): base (metricDefaultValue, metricRuleName){}
  }
  public class LocalVariablesMetricClass : MetricClasses
  {
    #region Default Values
    public override int MaximumDefault{ get{return 20;}}
    public override int MinimumDefault{ get{return 0;}}
    public override int Increment{ get{ return 2; }}
    public override int TickFrequency{ get{return 2;}}
    
    public override int LargeChangeDefault{ get{return 1;}}
    public override int SmallChangeDefault{ get{return 1;}}
    #endregion
    public override  string MetricType{get{return "LocalVariables";}}
    public LocalVariablesMetricClass(MetricDefaultValue metricDefaultValue, string metricRuleName): base (metricDefaultValue, metricRuleName){}
  }
  public class MethodArgumentsMetricClass : MetricClasses
  {
    #region Default Values
    public override int MaximumDefault{ get{return 8;}}
    public override int MinimumDefault{ get{return 0;}}
    public override int Increment{ get{ return 1; }}
    public override int TickFrequency{ get{return 1;}}
    
    public override int LargeChangeDefault{ get{return 1;}}
    public override int SmallChangeDefault{ get{return 1;}}
    #endregion
    public override  string MetricType{get{return "MethodArguments";}}
    public MethodArgumentsMetricClass(MetricDefaultValue metricDefaultValue, string metricRuleName): base (metricDefaultValue, metricRuleName){}
  }
  public class ReturnPointsMetricClass : MetricClasses
  {
    #region Default Values
    public override int MaximumDefault{ get{return 8;}}
    public override int MinimumDefault{ get{return 0;}}
    public override int Increment{ get{ return 1; }}
    public override int TickFrequency{ get{return 1;}}
    
    public override int LargeChangeDefault{ get{return 1;}}
    public override int SmallChangeDefault{ get{return 1;}}
    #endregion
    public override  string MetricType{get{return "ReturnPoints";}}
    public ReturnPointsMetricClass(MetricDefaultValue metricDefaultValue, string metricRuleName): base (metricDefaultValue, metricRuleName){}
  }
  public class CyclomaticClass : MetricClasses
  {
    #region Default Values
    public override int MaximumDefault{ get{return 50;}}
    public override int MinimumDefault{ get{return 0;}}
    public override int Increment{ get{ return 10; }}
    public override int TickFrequency{ get{return 10;}}
    
    public override int LargeChangeDefault{ get{return 10;}}
    public override int SmallChangeDefault{ get{return 10;}}
    #endregion
    public override  string MetricType{get{return "Cyclomatic";}}
    public CyclomaticClass(MetricDefaultValue metricDefaultValue, string metricRuleName): base (metricDefaultValue, metricRuleName){}
  }
  public class CyclomaticDensityMetricClass : MetricClasses
  {
    #region Default Values
    public override int MaximumDefault{ get{return 8;}}
    public override int MinimumDefault{ get{return 0;}}
    public override int Increment{ get{ return 1; }}
    public override int TickFrequency{ get{return 1;}}
    
    public override int LargeChangeDefault{ get{return 1;}}
    public override int SmallChangeDefault{ get{return 1;}}
    #endregion
    public override  string MetricType{get{return "CyclomaticDensity";}}
    public CyclomaticDensityMetricClass(MetricDefaultValue metricDefaultValue, string metricRuleName): base (metricDefaultValue, metricRuleName){}
  }

  [Serializable]
  public class MetricDefaultValue : ISerializable
  {
    #region Serialization Support
    // A method called when serializing
    void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) 
    {
            info.AddValue("MethodArgumentsDefault", this.MethodArgumentsDefault);
            info.AddValue("ReturnPointsDefault", this.ReturnPointsDefault);
            info.AddValue("CyclomaticDefault", this.CyclomaticDefault);
            info.AddValue("CyclomaticDensityDefault", this.CyclomaticDensityDefault);
            info.AddValue("StatementsDefault", this.StatementsDefault);
        info.AddValue("LocalVariablesDefault", this.LocalVariablesDefault);
        }
    
    private MetricDefaultValue(SerializationInfo info, StreamingContext context)
    {
            this.MethodArgumentsDefault = info.GetInt32("MethodArgumentsDefault");
            this.ReturnPointsDefault = info.GetInt32("ReturnPointsDefault");
            this.CyclomaticDefault = info.GetInt32("CyclomaticDefault");
            this.CyclomaticDensityDefault = info.GetInt32("CyclomaticDensityDefault");
            this.StatementsDefault = info.GetInt32("StatementsDefault");
        this.LocalVariablesDefault = info.GetInt32("LocalVariablesDefault");
        }
    #endregion
    private int StatementsDefault = 100;
    private int LocalVariablesDefault = 20;
    private int MethodArgumentsDefault = 8;
    private int ReturnPointsDefault = 8;
    private int CyclomaticDefault = 50;
    private int CyclomaticDensityDefault = 6;
    public int GetValue(string typeName)
    {
      int localValue = 0;
      switch(typeName)
      {
        case "Statements":localValue = this.StatementsDefault; break;
        case "LocalVariables":localValue = this.LocalVariablesDefault; break;
        case "MethodArguments":localValue = this.MethodArgumentsDefault; break;
        case "ReturnPoints":localValue = this.ReturnPointsDefault; break;
        case "Cyclomatic":localValue = this.CyclomaticDefault; break;
        case "CyclomaticDensity":localValue = this.CyclomaticDensityDefault; break;
      }
      return localValue;
    }
    public void SetValue(string typeName, int typeValue)
    {
      switch(typeName)
      {
        case "Statements": this.StatementsDefault = typeValue; break;
        case "LocalVariables": this.LocalVariablesDefault = typeValue; break;
        case "MethodArguments":this.MethodArgumentsDefault = typeValue; break;
        case "ReturnPoints":this.ReturnPointsDefault = typeValue; break;
        case "Cyclomatic":this.CyclomaticDefault = typeValue; break;
        case "CyclomaticDensity":this.CyclomaticDensityDefault = typeValue; break;
      }
    }
    public MetricDefaultValue(){}
  }
}




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