精确计算TFS中新增以及更改的代码行数
<configuration>
<configSections>
<section name="LOCTargets"
type="ConsoleApplication2.TFSConfigSection, TFSChangeLOC" />
</configSections>
<appSettings>
<add key="OutputFilePath" value="C:\Users\xingy\Desktop\LOCdemo.html"/>
</appSettings>
<LOCTargets>
<add LocalPath="C:\SPA_5150\Apps\IntelligentRewards\dev\source"
StartChangeSetId="373171" EndChangeSetId="373173"/>
<add LocalPath="C:\SPA_5150\Apps\Framework\source"
StartChangeSetId="373165" EndChangeSetId="373170"/>
</LOCTargets>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
class Program
{
static int addNumber = ;
static int delNumber = ;
static int editNumber = ;
static int otherNumber = ;
static int renameNumber = ;
static Dictionary<int, int> changeSetDic = new Dictionary<int, int>();
static List<string> changedFiles = new List<string>(); static void Main(string[] args)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
TFSConfigSection section = config.Sections["LOCTargets"] as TFSConfigSection;
foreach (Target locTarget in section.Instances)
{
TFS(locTarget.LocalPath,locTarget.StartChangeSetId,locTarget.EndChangeSetId);
} ScanFiles();
OutputHtmlFile(changeSetDic); Console.WriteLine("Press Any Key to Exit ... ...");
Console.Read();
} private static void TFS(string localPath,string startId,string endId)
{
Uri tfsUri = new Uri("http://rnotfsat:8080/tfs");
string tfsPath = null; try
{
TfsConfigurationServer configurationServer =
TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); // Get the catalog of team project collections
ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
new[] {CatalogResourceTypes.ProjectCollection},
false, CatalogQueryOptions.None); // List the team project collections
foreach (CatalogNode collectionNode in collectionNodes)
{
// Use the InstanceId property to get the team project collection
Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId); if (!teamProjectCollection.Name.Equals(@"rnotfsat\rnotfsat"))
continue; var vcs = teamProjectCollection.GetService<VersionControlServer>();
var workSpace = vcs.GetWorkspace(localPath);
tfsPath = workSpace.GetServerItemForLocalItem(localPath); var changesetList = vcs.QueryHistory(
tfsPath,
VersionSpec.Latest,
,
RecursionType.Full,
null,
VersionSpec.ParseSingleSpec(startId, null),
VersionSpec.ParseSingleSpec(endId, null),
Int32.MaxValue,
true,
false).Cast<Changeset>(); foreach (var cs in changesetList)
{
changeSetDic.Add(cs.ChangesetId, ); var changeList = cs.Changes;
foreach (var change in changeList)
{
if (change.Item != null)
{
var localFile = workSpace.GetLocalItemForServerItem(change.Item.ServerItem);
if (change.ChangeType.HasFlag(ChangeType.Edit))
{
if (!changedFiles.Contains(localFile))
{
changedFiles.Add(localFile);
}
editNumber++;
} else if (change.ChangeType.HasFlag(ChangeType.Add))
{
if (File.Exists(localFile))
{
changeSetDic[cs.ChangesetId] += File.ReadLines(localFile).Count();
addNumber++;
}
} else if (change.ChangeType.HasFlag(ChangeType.Rename) ||
change.ChangeType.HasFlag(ChangeType.SourceRename))
{
renameNumber++;
} else if (change.ChangeType.HasFlag(ChangeType.Delete))
{
delNumber++;
} else
{
otherNumber++;
}
}
}
}
}
}
catch (ChangesetNotFoundException)
{
Console.WriteLine("!! Please check the change set id inside your config file !!");
}
catch (Exception e)
{
Console.WriteLine(e);
}
} private static void ScanFiles()
{
Console.WriteLine("In total {0} files will be scanned !", changedFiles.Count);
Console.WriteLine();
Console.WriteLine(); int left = changedFiles.Count; foreach (var csFile in changedFiles)
{
GetContent(changeSetDic, csFile);
Console.WriteLine(csFile + " is scanned and analyzed !");
left--;
Console.WriteLine("{0} files left.", left);
}
} private static void GetContent(Dictionary<int, int>csDic, string filePath)
{
Process proc = new Process();
proc.StartInfo.FileName = "tfpt";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.Arguments = " annotate \"" + filePath + "\" /noprompt";
proc.Start(); StringBuilder sb = new StringBuilder();
while (!proc.HasExited)
{
sb.Append(proc.StandardOutput.ReadToEnd());
} string allResult = sb.ToString();
String[] lines = allResult.Split(new [] {Environment.NewLine},Int32.MaxValue,StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines)
{
var csIdInStr = line.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
int csId = Convert.ToInt32(csIdInStr[]); if (csDic.ContainsKey(csId))
{
csDic[csId]++;
}
}
} private static void OutputHtmlFile(Dictionary<int, int> csDic)
{
string htmlSource = File.ReadAllText("HTMLTemplate.html");
int totalCount = ; StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<int, int> kv in csDic)
{
sb.Append("<tr><td>").Append(kv.Key).Append("</td><td>").Append(kv.Value).Append("</td></tr>");
totalCount += kv.Value;
} htmlSource = Regex.Replace(htmlSource, "yukunContent", sb.ToString());
htmlSource = Regex.Replace(htmlSource, "yukunTotal", totalCount.ToString());
htmlSource = Regex.Replace(htmlSource, "AddNumber", addNumber.ToString());
htmlSource = Regex.Replace(htmlSource, "EditNumber", editNumber.ToString());
htmlSource = Regex.Replace(htmlSource, "DeleteNumber", delNumber.ToString());
htmlSource = Regex.Replace(htmlSource, "OtherNumber", otherNumber.ToString());
htmlSource = Regex.Replace(htmlSource, "RenameNumber", renameNumber.ToString());
File.WriteAllText(ConfigurationManager.AppSettings["OutputFilePath"], htmlSource);
}
}
精确计算TFS中新增以及更改的代码行数的更多相关文章
- python3 计算文件夹中所有py文件里面代码行数,注释行数,空行数
import os,re #代码所在位置 FILE_PATH = './' def analyze_code(codefilesource): ''' 打开一个py文件统计其中的代码行数,包括空格和注 ...
- VS2015 中统计整个项目的代码行数
在一个大工程中有很多的源文件和头文件,我如何快速统计总行数? ------解决方案--------------------b*[^:b#/]+.*$^b*[^:b#/]+.*$ ctrl + shif ...
- Python计算一个项目中含有的代码行数
最近想要知道以前做过的project有多少行代码,因为文件太多,直接手工数效率太低,于是编写一个python程序用来计算一个project有多少代码行. 首先,在一个项目中,有很多子文件夹,子文件夹中 ...
- 计算代码行数Demo源码
源码下载:04-计算代码行数.zip24.1 KB//// main.m// 计算代码行数//// Created by apple on 13-8-12.//技术博客http://www.cn ...
- 【原】Mac下统计任意文件夹中代码行数的工具——cloc
这里介绍一个Mac系统统计代码行数的工具cloc. 1.首先,安装homebrew,已安装的请跳过. 打开终端工具Terminal,输入下列命令.过程中会让你按RETURN键以及输入mac桌面密码,按 ...
- php 计算代码行数
<?php header("Content-type:text/html;charset=utf-8"); // php 递归计算文件夹代码行数 function codeL ...
- 【未解决】对于使用Windows的IDEA进行编译的文件,但无法在Linux系统中统计代码行数的疑问
在我学习使用Windows的IDEA的过程中,将代码文件转移到Linux虚拟机当中,但无法在Linux系统中统计代码行数. 注意:拷贝进虚拟机的文件均能编译运行. 具体过程如下: root@yogil ...
- 使用vs的查找功能,简单大概的统计vs中的代码行数
VS强大的查找功能,可以使用正则表达式来进行查找,这里统计代码行数的原理就是: 在所有指定文件中进行搜索,统计匹配的文本行数. 但是匹配的行需要满足:非注释.非空等特殊非代码行. 使用Ctrl+Shi ...
- 【原】Mac下统计任意文件夹中代码行数的工
[链接][原]Mac下统计任意文件夹中代码行数的工http://www.cnblogs.com/wengzilin/p/4580646.html
随机推荐
- C++ 表达式
<C++ Primer 4th>读书摘要 C++ 提供了丰富的操作符,并定义操作数为内置类型时,这些操作符的含义.除此之外,C++ 还支持操作符重载,允许程序员自定义用于类类型时操作符的含 ...
- 再谈this
不管学习什么知识,习惯于把自己所学习的知识列成一个list,会有助于我们理清思路,是一个很好的学习方法.强烈推荐. 以下篇幅有点长,希望读者耐心阅读. 以下内容会分为如下部分: 1.涵义 1.1:th ...
- .NET读取Office文件内容(word、excel、ppt)
引用命名空间 using Microsoft.Office.Core; using Word = Microsoft.Office.Interop.Word; using Excel = Micros ...
- CSS中一些不经意的细节问题1
CSS这样的语法,细节问题非常多,往往一些难以处理的问题,有可能是一些细节问题不到位,所以先记下一些,留给以后自己看看. 1.line-height:150%与line-height:1.5 的区别 ...
- atitit.自适应设计悬浮图片的大小and 位置
atitit.自适应设计悬浮图片的大小and 位置 #--------最好使用relate定位.. 中间,图片的大小和位置走能相对table, 没有遮罩左的或者哈面儿文本的问题,要悬浮,使用top:- ...
- shiny server SparkR web展示界面(一)
1. shiny server简介 shiny-server是一种可用把R 语言以web形式展示的服务,下面就讲讲如何在自己的服务器上构建Shiny Server.下一篇主要介绍如何集成sparkR后 ...
- JavaScript-分支语句与函数
一.分支语句-if语句 四种if语句: 1.if(判断条件) { 满足条件时需执行的语句 } 2.if(判断条件) { 满足条件时需执行的语句 } else { 不满足条件时需执行的语句 } 3.if ...
- untiy数据包的输出、加载和卸载
1:untiy数据包的输出: BuildPipeline.BuildAssetBundle将任意类型的资源打包成AssetsBundle文件. BuildPipeline.BuildAssetBund ...
- 关于C++单件模式释放对象
http://blog.csdn.net/windboyzsj/article/details/2790485 最近接触的一个项目要用到单件模式,我像往常一样哒哒(敲击键盘ing)一个单件模式的典型结 ...
- iOS:如何通过UIEdgeInsetsMake来制作可伸缩的Button
注:本文翻译自国外iOS开发者Natasha The Robot的一篇博文,链接在此.在iOS应用中,经常会有很多Button有相同的背景图片,却由于处在不同的位置而大小不同(尽管在iOS7中Butt ...