Implement basic label command
[tfs.git] / class / Microsoft.TeamFoundation.VersionControl.Client / VersionControlServer.cs
blob5848954f3027505bf17d6002b1547eea11a3642d
1 //
2 // Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer
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.Net;
34 using System.Xml;
35 using System.Web.Services;
36 using Microsoft.TeamFoundation.VersionControl.Common;
38 namespace Microsoft.TeamFoundation.VersionControl.Client
40 public sealed class VersionControlServer
42 private Repository repository;
43 private string authenticatedUser;
44 internal Uri uri;
46 public event ExceptionEventHandler NonFatalError;
47 public event GettingEventHandler Getting;
48 public event ProcessingChangeEventHandler BeforeCheckinPendingChange;
49 public event PendingChangeEventHandler NewPendingChange;
50 public event ConflictEventHandler Conflict;
52 //internal event FileTransferEventHandler Uploading;
54 public VersionControlServer(Uri uri, ICredentials credentials)
56 this.uri = uri;
57 this.repository = new Repository(this, uri, credentials);
59 if (credentials != null)
60 this.authenticatedUser = credentials.GetCredential(uri, "").UserName;
63 public LabelResult[] CreateLabel (VersionControlLabel label,
64 LabelItemSpec[] labelSpecs,
65 LabelChildOption childOption)
67 Workspace workspace = GetWorkspace(labelSpecs[0].ItemSpec.Item);
68 return repository.LabelItem(workspace, label, labelSpecs, childOption);
71 public Workspace CreateWorkspace(string name, string owner)
73 return CreateWorkspace(name, owner, null, new WorkingFolder[0], Environment.MachineName);
76 public Workspace CreateWorkspace(string name, string owner, string comment,
77 WorkingFolder[] folders, string computer)
79 Workspace w1 = new Workspace(this, name, owner, comment, folders, computer);
80 Workspace w2 = repository.CreateWorkspace(w1);
81 Workstation.Current.AddCachedWorkspaceInfo(ServerGuid, Uri, w2);
82 return w2;
85 public void DeleteWorkspace(string workspaceName, string workspaceOwner)
87 repository.DeleteWorkspace(workspaceName, workspaceOwner);
88 Workstation.Current.RemoveCachedWorkspaceInfo(Uri, workspaceName);
91 public Changeset GetChangeset (int changesetId)
93 return GetChangeset(changesetId, false, false);
96 public Changeset GetChangeset (int changesetId, bool includeChanges,
97 bool includeDownloadInfo)
99 return repository.QueryChangeset(changesetId, includeChanges, includeDownloadInfo);
102 public Item GetItem(int id, int changeSet)
104 return GetItem(id, changeSet, false);
107 public Item GetItem(int id, int changeSet, bool includeDownloadInfo)
109 int[] ids = new int[1];
110 ids[0] = id;
112 Item[] items = GetItems(ids, changeSet, includeDownloadInfo);
113 if (items.Length > 0) return items[0];
114 return null;
117 public Item[] GetItems(int[] ids, int changeSet)
119 return GetItems(ids, changeSet, false);
122 public Item[] GetItems(int[] ids, int changeSet, bool includeDownloadInfo)
124 return repository.QueryItemsById(ids, changeSet, includeDownloadInfo);
127 public ItemSet GetItems(string path, RecursionType recursionType)
129 ItemSpec itemSpec = new ItemSpec(path, recursionType);
130 LatestVersionSpec versionSpec = new LatestVersionSpec();
132 return GetItems(itemSpec, versionSpec, DeletedState.NonDeleted,
133 ItemType.Any, false);
136 public ItemSet GetItems(string path, VersionSpec versionSpec,
137 RecursionType recursionType)
139 ItemSpec itemSpec = new ItemSpec(path, recursionType);
140 return GetItems(itemSpec, versionSpec, DeletedState.NonDeleted,
141 ItemType.Any, false);
144 public ItemSet GetItems(ItemSpec itemSpec, VersionSpec versionSpec,
145 DeletedState deletedState, ItemType itemType,
146 bool includeDownloadInfo)
148 string workspaceName = String.Empty;
149 string workspaceOwner = String.Empty;
151 if (!VersionControlPath.IsServerItem(itemSpec.Item))
153 WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(itemSpec.Item);
154 if (info != null)
156 workspaceName = info.Name;
157 workspaceOwner = info.OwnerName;
161 return repository.QueryItems(workspaceName, workspaceOwner,
162 itemSpec, versionSpec, deletedState,
163 itemType, includeDownloadInfo);
166 public Workspace GetWorkspace(string localPath)
168 string path = Path.GetFullPath(localPath);
170 WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(path);
171 if (info == null) throw new ItemNotMappedException(path);
173 return new Workspace(this, info.Name, info.OwnerName,
174 info.Comment, new WorkingFolder[0], Workstation.Current.Name);
177 public Workspace GetWorkspace(string workspaceName, string workspaceOwner)
179 return repository.QueryWorkspace(workspaceName, workspaceOwner);
182 public IEnumerable QueryHistory (string path, VersionSpec version,
183 int deletionId, RecursionType recursion,
184 string user, VersionSpec versionFrom,
185 VersionSpec versionTo, int maxCount,
186 bool includeChanges, bool slotMode)
188 return QueryHistory(path, version, deletionId, recursion,
189 user, versionFrom, versionTo, maxCount,
190 includeChanges, slotMode, false);
193 public IEnumerable QueryHistory (string path, VersionSpec version,
194 int deletionId, RecursionType recursion,
195 string user, VersionSpec versionFrom,
196 VersionSpec versionTo, int maxCount,
197 bool includeChanges, bool slotMode,
198 bool includeDownloadInfo)
200 ItemSpec itemSpec = new ItemSpec(path, recursion, deletionId);
202 string workspaceName = String.Empty;
203 string workspaceOwner = String.Empty;
205 if (!VersionControlPath.IsServerItem(itemSpec.Item))
207 WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(itemSpec.Item);
208 if (info != null)
210 workspaceName = info.Name;
211 workspaceOwner = info.OwnerName;
215 return repository.QueryHistory(workspaceName, workspaceOwner,
216 itemSpec, version,
217 user, versionFrom, versionTo, maxCount,
218 includeChanges, slotMode, includeDownloadInfo);
221 public Workspace GetWorkspace(WorkspaceInfo workspaceInfo)
223 if (workspaceInfo == null)
224 throw new ArgumentNullException("workspaceInfo");
226 return new Workspace(this, workspaceInfo.Name, workspaceInfo.OwnerName,
227 workspaceInfo.Comment, new WorkingFolder[0], workspaceInfo.Computer);
230 public VersionControlLabel[] QueryLabels(string labelName, string labelScope,
231 string owner, bool includeItems)
233 return repository.QueryLabels(null, null, labelName, labelScope, owner, null,
234 VersionSpec.Latest, includeItems, false);
237 public VersionControlLabel[] QueryLabels(string labelName, string labelScope,
238 string owner, bool includeItems,
239 string filterItem, VersionSpec versionFilterItem)
241 return repository.QueryLabels(null, null, labelName, labelScope, owner, filterItem,
242 versionFilterItem, includeItems, false);
245 public VersionControlLabel[] QueryLabels(string labelName, string labelScope,
246 string owner, bool includeItems,
247 string filterItem, VersionSpec versionFilterItem,
248 bool generateDownloadUrls)
250 return repository.QueryLabels(null, null, labelName, labelScope, owner, filterItem,
251 versionFilterItem, includeItems, generateDownloadUrls);
254 public ItemSecurity[] GetPermissions(string[] items, RecursionType recursion)
256 return GetPermissions(null, items, recursion);
259 public ItemSecurity[] GetPermissions(string[] identityNames, string[] items,
260 RecursionType recursion)
262 return Repository.QueryItemPermissions(identityNames, items, recursion);
265 public Workspace[] QueryWorkspaces(string workspaceName, string ownerName,
266 string computer)
268 return repository.QueryWorkspaces(workspaceName, ownerName, computer);
271 internal void OnDownloading(GettingEventArgs args)
273 if (null != Getting) Getting(this, args);
276 internal void OnNonFatalError(Workspace workspace, Failure failure)
278 if (null != NonFatalError) NonFatalError(workspace, new ExceptionEventArgs(workspace, failure));
281 internal void OnUploading()
283 //if (null != Uploading) Uploading(null, null);
286 internal void UpdateWorkspaceInfoCache(XmlNode parent, string ownerName,
287 string computer)
289 Workspace[] workspaces = QueryWorkspaces(null, ownerName, computer);
290 InternalServerInfo serverInfo = new InternalServerInfo(Uri.ToString(), ServerGuid, workspaces);
291 XmlElement xmlElement = serverInfo.ToXml(parent.OwnerDocument);
292 parent.AppendChild(xmlElement);
295 public string AuthenticatedUser
297 get { return authenticatedUser; }
300 public Guid ServerGuid
302 get { return new Guid(); }
305 internal Repository Repository
307 get { return repository; }
310 internal Uri Uri
312 get { return uri; }