show the difference between two versions for a specified path
[tfs.git] / class / Microsoft.TeamFoundation.VersionControl.Client / WorkspaceInfo.cs
blob407c2eb90a0e32c38a74c5e98629f87bf9918030
1 //
2 // Microsoft.TeamFoundation.VersionControl.Client.WorkspaceInfo
3 //
4 // Authors:
5 // Joel Reed (joelwreed@gmail.com)
6 //
7 // Copyright (C) 2007 Joel Reed
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.Generic;
31 using System.Net;
32 using System.Text;
33 using System.Xml;
34 using System.Web.Services;
35 using Microsoft.TeamFoundation.Client;
37 namespace Microsoft.TeamFoundation.VersionControl.Client
39 public sealed class WorkspaceInfo
41 private string comment;
42 private string computer;
43 private string displayName;
44 private string name;
45 private string ownerName;
46 private string[] mappedPaths;
47 private InternalServerInfo server;
49 internal WorkspaceInfo(InternalServerInfo server)
51 this.server = server;
54 internal WorkspaceInfo(InternalServerInfo server, Workspace workspace)
56 this.server = server;
57 comment = workspace.Comment;
58 computer = workspace.Computer;
59 name = workspace.Name;
60 ownerName = workspace.OwnerName;
62 List<string> paths = new List<string>();
63 foreach (WorkingFolder folder in workspace.Folders)
65 paths.Add(folder.LocalItem);
68 mappedPaths = paths.ToArray();
71 internal XmlElement ToXml(XmlDocument doc)
73 XmlElement xmlElement = doc.CreateElement("WorkspaceInfo");
75 xmlElement.SetAttributeNode("name", "").Value = Name;
76 xmlElement.SetAttributeNode("ownerName", "").Value = OwnerName;
77 xmlElement.SetAttributeNode("computer", "").Value = Computer;
78 xmlElement.SetAttributeNode("comment", "").Value = Comment;
79 xmlElement.SetAttributeNode("LastSavedCheckinTimeStamp", "").Value = DateTime.Now.ToString();
81 XmlElement mpaths = doc.CreateElement("MappedPaths");
82 xmlElement.AppendChild(mpaths);
84 foreach (string path in mappedPaths)
86 XmlElement pathElement = doc.CreateElement("MappedPath");
87 mpaths.AppendChild(pathElement);
88 pathElement.SetAttributeNode("path", "").Value = path;
91 return xmlElement;
94 internal static WorkspaceInfo FromXml(InternalServerInfo server, XmlReader reader)
96 string elementName = reader.Name;
97 WorkspaceInfo info = new WorkspaceInfo(server);
99 info.name = reader.GetAttribute("name");
100 info.ownerName = reader.GetAttribute("ownerName");
101 info.computer = reader.GetAttribute("computer");
102 info.comment = reader.GetAttribute("comment");
104 List<string> mappedPaths = new List<string>();
105 while (reader.Read())
107 if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName)
108 break;
110 if (reader.NodeType == XmlNodeType.Element && reader.Name == "MappedPath")
111 mappedPaths.Add(reader.GetAttribute("path"));
114 info.mappedPaths = mappedPaths.ToArray();
115 return info;
118 public Workspace GetWorkspace(TeamFoundationServer tfs)
120 VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));
121 return vcs.GetWorkspace(Name, OwnerName);
124 internal void SaveAsXml(XmlNode parent)
128 public override string ToString()
130 StringBuilder sb = new StringBuilder();
132 sb.Append("WorkspaceInfo instance ");
133 sb.Append(GetHashCode());
135 sb.Append("\n Name: ");
136 sb.Append(Name);
138 sb.Append("\n OwnerName: ");
139 sb.Append(OwnerName);
141 sb.Append("\n Comment: ");
142 sb.Append(Comment);
144 sb.Append("\n Computer: ");
145 sb.Append(Computer);
147 sb.Append("\n ServerUri: ");
148 sb.Append(ServerUri);
150 return sb.ToString();
153 public string Comment
155 get { return comment; }
158 public string Computer
160 get { return computer; }
163 public string[] MappedPaths
165 get { return mappedPaths; }
166 internal set { mappedPaths = value; }
169 public string DisplayName
171 get { return displayName; }
174 public string Name
176 get { return name; }
179 public string OwnerName
181 get { return ownerName; }
184 public Uri ServerUri
186 get { return server.Uri; }
189 internal InternalServerInfo Server
191 get { return server; }