精确计算TFS中新增以及更改的代码行数
2013-10-25 17:38
375 查看
<configuration> <configSections> <sectionname="LOCTargets" type="ConsoleApplication2.TFSConfigSection,TFSChangeLOC"/> </configSections> <appSettings> <addkey="OutputFilePath"value="C:\Users\xingy\Desktop\LOCdemo.html"/> </appSettings> <LOCTargets> <addLocalPath="C:\SPA_5150\Apps\IntelligentRewards\dev\source" StartChangeSetId="373171"EndChangeSetId="373173"/> <addLocalPath="C:\SPA_5150\Apps\Framework\source" StartChangeSetId="373165"EndChangeSetId="373170"/> </LOCTargets> <startup> <supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.5"/> </startup> </configuration>
classProgram { staticintaddNumber=0; staticintdelNumber=0; staticinteditNumber=0; staticintotherNumber=0; staticintrenameNumber=0; staticDictionary<int,int>changeSetDic=newDictionary<int,int>(); staticList<string>changedFiles=newList<string>(); staticvoidMain(string[]args) { Configurationconfig=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); TFSConfigSectionsection=config.Sections["LOCTargets"]asTFSConfigSection; foreach(TargetlocTargetinsection.Instances) { TFS(locTarget.LocalPath,locTarget.StartChangeSetId,locTarget.EndChangeSetId); } ScanFiles(); OutputHtmlFile(changeSetDic); Console.WriteLine("PressAnyKeytoExit......"); Console.Read(); } privatestaticvoidTFS(stringlocalPath,stringstartId,stringendId) { UritfsUri=newUri("http://rnotfsat:8080/tfs"); stringtfsPath=null; try { TfsConfigurationServerconfigurationServer= TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); //Getthecatalogofteamprojectcollections ReadOnlyCollection<CatalogNode>collectionNodes=configurationServer.CatalogNode.QueryChildren( new[]{CatalogResourceTypes.ProjectCollection}, false,CatalogQueryOptions.None); //Listtheteamprojectcollections foreach(CatalogNodecollectionNodeincollectionNodes) { //UsetheInstanceIdpropertytogettheteamprojectcollection GuidcollectionId=newGuid(collectionNode.Resource.Properties["InstanceId"]); TfsTeamProjectCollectionteamProjectCollection=configurationServer.GetTeamProjectCollection(collectionId); if(!teamProjectCollection.Name.Equals(@"rnotfsat\rnotfsat")) continue; varvcs=teamProjectCollection.GetService<VersionControlServer>(); varworkSpace=vcs.GetWorkspace(localPath); tfsPath=workSpace.GetServerItemForLocalItem(localPath); varchangesetList=vcs.QueryHistory( tfsPath, VersionSpec.Latest, 0, RecursionType.Full, null, VersionSpec.ParseSingleSpec(startId,null), VersionSpec.ParseSingleSpec(endId,null), Int32.MaxValue, true, false).Cast<Changeset>(); foreach(varcsinchangesetList) { changeSetDic.Add(cs.ChangesetId,0); varchangeList=cs.Changes; foreach(varchangeinchangeList) { if(change.Item!=null) { varlocalFile=workSpace.GetLocalItemForServerItem(change.Item.ServerItem); if(change.ChangeType.HasFlag(ChangeType.Edit)) { if(!changedFiles.Contains(localFile)) { changedFiles.Add(localFile); } editNumber++; } elseif(change.ChangeType.HasFlag(ChangeType.Add)) { if(File.Exists(localFile)) { changeSetDic[cs.ChangesetId]+=File.ReadLines(localFile).Count(); addNumber++; } } elseif(change.ChangeType.HasFlag(ChangeType.Rename)|| change.ChangeType.HasFlag(ChangeType.SourceRename)) { renameNumber++; } elseif(change.ChangeType.HasFlag(ChangeType.Delete)) { delNumber++; } else { otherNumber++; } } } } } } catch(ChangesetNotFoundException) { Console.WriteLine("!!Pleasecheckthechangesetidinsideyourconfigfile!!"); } catch(Exceptione) { Console.WriteLine(e); } } privatestaticvoidScanFiles() { Console.WriteLine("Intotal{0}fileswillbescanned!",changedFiles.Count); Console.WriteLine(); Console.WriteLine(); intleft=changedFiles.Count; foreach(varcsFileinchangedFiles) { GetContent(changeSetDic,csFile); Console.WriteLine(csFile+"isscannedandanalyzed!"); left--; Console.WriteLine("{0}filesleft.",left); } } privatestaticvoidGetContent(Dictionary<int,int>csDic,stringfilePath) { Processproc=newProcess(); proc.StartInfo.FileName="tfpt"; proc.StartInfo.UseShellExecute=false; proc.StartInfo.RedirectStandardOutput=true; proc.StartInfo.Arguments="annotate\""+filePath+"\"/noprompt"; proc.Start(); StringBuildersb=newStringBuilder(); while(!proc.HasExited) { sb.Append(proc.StandardOutput.ReadToEnd()); } stringallResult=sb.ToString(); String[]lines=allResult.Split(new[]{Environment.NewLine},Int32.MaxValue,StringSplitOptions.RemoveEmptyEntries); foreach(varlineinlines) { varcsIdInStr=line.Split(default(string[]),StringSplitOptions.RemoveEmptyEntries); intcsId=Convert.ToInt32(csIdInStr[0]); if(csDic.ContainsKey(csId)) { csDic[csId]++; } } } privatestaticvoidOutputHtmlFile(Dictionary<int,int>csDic) { stringhtmlSource=File.ReadAllText("HTMLTemplate.html"); inttotalCount=0; StringBuildersb=newStringBuilder(); foreach(KeyValuePair<int,int>kvincsDic) { 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); } }
相关文章推荐
- (转)python 计算代码行数以及相关知识点
- 基于BigDecimal的精确计算以及格式化输出代码示例
- 如何计算代码新增行数
- CCS7.2软/硬件断点设置,精确计算代码运行时间及定时器定时时间验证(适用于C28x芯片)
- MacOS 开发 - 计算代码行数
- PyQt5学习随笔01--计算一个目录里我们码的代码行数&&PyQt的多线程通信
- [PHP代码] 计算年龄 精确到天
- 黑马程序员——OCFoundation框架-9:计算某个文件夹下的代码行数
- java精度计算代码 java指定精确小数位
- 计算目录下所有程序文件代码行数
- 根据String以及textView所设定的字体大小来计算所需要行数,实现展开和收起的效果。
- 经典例题——计算代码行数(OC)
- 用MFC实现代码获取当前EXE 执行的绝对路径,用于扩展相对路径扩展,以及计算文件大小功能
- git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需要寻找两个分支最近的分割点,即base.假设git 树是多叉树,请实现一个算法,计算git树上任意两点的最近分割点。 (假设git树节点数为n,用邻接矩阵的形式表示git树:字符串数组matrix包含n个字符串,每个字符串由字符'0
- java精度计算代码,指定精确小数位
- 如何计算C++有效代码行数?
- 计算整个文件夹的代码行数
- JAVA作业—从命令行输入两个参数打开文件并计算代码行数
- 计算iOS Xcode总代码行数
- jquery 精度计算代码,指定精确小数位