精确计算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
随机推荐
- java5 Lock用法
锁是控制多个线程对共享资源进行访问的工具.通常,锁提供了对共享资源的独占访问.一次只能有一个线程获得锁,对共享资源的所有访问都需要首先获得锁.不过,某些锁可能允许对共享资源并发访问,如 ReadWri ...
- 地理围栏算法解析(Geo-fencing)
地理围栏算法解析 http://www.cnblogs.com/LBSer/p/4471742.html 地理围栏(Geo-fencing)是LBS的一种应用,就是用一个虚拟的栅栏围出一个虚拟地理边界 ...
- paip.语义分析--单字词形容词表180个
paip.语义分析--单字词形容词表180个 INSERT INTO t (word) SELECT DISTINCT word FROM `word_main` where tsisin is ...
- atitit.web 推送实现方案集合
atitit.web 推送实现方案集合 1. 俩中模式 Push/Pull 1 2. 需要实现的特性 2 2.1. 推送消息广播. 2 2.2. 推送定向消息. 2 2.3. 提供连接上线前.上线.下 ...
- bzoj 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...
- VC多线程的用法
.h 文件 #define WM_TEST WM_USER + 1 class CTestThread : public CWinThread { DECLARE_DYNCREATE(CTest ...
- 小白学数据分析----->ARPPU的误区
新年到来,该应该持续坚持写下去,还是有很多人要来学习和进步的. 今天提到了一个概念:ARPPU. 这个概念等同于之前大家认识的ARPU(其实这句话我是很不愿意说的),ARPPU是总收入除以总付费用户数 ...
- 如何在maven项目的pom.xml文件中添加jar包
在使用maven进行项目开发时,我们需要在pom.xml文件中添加自己所需要的jar包.这就要求我们获取jar包的groupId和artifactId. 我们可以在一些maven仓库上搜索我们所需要的 ...
- linux-impdp的使用
数据库是在linux服务器上,需要用impdp方式导入一个dmp,用root用户登录该数据库服务器后,直接采用impdp命令执行导入操作,提示:KSH:impdp:not found.经查原来是操作的 ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...