public override void Count(ref CodeLineCount count) { base.Count(ref count); if (this.TargetFile.EndsWith(".Designer.cs")) { count.Design = count.Total - count.Annotate - count.AnnotateMix - count.Space; } }
public void Sub(CodeLineCount count) { this.Annotate -= count.Annotate; this.AnnotateMix -= count.AnnotateMix; this.Design -= count.Design; this.Resource -= count.Resource; this.Space -= count.Space; this.Total -= count.Total; }
public void Add(CodeLineCount count) { this.Annotate += count.Annotate; this.AnnotateMix += count.AnnotateMix; this.Design += count.Design; this.Resource += count.Resource; this.Space += count.Space; this.Total += count.Total; }
public override void Count(ref CodeLineCount count) { XmlDocument resx = new XmlDocument(); using (FileStream stream = new FileStream(this.TargetFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { resx.Load(stream); } foreach (XmlNode dataNode in resx.DocumentElement.SelectNodes("data")) { if (null == dataNode.Attributes["type"]) { int resourceLines = dataNode.SelectSingleNode("value").InnerText .Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length; count.Resource += resourceLines; count.Total += resourceLines; } else if (dataNode.Attributes["type"].Value.StartsWith("System.Resources.ResXFileRef", StringComparison.OrdinalIgnoreCase)) { string resourceFile = dataNode.SelectSingleNode("value").InnerText.Split(';')[0]; string resourceDir = Path.GetDirectoryName(this.TargetFile); while (resourceFile.Contains(@"..\")) { resourceDir = Path.GetDirectoryName(resourceDir); resourceFile = resourceFile.Substring(3); } string resourceTxtFile = Path.Combine(resourceDir, resourceFile); using (StreamReader reader = new StreamReader(resourceTxtFile)) { while (!reader.EndOfStream) { string currentLine = reader.ReadLine().Trim(); if (currentLine.Length > 0) { count.Resource++; count.Total++; } } } } } }
public override void Count(ref CodeLineCount count) { if (File.Exists(TargetFile)) { using (StreamReader reader = new StreamReader(TargetFile)) { while (!reader.EndOfStream) { string currentLine = reader.ReadLine().Trim(); if (currentLine.StartsWith("-") || currentLine.StartsWith("+")) { if (!currentLine.StartsWith("---") && !currentLine.StartsWith("+++")) { count.Total++; } } } } } }
public override void Count(ref CodeLineCount count) { try { using (FileStream stream = new FileStream(this.TargetFile, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)) using (ExcelPackage package = new ExcelPackage(stream)) { ExcelWorkbook book = package.Workbook; foreach (ExcelWorksheet sheet in book.Worksheets) { if (sheet.Dimension != null) { count.Total += sheet.Dimension.Rows; } } } } catch { } }
public virtual void Count(ref CodeLineCount count) { if (File.Exists(TargetFile)) { using (StreamReader reader = new StreamReader(TargetFile)) { while (!reader.EndOfStream) { string currentLine = reader.ReadLine().Trim(); isMix = false; CountLine(ref count, currentLine); } } } }
private void CountLine(ref CodeLineCount count, string currentLine) { if (0 == currentLine.Length) { count.Space++; } else { int currentIndex = 0; switch (FindNextSymbol(currentLine, ref currentIndex)) { case AnnotateType.None: if (inAnnotateBlock) { count.Annotate++; } break; case AnnotateType.Line: CheckAnnotateLine(ref count, currentLine, currentIndex); break; case AnnotateType.Begin: CheckAnnotateBlockBegin(ref count, currentLine, currentIndex); break; case AnnotateType.End: CheckAnnotateBlockEnd(ref count, currentLine, currentIndex); break; } } count.Total++; }
private void CheckAnnotateLine(ref CodeLineCount count, string currentLine, int currentIndex) { if (inAnnotateBlock) { int nextEndIndex = currentLine.IndexOf(this.AnnotateBlockEndKeyWord, currentIndex); if (-1 == nextEndIndex) { count.Annotate++; } else { CheckAnnotateBlockEnd(ref count, currentLine, nextEndIndex); } } else { if (0 == currentIndex) { count.Annotate++; } else { count.AnnotateMix++; } } }
private void CheckAnnotateBlockEnd(ref CodeLineCount count, string currentLine, int currentIndex) { inAnnotateBlock = false; currentIndex = currentIndex + this.AnnotateBlockEndKeyWord.Length; if (currentIndex < currentLine.Length) { int startIndex = currentIndex; AnnotateType nextType = FindNextSymbol(currentLine, ref startIndex); switch (nextType) { case AnnotateType.None: count.AnnotateMix++; break; case AnnotateType.Line: if (currentIndex == startIndex) { count.Annotate++; } else { count.AnnotateMix++; } break; case AnnotateType.Begin: if (!isMix && currentIndex != startIndex) { count.AnnotateMix++; isMix = true; } CheckAnnotateBlockBegin(ref count, currentLine, currentIndex); break; case AnnotateType.End: this.Message = "发现错误的注释块结尾"; break; } } else { if (!isMix) { count.Annotate++; } } }
private string GenerateMessage(CodeLineCount countObj) { StringBuilder message = new StringBuilder(); message.AppendFormat("总行数:{0}", countObj.Total); int fixedCount = countObj.Total; foreach (ListViewItem item in listViewInclude.Items) { PropertyInfo info = item.Tag as PropertyInfo; int count = (int)info.GetValue(countObj, null); message.AppendFormat(", {0}:{1}", item.Text, count); if (!item.Checked) { fixedCount -= count; } } message.AppendFormat(", 修正后行数:{0}", fixedCount); message.AppendLine(); return message.ToString(); }
private void OutputCount() { //richTextBoxReport.Clear(); StringBuilder countMessage = new StringBuilder(); CodeLineCount totalCountObj = new CodeLineCount(); foreach (AbstractCodeFile codeFile in this.rootFile.IncludeFiles) { countMessage.Append(GenerateMessage(codeFile)); totalCountObj.Add(codeFile.CodeLineCount); } countMessage.AppendLine("----------------------------------所有工程总计----------------------------------"); countMessage.Append(GenerateMessage(totalCountObj)); labelTotal.Text = "总计:" + GenerateMessage(totalCountObj).Trim(); //richTextBoxReport.Text = countMessage.ToString(); }
public AbstractCodeFile() { codeLineCount = new CodeLineCount(); IncludeFiles = new List<AbstractCodeFile>(); }
public override void Count(ref CodeLineCount count) { throw new NotImplementedException(); }