2 using System
.Globalization
;
5 using Microsoft
.TeamFoundation
;
6 using Microsoft
.TeamFoundation
.Client
;
7 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
8 using Microsoft
.TeamFoundation
.VersionControl
.Common
;
14 static void Main(string[] args
)
16 // Check and get the arguments.
18 RecursionType recursion
;
19 VersionControlServer sourceControl
;
20 GetPathAndRecursion(args
, out path
, out recursion
, out sourceControl
);
25 // Get the latest version of the information for the items.
26 Console
.WriteLine("path is {0}", path
);
27 ItemSet itemSet
= sourceControl
.GetItems(path
, recursion
);
28 items
= itemSet
.Items
;
30 catch (TeamFoundationServerException e
)
32 // We couldn't contact the server, the item wasn't found,
33 // or there was some other problem reported by the server,
35 Console
.Error
.WriteLine("Exception: {0}", e
.Message
);
39 if (items
.Length
== 0)
41 Console
.WriteLine("There are no items for " + path
);
45 Array
.Sort(items
, Item
.Comparer
);
48 int numFiles
= 0, numFolders
= 0;
49 String format
= "{0,-25} {1,-8} {2, 8} {3}";
50 foreach (Item item
in items
)
52 if (item
.ItemType
== ItemType
.File
)
54 // In addition to the information printed, the Item object has
55 // the changeset version and MD5 hash of the file content as
56 // properties on item.
58 totalBytes
+= item
.ContentLength
;
59 Console
.WriteLine(format
,
60 item
.CheckinDate
.ToLocalTime().ToString("G"),
68 Console
.WriteLine(format
,
69 item
.CheckinDate
.ToLocalTime().ToString("G"),
77 Console
.WriteLine("{0} files, {1} folders, {2} bytes",
78 numFiles
, numFolders
, totalBytes
);
82 private static void GetPathAndRecursion(String
[] args
,
83 out String path
, out RecursionType recursion
,
84 out VersionControlServer sourceControl
)
88 Console
.WriteLine("Usage: dirsize <domain username password>");
92 // Figure out the server based on either the argument or the
94 WorkspaceInfo wsInfo
= null;
95 path
= Environment
.CurrentDirectory
;
99 wsInfo
= Workstation
.Current
.GetLocalWorkspaceInfo(Environment
.CurrentDirectory
);
102 // Stop if we couldn't figure out the server.
105 Console
.Error
.WriteLine("Unable to determine the server.");
109 Console
.WriteLine("Server: {0}", wsInfo
.ServerUri
.AbsoluteUri
);
111 TeamFoundationServer tfs
= new TeamFoundationServer(wsInfo
.ServerUri
.AbsoluteUri
,
112 new NetworkCredential(args
[1], args
[2], args
[0]));
114 sourceControl
= (VersionControlServer
)tfs
.GetService(typeof(VersionControlServer
));
116 // Pick up the recursion, if supplied. By default,
117 // we want item and its immediate children, if it is a folder.
118 // If the item is a file, then only the file will be returned.
119 recursion
= RecursionType
.OneLevel
;
120 if (args
.Length
== 1 && args
[0] == "/r" ||
121 args
.Length
== 2 && args
[1] == "/r")
123 recursion
= RecursionType
.Full
;