show the difference between two versions for a specified path
[tfs.git] / tools / opentf / ShowCommand.cs
blobf201a120a63a13824e71784d0e57de403579974b
1 //
2 // ShowCommand.cs
3 //
4 // Authors:
5 // Joel Reed (joelwreed@gmail.com)
6 //
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System;
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.IO;
33 using System.Text;
34 using System.Net;
35 using Microsoft.TeamFoundation.Server;
36 using Microsoft.TeamFoundation.Client;
37 using Microsoft.TeamFoundation.VersionControl.Common;
38 using Microsoft.TeamFoundation.VersionControl.Client;
39 using System.Web.Services;
40 using System.Web.Services.Description;
41 using System.Web.Services.Discovery;
42 using System.Web.Services.Protocols;
43 using Mono.GetOptions;
45 [System.Web.Services.WebServiceBinding(Name="AdminSoap", Namespace="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/Admin/03")]
46 public class AdminStats : System.Web.Services.Protocols.SoapHttpClientProtocol {
48 public AdminStats(string url, ICredentials credentials)
50 this.Url = url + "/VersionControl/v1.0/administration.asmx";
51 this.Credentials = credentials;
54 [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/Admin/03/QueryRepositoryInformation", RequestNamespace="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/Admin/03", ResponseNamespace="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/Admin/03", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
55 public AdminRepositoryInfo QueryRepositoryInformation()
57 object[] results = this.Invoke("QueryRepositoryInformation", new object[0]);
58 return ((AdminRepositoryInfo)(results[0]));
62 [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/Admin/03")]
63 public class AdminRepositoryInfo {
65 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
66 public int UserCount;
68 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
69 public int GroupCount;
71 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
72 public int WorkspaceCount;
74 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
75 public int ShelvesetCount;
77 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
78 public int FileCount;
80 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
81 public int FolderCount;
83 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
84 public int MaxChangesetID;
86 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
87 public int PendingChangeCount;
89 [System.Xml.Serialization.XmlAttributeAttribute(Namespace="")]
90 public int ShelvesetDeletedCount;
93 [Command("show", "Show information about build configuration, cache settings, identity info, usage statistics, or registered tools.", "[ build | cache | ident | stats | tools ]")]
94 class ShowCommand : Command
96 public ShowCommand(Driver driver, string[] args): base(driver, args)
100 public void ShowStats()
102 string url = Driver.GetServerUrl();
103 AdminStats stats = new AdminStats(url, Driver.GetCredentials(new Uri(url), null));
104 AdminRepositoryInfo info = stats.QueryRepositoryInformation();
106 Console.WriteLine("Files: " + info.FileCount);
107 Console.WriteLine("Folders: " + info.FolderCount);
108 Console.WriteLine("Groups: " + info.GroupCount);
109 Console.WriteLine("Pending Changes: " + info.PendingChangeCount);
110 Console.WriteLine("Shelvesets: " + info.ShelvesetCount);
111 Console.WriteLine("Users: " + info.UserCount);
112 Console.WriteLine("Workspaces: " + info.WorkspaceCount);
115 public class ProjectInfoComparer: IComparer<ProjectInfo>
117 public int Compare(ProjectInfo x, ProjectInfo y)
119 return x.Name.CompareTo(y.Name);
123 public void ShowProjects()
125 ICommonStructureService css = Driver.TeamFoundationServer.GetService(typeof(ICommonStructureService)) as ICommonStructureService;
126 ProjectInfo[] projects = css.ListProjects();
127 Array.Sort(projects, new ProjectInfoComparer());
129 int GUID_SIZE = 36;
130 int maxName = WindowWidth - GUID_SIZE - 2;
131 string line = String.Format("{0} {1}",
132 "Guid".PadRight(GUID_SIZE),
133 "Name".PadRight(maxName));
134 Console.WriteLine(line);
136 line = String.Format("{0} {1}",
137 "-".PadRight(GUID_SIZE, '-'),
138 "-".PadRight(maxName, '-'));
140 Console.WriteLine(line);
142 foreach (ProjectInfo pinfo in (projects))
144 int indx = Math.Max(pinfo.Uri.LastIndexOf('/') + 1, 0);
145 string guid = pinfo.Uri.Substring(indx);
146 Console.WriteLine(guid + " " + pinfo.Name);
150 public void ShowTools()
152 RegistrationEntry[] registrationEntries = ((IRegistration) Driver.TeamFoundationServer.GetService(typeof(IRegistration))).GetRegistrationEntries("");
153 foreach (RegistrationEntry entry in registrationEntries)
155 Console.WriteLine(entry.Type);
156 Console.WriteLine(new String('-', WindowWidth));
158 if (entry.ArtifactTypes.Length > 0)
160 Console.WriteLine();
161 Console.WriteLine("ArtifactTypes: ");
162 Console.WriteLine();
163 foreach (ArtifactType artifactType in entry.ArtifactTypes)
165 Console.WriteLine(" {0}", artifactType.Name);
166 foreach (OutboundLinkType outboundLinkType in artifactType.OutboundLinkTypes)
168 Console.WriteLine(" {0}: {1} {2}", outboundLinkType.Name,
169 outboundLinkType.TargetArtifactTypeName,
170 outboundLinkType.TargetArtifactTypeTool);
175 if (entry.Databases.Length > 0)
177 Console.WriteLine();
178 Console.WriteLine("Databases: ");
179 Console.WriteLine();
180 foreach (Database database in entry.Databases)
182 Console.WriteLine(" {0}: {1} on {2}", database.Name, database.DatabaseName, database.SQLServerName);
186 Console.WriteLine();
187 Console.WriteLine("ServiceInterfaces: ");
188 Console.WriteLine();
190 foreach (ServiceInterface serviceInterface in entry.ServiceInterfaces)
192 Console.WriteLine(" {0}: {1}", serviceInterface.Name, serviceInterface.Url);
195 Console.WriteLine();
199 private void ShowCache()
201 Console.WriteLine("Cached Workspaces");
203 string cpath = Path.Combine(TeamFoundationServer.ClientSettingsDirectory, "VersionControl.config");
204 Console.WriteLine("File: " + cpath);
205 Console.WriteLine();
207 WorkspaceInfo[] infos = Workstation.Current.GetAllLocalWorkspaceInfo();
208 foreach (WorkspaceInfo info in infos)
210 Console.WriteLine("Name: " + info.Name);
211 Console.WriteLine("Uri : " + info.ServerUri.ToString());
212 Console.WriteLine();
214 foreach (string path in info.MappedPaths)
216 Console.WriteLine(" Path: " + path);
219 Console.WriteLine();
223 public void ShowBuild()
225 bool magic = false;
226 #if HAVE_MAGIC
227 magic = true;
228 #endif
229 Console.WriteLine("File Type Support: {0}", magic);
231 bool keyring = false;
232 #if HAVE_GNOME_KEYRING
233 keyring = true;
234 #endif
235 Console.WriteLine("Gnome Keyring Support: {0}", keyring);
237 bool gui = false;
238 #if HAVE_GTK
239 gui = true;
240 #endif
241 Console.WriteLine("GUI Support: {0}", gui);
243 bool highlight = false;
244 #if HAVE_SYNTAX_HIGHLIGHTING
245 highlight = true;
246 #endif
247 Console.WriteLine("Syntax Highlighting: {0}", highlight);
250 public void ShowIdentity()
252 IGroupSecurityService gss = Driver.TeamFoundationServer.GetService(typeof(IGroupSecurityService)) as IGroupSecurityService;
253 Identity identity = gss.ReadIdentity(SearchFactor.AccountName, Driver.Username, QueryMembership.Direct);
254 Console.WriteLine("Account Name: " + identity.AccountName);
255 Console.WriteLine("Description: " + identity.Description);
256 Console.WriteLine("DisplayName: " + identity.DisplayName);
257 Console.WriteLine("Distinguished Name: " + identity.DistinguishedName);
258 Console.WriteLine("Domain: " + identity.Domain);
259 Console.WriteLine("Mail Address: " + identity.MailAddress);
260 Console.WriteLine("Sid: " + identity.Sid);
261 Console.WriteLine("Type: " + identity.Type);
264 public override void Run()
266 if (Arguments.Length < 1)
268 Console.WriteLine("Usage: tf show [ build | cache | ident | stats | tools ]");
269 Environment.Exit((int)ExitCode.Failure);
272 switch (Arguments[0])
274 case "build":
275 ShowBuild();
276 break;
277 case "cache":
278 ShowCache();
279 break;
280 case "ident":
281 ShowIdentity();
282 break;
283 case "projects":
284 ShowProjects();
285 break;
286 case "stats":
287 ShowStats();
288 break;
289 case "tools":
290 ShowTools();
291 break;
292 default:
293 Console.WriteLine("Unknown show option: '{0}'", Arguments[0]);
294 break;