public IList GetMetricHistory(string codeElementName, NDependMetricDefinition metricDefinition)
        {
            CodeBaseManager codeBaseManager = new CodeBaseManager(analysisResultRefsList[0].Project);
            CodeElementsManagerReflectionHelper reflectionHelper = new CodeElementsManagerReflectionHelper();

            Type metricType = Type.GetType(metricDefinition.NDependMetricType);
            Type nullableMetricType = typeof(Nullable<>).MakeGenericType(metricType);
            var metricValue = Activator.CreateInstance(nullableMetricType);
            IList metricValues = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(nullableMetricType));

            foreach (var analysisResultRef in analysisResultRefsList)
            {
                ICodeBase currentAnalysisResultCodeBase = codeBaseManager.LoadCodeBase(analysisResultRef);
                CodeElementsManager currenAnalysisResultCodeBaseManager = new CodeElementsManager(currentAnalysisResultCodeBase);
                metricValue = null;

                switch (metricDefinition.NDependCodeElementType)
                {
                    case "NDepend.CodeModel.IAssembly":
                        IAssembly selectedAssemblyFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetAssemblyByName(codeElementName);
                        if (selectedAssemblyFromCurrentAnalysisResultCodebase != null)
                            metricValue = reflectionHelper.GetCodeElementMetric(
                                selectedAssemblyFromCurrentAnalysisResultCodebase,
                                typeof(IAssembly),
                                metricDefinition.InternalPropertyName,
                                metricDefinition.NDependMetricType);
                        break;

                    case "NDepend.CodeModel.INamespace":
                        INamespace selectedNamespaceFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetNamespaceByName(codeElementName);
                        if (selectedNamespaceFromCurrentAnalysisResultCodebase != null)
                            metricValue = reflectionHelper.GetCodeElementMetric(
                                selectedNamespaceFromCurrentAnalysisResultCodebase,
                                typeof(INamespace),
                                metricDefinition.InternalPropertyName,
                                metricDefinition.NDependMetricType);
                        break;
                    case "NDepend.CodeModel.IType":
                        IType selectedTypeFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetTypeByName(codeElementName);
                        if (selectedTypeFromCurrentAnalysisResultCodebase != null)
                            metricValue = reflectionHelper.GetCodeElementMetric(
                                selectedTypeFromCurrentAnalysisResultCodebase,
                                typeof(IType),
                                metricDefinition.InternalPropertyName,
                                metricDefinition.NDependMetricType);
                        break;
                    case "NDepend.CodeModel.IMethod":
                        IMethod selectedMethodFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetMethodByName(codeElementName);
                        if (selectedMethodFromCurrentAnalysisResultCodebase != null)
                            metricValue = (reflectionHelper.GetCodeElementMetric(
                                selectedMethodFromCurrentAnalysisResultCodebase,
                                typeof(IMethod),
                                metricDefinition.InternalPropertyName,
                                metricDefinition.NDependMetricType));
                        break;
                }
                metricValues.Add(metricValue);
            }
            return metricValues;
        }
Exemplo n.º 2
0
 private void lvwMetricsList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.lvwMetricsList.SelectedItems.Count > 0)
     {
         ListViewItem            lvi = this.lvwMetricsList.SelectedItems[0];
         NDependMetricDefinition nDependMetricDefinition = (NDependMetricDefinition)lvi.Tag;
         FillMetricDescriptionRTFBox(nDependMetricDefinition);
     }
 }
Exemplo n.º 3
0
 private void FillMetricDescriptionRTFBox(NDependMetricDefinition nDependMetricDefinition)
 {
     this.rtfMetricProperties.Clear();
     this.rtfMetricProperties.AppendText(nDependMetricDefinition.MetricName);
     this.rtfMetricProperties.Find(nDependMetricDefinition.MetricName);
     this.rtfMetricProperties.SelectionFont   = new Font(rtfMetricProperties.Font, rtfMetricProperties.Font.Style ^ FontStyle.Bold);
     this.rtfMetricProperties.SelectionStart  = this.rtfMetricProperties.Text.Length;
     this.rtfMetricProperties.SelectionLength = 0;
     this.rtfMetricProperties.SelectionFont   = rtfMetricProperties.Font;
     this.rtfMetricProperties.AppendText(Environment.NewLine + nDependMetricDefinition.Description);
 }
