<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中新增以及更改的代码行数的更多相关文章

  1. python3 计算文件夹中所有py文件里面代码行数,注释行数,空行数

    import os,re #代码所在位置 FILE_PATH = './' def analyze_code(codefilesource): ''' 打开一个py文件统计其中的代码行数,包括空格和注 ...

  2. VS2015 中统计整个项目的代码行数

    在一个大工程中有很多的源文件和头文件,我如何快速统计总行数? ------解决方案--------------------b*[^:b#/]+.*$^b*[^:b#/]+.*$ ctrl + shif ...

  3. Python计算一个项目中含有的代码行数

    最近想要知道以前做过的project有多少行代码,因为文件太多,直接手工数效率太低,于是编写一个python程序用来计算一个project有多少代码行. 首先,在一个项目中,有很多子文件夹,子文件夹中 ...

  4. 计算代码行数Demo源码

    源码下载:04-计算代码行数.zip24.1 KB////  main.m//  计算代码行数////  Created by apple on 13-8-12.//技术博客http://www.cn ...

  5. 【原】Mac下统计任意文件夹中代码行数的工具——cloc

    这里介绍一个Mac系统统计代码行数的工具cloc. 1.首先,安装homebrew,已安装的请跳过. 打开终端工具Terminal,输入下列命令.过程中会让你按RETURN键以及输入mac桌面密码,按 ...

  6. php 计算代码行数

    <?php header("Content-type:text/html;charset=utf-8"); // php 递归计算文件夹代码行数 function codeL ...

  7. 【未解决】对于使用Windows的IDEA进行编译的文件,但无法在Linux系统中统计代码行数的疑问

    在我学习使用Windows的IDEA的过程中,将代码文件转移到Linux虚拟机当中,但无法在Linux系统中统计代码行数. 注意:拷贝进虚拟机的文件均能编译运行. 具体过程如下: root@yogil ...

  8. 使用vs的查找功能,简单大概的统计vs中的代码行数

    VS强大的查找功能,可以使用正则表达式来进行查找,这里统计代码行数的原理就是: 在所有指定文件中进行搜索,统计匹配的文本行数. 但是匹配的行需要满足:非注释.非空等特殊非代码行. 使用Ctrl+Shi ...

  9. 【原】Mac下统计任意文件夹中代码行数的工

    [链接][原]Mac下统计任意文件夹中代码行数的工http://www.cnblogs.com/wengzilin/p/4580646.html

随机推荐

  1. Spring-MVC接收request参数和向页面传值总结

    接收请求参数值,三种方式: 1使用HttpServletRequest获取 2使用@RequestParam注解 3使用自动封装机制封装成bean对象 向页面传值 1直接使用HttpServletRe ...

  2. lucene索引文件大小优化小结

    http://www.cnblogs.com/LBSer/p/4068864.html 随着业务快速发展,基于lucene的索引文件zip压缩后也接近了GB量级,而保持索引文件大小为一个可以接受的范围 ...

  3. Java-认识字符集-转载

    问题起源 对于计算机而言,它仅认识两个0和1,不管是在内存中还是外部存储设备上,我们所看到的文字.图片.视频等等“数据”在计算机中都是已二进制形式存在的.不同字符对应二进制数的规则,就是字符的编码.字 ...

  4. MySQL 存储过程 定时任务

    drop procedure if exists move_track_data; delimiter // create procedure move_track_data() begin ; st ...

  5. atitit.web原理 理论attilax总结

    atitit.web原理 理论attilax总结 1. Web3.01 2. Web的未来趋势1 3. Web语言与应用导论_百度百科.html2 4. <Web设计与编程导论(影印版)> ...

  6. paip. 内存占用少的php ide选择评测总结

    paip. 内存占用少的php ide选择评测总结 php ide主要以内存占用为标准进行评测.. 其次以软件体积为标准.. 作者Attilax  艾龙,  EMAIL:1466519819@qq.c ...

  7. paip.提升用户体验--提升java的热部署热更新能力

    paip.提升用户体验--提升java的热部署热更新能力 想让java做到php那么好的热部署能力  "fix online"/在线修复吗??直接在服务器上修改源码生效,无需重启应 ...

  8. asp.net 读取RedisSessionStateProvider配置

    最近项目遇到需要读取RedisSessionStateProvider配置文件applicationName节点,如: 读取的方法有很多: 1直接读取web.config文件, void test1( ...

  9. Java中long和Long有什么区别 (转载)

    “Long is a class. long is a primitive. That means Long can be null, where long can't. Long can go an ...

  10. SimpleTemplate模板引擎开发

    模板引擎相信大家是经常使用的,但是实现原理估计没多少人知道(你要是说不就是replace嘛,那我也无话说了...). 先来看看这个SimpleTemplate想实现的是什么功能吧: 是个C#端的模板引 ...