<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. 一个格式化日期和时间的JavaScript类库

    原文地址:http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html 结合meizz的代码做了适当调整. Date.pro ...

  2. [BTS] The adapter "SQL" raised an error message. Details "The Messaging Engine is shutting down. ".

    Get a warning in event log. Log Name:      ApplicationSource:        BizTalk ServerDate:          3/ ...

  3. 利用nodejs模块缓存机制创建“全局变量”

    在<深入浅出nodejs>有这样一段(有部分增减): 1.nodejs引入模块分四个步骤 路径分析 文件定位 编译执行 加入内存 2.核心模块部分在node源代码的编译过程中就编译成了二级 ...

  4. iOS开发——高级技术&内购服务

    内购服务 大家都知道做iOS开发本身的收入有三种来源:出售应用.内购和广告.国内用户通常很少直接 购买应用,因此对于开发者而言(特别是个人开发者),内购和广告收入就成了主要的收入来源.内购营销模式,通 ...

  5. 详解Bootstrap列表组组件

    列表组可以用来制作列表清单.垂直导航等效果,也可以配合其他的组件制作出更漂亮的组件,列表组在bootstrap框架中也是一个独立的组件,所以也对应有自己独立源码: LESS:list-group.le ...

  6. 启动Eclipse 弹出“Failed to load the JNI shared library”错误的解决方法

    原因1:eclipse的版本与jre或者jdk版本不一致 对策:要么两者都安装64位的,要么都安两个是32位一个是64位. 原因2:给定目录下jvm.dll不存在 对策:(1)重新安装jre或者jdk ...

  7. android studio logcat 换行(日志换行)

    起因 今天突然要调试网络数据,调试一大截那个xml数据. 解决思路 一开始去setting哪里看一下logcat 是否有line break,类似的字眼,可惜没有. 我猜如果没有在设置的话,估计就在“ ...

  8. [CoreOS 转载] CoreOS实践指南(五):分布式数据存储Etcd(上)

    转载:http://www.csdn.net/article/2015-01-22/2823659 摘要:在“漫步云端:CoreOS实践指南”系列的前几篇,分别介绍了如何架设CoreOS集群,系统服务 ...

  9. Selenium实战脚本集(3)--抓取infoq里的测试新闻

    描述 打开infoq页面,抓取最新的一些测试文章 需要抓取文章的标题和内容 如果你有个人blog的话,可以将这些文章转载到自己的blog 要求 不要在新窗口打开文章 自行了解最新的测试思潮与实践

  10. Android NDK 同时编译多个Module

    LOCAL_PATH := $(call my-dir) ## ## NDK 支持同时编译多个Module: ## 在配置的时候,每个Module需要 以 include $(CLEAR_VARS)开 ...