Exemplo n.º 4
0
 private void lvwMetricsList_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (this.lvwMetricsList.SelectedItems.Count > 0)
     {
         ListViewItem            lvi = this.lvwMetricsList.SelectedItems[0];
         NDependMetricDefinition nDependMetricDefinition = (NDependMetricDefinition)lvi.Tag;
         IList  metricValues = new AnalysisHistoryManager(nDependProject).GetMetricHistory(this.lblCodeElementName.Text, nDependMetricDefinition);
         string chartTitle   = this.lblCodeElementType.Text.ToUpper() + ": " + this.lblCodeElementName.Text;
         ShowMetricChart(chartTitle, nDependMetricDefinition.MetricName, metricValues);
     }
 }
Exemplo n.º 5
0
        public MetricProperties(
            NDependMetricDefinition nDependMetricDefinition,
            string codeElementName,
            DataTable selectedCodeElementMatricsDataTable,
            string parentCodeElementName,
            string assemblyName,
            IProject nDependProject)
            : this(codeElementName, selectedCodeElementMatricsDataTable, parentCodeElementName, assemblyName, nDependProject)
        {
            this.metricDefinitionType    = MetricDefinitionType.NDependMetric;
            this.nDependMetricDefinition = nDependMetricDefinition;
            this.codeElementType         = nDependMetricDefinition.NDependCodeElementType.Split('.').Last <string>().Substring(1);
            this.metricResumedName       = nDependMetricDefinition.PropertyName;
            this.metricFullName          = nDependMetricDefinition.MetricName;
            this.metricDescription       = nDependMetricDefinition.Description;
            this.metricType = nDependMetricDefinition.NDependMetricType;

            FillControls();
        }
        private void ListViewMouseDoubleClickEventManager(ListView senderListView)
        {
            if (senderListView.SelectedItems.Count > 0)
            {
                MetricProperties metricProperties;

                DataGridView        sourceDataGridView    = (DataGridView)senderListView.Tag;
                string              codeElementName       = sourceDataGridView.SelectedRows[0].Cells[0].Value.ToString();
                DataTable           metricsDataTable      = (DataTable)sourceDataGridView.DataSource;
                DataGridViewTagInfo dataGridViewTagInfo   = ((DataGridViewTagInfo)sourceDataGridView.Tag);
                DataGridView        assembliesDatagrid    = GetAssebliesDataGridView(sourceDataGridView);
                string              assemblyName          = assembliesDatagrid.SelectedRows[0].Cells[0].Value.ToString();
                string              parentCodeElementName = dataGridViewTagInfo.LinkedDataGrids.ParentDataGridView == null ?
                                                            ((IAssembly)codeElementsManager.CodeBase.Assemblies.WithName(assemblyName).First()).VisualStudioProjectFilePath.FileName :
                                                            dataGridViewTagInfo.LinkedDataGrids.ParentDataGridView.SelectedRows[0].Cells[0].Value.ToString();

                ListViewItem lvi = senderListView.SelectedItems[0];
                if (lvi.Tag.GetType() == typeof(NDependMetricDefinition))
                {
                    NDependMetricDefinition nDependMetricDefinition = (NDependMetricDefinition)lvi.Tag;
                    metricProperties = new MetricProperties(
                        nDependMetricDefinition,
                        codeElementName,
                        metricsDataTable,
                        parentCodeElementName,
                        assemblyName,
                        nDependProject);
                }
                else
                {
                    UserDefinedMetricDefinition userDefinedMetricDefinition = (UserDefinedMetricDefinition)lvi.Tag;
                    metricProperties = new MetricProperties(
                        userDefinedMetricDefinition,
                        codeElementName,
                        metricsDataTable,
                        parentCodeElementName,
                        assemblyName,
                        nDependProject);
                }

                metricProperties.Show();
            }
        }
Exemplo n.º 7
0
        public List <double> GetMetricFromAllCodeElementsInAssembly(NDependMetricDefinition codeElementMetricDefinition, string assemblyName)
        {
            string codeElementType = codeElementMetricDefinition.NDependCodeElementType;

            switch (codeElementType)
            {
            case "NDepend.CodeModel.IAssembly":
                return(null);

            case "NDepend.CodeModel.INamespace":
                return((from m in codeBase.Assemblies.WithName(assemblyName).ChildNamespaces()
                        select GetCodeElementMetricValue <INamespace>((INamespace)m, codeElementMetricDefinition)).ToList());

            case "NDepend.CodeModel.IType":
                return((from m in codeBase.Assemblies.WithName(assemblyName).ChildTypes()
                        select GetCodeElementMetricValue <IType>((IType)m, codeElementMetricDefinition)).ToList());

            case "NDepend.CodeModel.IMethod":
                return((from m in codeBase.Assemblies.WithName(assemblyName).ChildMethods()
                        select GetCodeElementMetricValue <IMethod>((IMethod)m, codeElementMetricDefinition)).ToList());
            }
            return(null);
        }
