Exemple #1
0
        // EndItem: CodeMetric

        // BeginItem: CalculateMetrics
        /// <summary>
        /// Calcula el número de partes, items y loc del archivo fuente indicado en el constructor.
        /// </summary>
        public void CalculateMetrics()
        {
            using (StreamReader fileStream = File.OpenText(filePath))
            {
                string   line           = "";
                CodePart currentPart    = null;
                CodeItem currentItem    = null;
                bool     startedComment = false;

                while ((line = fileStream.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (!startedComment && matchBeginLargeComment.IsMatch(line))
                    {
                        startedComment = true;
                    }
                    if (startedComment && matchEndLargeComment.IsMatch(line))
                    {
                        startedComment = false;
                    }

                    if (startedComment)
                    {
                        continue;
                    }

                    if (currentPart == null && matchBeginPart.IsMatch(line))
                    {
                        currentPart = new CodePart(matchBeginPart.Split(line)[1].Trim());
                    }
                    else if (currentPart != null)
                    {
                        if (matchEndPart.IsMatch(line))
                        {
                            parts.Add(currentPart);
                            currentPart = null;
                        }
                        else if (matchBeginItem.IsMatch(line))
                        {
                            currentItem = new CodeItem(matchBeginItem.Split(line)[1].Trim());
                        }
                        else if (currentItem != null)
                        {
                            if (matchEndItem.IsMatch(line))
                            {
                                currentPart.AddItem(currentItem);
                                currentItem = null;
                            }
                            else
                            {
                                currentItem.itemLoc++;
                            }
                        }

                        if (currentPart != null)
                        {
                            currentPart.partLoc++;
                        }
                    }

                    if (!matchSingleComment.IsMatch(line))
                    {
                        totalLoc++;
                    }
                }
            }
        }
Exemple #2
0
 // BeginItem: AddItem
 public void AddItem(CodeItem item)
 {
     _items.Add(item);
     itemsContent.Controls.Add(item);
     itemsCountLabel.Text = _items.Count.ToString();
 }