1         /// <summary>
 2         /// 获取工作目录的所有节点,包括子目录
 3         /// </summary>
 4         /// <param name="workingCopyDir"></param>
 5         /// <returns></returns>
 6         public List<LocalNode> FetchWorkingCopy(string workingCopyDir)
 7         {
 8             var nodes = new List<LocalNode>();
 9             var workingRoot = SvnClient.GetWorkingCopyRoot(workingCopyDir);
10             if (workingRoot == null)
11             {
12                 FetchNotVersionedDir(workingCopyDir, nodes);
13             }
14             else
15             {
16                 FetchWorkingCopyDir(workingCopyDir, nodes);
17             }
18             PrintLocalNodes(nodes);
19             return nodes;
20         }
View Code
 1         private void FetchWorkingCopyDir(string path, List<LocalNode> nodes)
 2         {
 3             var statusArgs = new SvnStatusArgs
 4             {
 5                 Depth = SvnDepth.Children,
 6                 RetrieveAllEntries = true,
 7                 ThrowOnError = false
 8             };
 9             Collection<SvnStatusEventArgs> list;
10             if (!SvnClient.GetStatus(path, statusArgs, out list))
11                 return;
12             for (var i = 1; i < list.Count; i++)
13             {
14                 var argse = list[i];
15                 if (argse.Versioned)
16                 {
17                     nodes.Add(new LocalNode { FullPath = argse.FullPath, NodeKind = argse.NodeKind, NodeStatus = argse.LocalNodeStatus });
18                     if (argse.NodeKind == SvnNodeKind.Directory)
19                         FetchWorkingCopyDir(argse.FullPath, nodes);
20                 }
21                 else
22                 {
23                     var nodeKind = File.Exists(argse.FullPath) ? SvnNodeKind.File : SvnNodeKind.Directory;
24                     nodes.Add(new LocalNode { FullPath = argse.FullPath, NodeKind = nodeKind, NodeStatus = argse.LocalNodeStatus });
25                     if (nodeKind == SvnNodeKind.Directory)
26                         FetchNotVersionedDir(argse.FullPath, nodes);
27                 }
28             }
29         }
30 
31         private void FetchNotVersionedDir(string path, List<LocalNode> nodes)
32         {
33             var files = Directory.GetFiles(path);
34             nodes.AddRange(files.Select(file => new LocalNode { FullPath = file, NodeKind = SvnNodeKind.File, NodeStatus = SvnStatus.NotVersioned }));
35             var dirs = Directory.GetDirectories(path);
36             foreach (var dir in dirs)
37             {
38                 nodes.Add(new LocalNode { FullPath = dir, NodeKind = SvnNodeKind.Directory, NodeStatus = SvnStatus.NotVersioned });
39                 FetchNotVersionedDir(dir, nodes);
40             }
41         }
View Code
1     public class LocalNode
2     {
3         public string FullPath { get; set; }
4         public SvnNodeKind NodeKind { get; set; }
5         public SvnStatus NodeStatus { get; set; }
6     }

 

posted on 2017-04-19 14:55  油纸伞  阅读(283)  评论(0编辑  收藏  举报