prep for online patch
[tfs.git] / class / Microsoft.TeamFoundation.VersionControl.Client / VersionControlServer.cs
bloba3e775be372b20f23265b433f89b908abae9d7c9
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 LabelResult[] UnlabelItem (string labelName, string labelScope,
72 ItemSpec[] itemSpecs, VersionSpec version)
74 Workspace workspace = GetWorkspace(itemSpecs[0].Item);
75 return repository.UnlabelItem(workspace, labelName, labelScope,
76 itemSpecs, version);
79 public Workspace CreateWorkspace(string name, string owner)
81 return CreateWorkspace(name, owner, null, new WorkingFolder[0], Environment.MachineName);
84 public Workspace CreateWorkspace(string name, string owner, string comment,
85 WorkingFolder[] folders, string computer)
87 Workspace w1 = new Workspace(this, name, owner, comment, folders, computer);
88 Workspace w2 = repository.CreateWorkspace(w1);
89 Workstation.Current.AddCachedWorkspaceInfo(ServerGuid, Uri, w2);
90 return w2;
93 public void DeleteWorkspace(string workspaceName, string workspaceOwner)
95 repository.DeleteWorkspace(workspaceName, workspaceOwner);
96 Workstation.Current.RemoveCachedWorkspaceInfo(Uri, workspaceName);
99 // public BranchHistoryTreeItem[][] GetBranchHistory (ItemSpec[] itemSpecs,
100 // VersionSpec version)
104 public Changeset GetChangeset (int changesetId)
106 return GetChangeset(changesetId, false, false);
109 public Changeset GetChangeset (int changesetId, bool includeChanges,
110 bool includeDownloadInfo)
112 return repository.QueryChangeset(changesetId, includeChanges, includeDownloadInfo);
115 public Item GetItem(int id, int changeSet)
117 return GetItem(id, changeSet, false);
120 public Item GetItem(int id, int changeSet, bool includeDownloadInfo)
122 int[] ids = new int[1];
123 ids[0] = id;
125 Item[] items = GetItems(ids, changeSet, includeDownloadInfo);
126 if (items.Length > 0) return items[0];
127 return null;
130 public Item[] GetItems(int[] ids, int changeSet)
132 return GetItems(ids, changeSet, false);
135 public Item[] GetItems(int[] ids, int changeSet, bool includeDownloadInfo)
137 return repository.QueryItemsById(ids, changeSet, includeDownloadInfo);
140 public ItemSet GetItems(string path, RecursionType recursionType)
142 ItemSpec itemSpec = new ItemSpec(path, recursionType);
143 LatestVersionSpec versionSpec = new LatestVersionSpec();
145 return GetItems(itemSpec, versionSpec, DeletedState.NonDeleted,
146 ItemType.Any, false);
149 public ItemSet GetItems(string path, VersionSpec versionSpec,
150 RecursionType recursionType)
152 ItemSpec itemSpec = new ItemSpec(path, recursionType);
153 return GetItems(itemSpec, versionSpec, DeletedState.NonDeleted,
154 ItemType.Any, false);
157 public ItemSet GetItems(ItemSpec itemSpec, VersionSpec versionSpec,
158 DeletedState deletedState, ItemType itemType,
159 bool includeDownloadInfo)
161 List<ItemSpec> itemSpecs = new List<ItemSpec>();
162 itemSpecs.Add(itemSpec);
163 return GetItems(itemSpecs.ToArray(), versionSpec, deletedState,
164 itemType, includeDownloadInfo);
167 public ItemSet GetItems(ItemSpec[] itemSpecs, VersionSpec versionSpec,
168 DeletedState deletedState, ItemType itemType,
169 bool includeDownloadInfo)
171 if (itemSpecs.Length == 0) return null;
173 string workspaceName = String.Empty;
174 string workspaceOwner = String.Empty;
176 string item = itemSpecs[0].Item;
177 if (!VersionControlPath.IsServerItem(item))
179 WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(item);
180 if (info != null)
182 workspaceName = info.Name;
183 workspaceOwner = info.OwnerName;
187 return repository.QueryItems(workspaceName, workspaceOwner,
188 itemSpecs, versionSpec, deletedState,
189 itemType, includeDownloadInfo);
192 public Workspace GetWorkspace(string localPath)
194 string path = Path.GetFullPath(localPath);
196 WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(path);
197 if (info == null) throw new ItemNotMappedException(path);
199 return new Workspace(this, info.Name, info.OwnerName,
200 info.Comment, new WorkingFolder[0], Workstation.Current.Name);
203 public Workspace GetWorkspace(string workspaceName, string workspaceOwner)
205 return repository.QueryWorkspace(workspaceName, workspaceOwner);
208 public IEnumerable QueryHistory (string path, VersionSpec version,
209 int deletionId, RecursionType recursion,
210 string user, VersionSpec versionFrom,
211 VersionSpec versionTo, int maxCount,
212 bool includeChanges, bool slotMode)
214 return QueryHistory(path, version, deletionId, recursion,
215 user, versionFrom, versionTo, maxCount,
216 includeChanges, slotMode, false);
219 public IEnumerable QueryHistory (string path, VersionSpec version,
220 int deletionId, RecursionType recursion,
221 string user, VersionSpec versionFrom,
222 VersionSpec versionTo, int maxCount,
223 bool includeChanges, bool slotMode,
224 bool includeDownloadInfo)
226 ItemSpec itemSpec = new ItemSpec(path, recursion, deletionId);
228 string workspaceName = String.Empty;
229 string workspaceOwner = String.Empty;
231 if (!VersionControlPath.IsServerItem(itemSpec.Item))
233 WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(itemSpec.Item);
234 if (info != null)
236 workspaceName = info.Name;
237 workspaceOwner = info.OwnerName;
241 return repository.QueryHistory(workspaceName, workspaceOwner,
242 itemSpec, version,
243 user, versionFrom, versionTo, maxCount,
244 includeChanges, slotMode, includeDownloadInfo);
247 public Workspace GetWorkspace(WorkspaceInfo workspaceInfo)
249 if (workspaceInfo == null)
250 throw new ArgumentNullException("workspaceInfo");
252 return new Workspace(this, workspaceInfo.Name, workspaceInfo.OwnerName,
253 workspaceInfo.Comment, new WorkingFolder[0], workspaceInfo.Computer);
256 public VersionControlLabel[] QueryLabels(string labelName, string labelScope,
257 string owner, bool includeItems)
259 return repository.QueryLabels(null, null, labelName, labelScope, owner, null,
260 VersionSpec.Latest, includeItems, false);
263 public VersionControlLabel[] QueryLabels(string labelName, string labelScope,
264 string owner, bool includeItems,
265 string filterItem, VersionSpec versionFilterItem)
267 return repository.QueryLabels(null, null, labelName, labelScope, owner, filterItem,
268 versionFilterItem, includeItems, false);
271 public VersionControlLabel[] QueryLabels(string labelName, string labelScope,
272 string owner, bool includeItems,
273 string filterItem, VersionSpec versionFilterItem,
274 bool generateDownloadUrls)
276 return repository.QueryLabels(null, null, labelName, labelScope, owner, filterItem,
277 versionFilterItem, includeItems, generateDownloadUrls);
280 public ItemSecurity[] GetPermissions(string[] items, RecursionType recursion)
282 return GetPermissions(null, items, recursion);
285 public ItemSecurity[] GetPermissions(string[] identityNames, string[] items,
286 RecursionType recursion)
288 return Repository.QueryItemPermissions(identityNames, items, recursion);
291 public Workspace[] QueryWorkspaces(string workspaceName, string ownerName,
292 string computer)
294 return repository.QueryWorkspaces(workspaceName, ownerName, computer);
297 internal void OnDownloading(GettingEventArgs args)
299 if (null != Getting) Getting(this, args);
302 internal void OnNonFatalError(Workspace workspace, Failure failure)
304 if (null != NonFatalError) NonFatalError(workspace, new ExceptionEventArgs(workspace, failure));
307 internal void OnUploading()
309 //if (null != Uploading) Uploading(null, null);
312 internal void UpdateWorkspaceInfoCache(XmlNode parent, string ownerName,
313 string computer)
315 Workspace[] workspaces = QueryWorkspaces(null, ownerName, computer);
316 InternalServerInfo serverInfo = new InternalServerInfo(Uri.ToString(), ServerGuid, workspaces);
317 XmlElement xmlElement = serverInfo.ToXml(parent.OwnerDocument);
318 parent.AppendChild(xmlElement);
321 public string AuthenticatedUser
323 get { return authenticatedUser; }
326 public Guid ServerGuid
328 get { return new Guid(); }
331 internal Repository Repository
333 get { return repository; }
336 internal Uri Uri
338 get { return uri; }