Exemplo n.º 8
0
        public double GetCodeElementMetricValue <CodeElementType>(CodeElementType codeElement, NDependMetricDefinition codeElementMetricDefinition)
        {
            Double       metricValue = 0;
            PropertyInfo property    = codeElement.GetType().GetProperty(codeElementMetricDefinition.InternalPropertyName);

            if (property != null)
            {
                metricValue = Convert.ToDouble(property.GetValue(codeElement));
            }
            return(metricValue);
        }
Exemplo n.º 9
0
 public object GetCodeElementMetricValue(object codeElement, Type codeElementType, NDependMetricDefinition codeElementMetricDefinition)
 {
     Type[]   genericTypes     = new Type[] { codeElementType, Type.GetType(codeElementMetricDefinition.NDependMetricType) };
     object[] methodParameters = new object[] { codeElement, codeElementMetricDefinition };
     return(GenericsHelper.InvokeInstanceGenericMethod(this, this.GetType().FullName, "GetGenericCodeElementMetricValue", genericTypes, methodParameters));
 }
Exemplo n.º 10
0
        public MetricType GetGenericCodeElementMetricValue <CodeElementType, MetricType>(CodeElementType codeElement, NDependMetricDefinition codeElementMetricDefinition)
        {
            PropertyInfo property = codeElement.GetType().GetProperty(codeElementMetricDefinition.InternalPropertyName);

            return((MetricType)property.GetValue(codeElement));
        }
Exemplo n.º 11
0
        public IList GetMetricHistory(string codeElementName, NDependMetricDefinition metricDefinition)
        {
            CodeBaseManager codeBaseManager = new CodeBaseManager(analysisResultRefsList[0].Project);
            CodeElementsManagerReflectionHelper reflectionHelper = new CodeElementsManagerReflectionHelper();

            Type  metricType         = Type.GetType(metricDefinition.NDependMetricType);
            Type  nullableMetricType = typeof(Nullable <>).MakeGenericType(metricType);
            var   metricValue        = Activator.CreateInstance(nullableMetricType);
            IList metricValues       = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(nullableMetricType));

            foreach (var analysisResultRef in analysisResultRefsList)
            {
                ICodeBase           currentAnalysisResultCodeBase       = codeBaseManager.LoadCodeBase(analysisResultRef);
                CodeElementsManager currenAnalysisResultCodeBaseManager = new CodeElementsManager(currentAnalysisResultCodeBase);
                metricValue = null;

                switch (metricDefinition.NDependCodeElementType)
                {
                case "NDepend.CodeModel.IAssembly":
                    IAssembly selectedAssemblyFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetAssemblyByName(codeElementName);
                    if (selectedAssemblyFromCurrentAnalysisResultCodebase != null)
                    {
                        metricValue = reflectionHelper.GetCodeElementMetric(
                            selectedAssemblyFromCurrentAnalysisResultCodebase,
                            typeof(IAssembly),
                            metricDefinition.InternalPropertyName,
                            metricDefinition.NDependMetricType);
                    }
                    break;

                case "NDepend.CodeModel.INamespace":
                    INamespace selectedNamespaceFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetNamespaceByName(codeElementName);
                    if (selectedNamespaceFromCurrentAnalysisResultCodebase != null)
                    {
                        metricValue = reflectionHelper.GetCodeElementMetric(
                            selectedNamespaceFromCurrentAnalysisResultCodebase,
                            typeof(INamespace),
                            metricDefinition.InternalPropertyName,
                            metricDefinition.NDependMetricType);
                    }
                    break;

                case "NDepend.CodeModel.IType":
                    IType selectedTypeFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetTypeByName(codeElementName);
                    if (selectedTypeFromCurrentAnalysisResultCodebase != null)
                    {
                        metricValue = reflectionHelper.GetCodeElementMetric(
                            selectedTypeFromCurrentAnalysisResultCodebase,
                            typeof(IType),
                            metricDefinition.InternalPropertyName,
                            metricDefinition.NDependMetricType);
                    }
                    break;

                case "NDepend.CodeModel.IMethod":
                    IMethod selectedMethodFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetMethodByName(codeElementName);
                    if (selectedMethodFromCurrentAnalysisResultCodebase != null)
                    {
                        metricValue = (reflectionHelper.GetCodeElementMetric(
                                           selectedMethodFromCurrentAnalysisResultCodebase,
                                           typeof(IMethod),
                                           metricDefinition.InternalPropertyName,
                                           metricDefinition.NDependMetricType));
                    }
                    break;
                }
                metricValues.Add(metricValue);
            }
            return(metricValues);
        }