show the difference between two versions for a specified path
[tfs.git] / class / Microsoft.TeamFoundation.VersionControl.Client / VersionControlLabel.cs
blob72d16951b673d0296a4d04909c64600677d2cfb1
1 //
2 // Microsoft.TeamFoundation.VersionControl.Client.VersionControlLabel
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;
36 namespace Microsoft.TeamFoundation.VersionControl.Client
38 public sealed class VersionControlLabel
40 private string comment;
41 private Item[] items;
42 private int labelId;
43 private System.DateTime lastModifiedDate;
44 private string name;
45 private string scope;
46 private string ownerName;
47 private VersionControlServer versionControlServer;
49 internal VersionControlLabel()
53 public VersionControlLabel (VersionControlServer versionControlServer,
54 string name, string ownerName, string scope,
55 string comment)
57 this.versionControlServer = versionControlServer;
58 this.name = name;
59 this.ownerName = ownerName;
60 this.scope = scope;
61 this.comment = comment;
62 this.lastModifiedDate = new DateTime(1);
65 internal static VersionControlLabel FromXml(Repository repository, XmlReader reader)
67 VersionControlLabel label = new VersionControlLabel();
68 string elementName = reader.Name;
70 label.lastModifiedDate = DateTime.Parse(reader.GetAttribute("date"));
71 label.name = reader.GetAttribute("name");
72 label.ownerName = reader.GetAttribute("owner");
73 label.scope = reader.GetAttribute("scope");
74 label.labelId = Convert.ToInt32(reader.GetAttribute("lid"));
76 List<Item> items = new List<Item>();
77 while (reader.Read())
79 if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName)
80 break;
82 if (reader.NodeType == XmlNodeType.Element)
84 switch (reader.Name)
86 case "Item":
87 items.Add(Item.FromXml(repository, reader));
88 break;
89 case "Comment":
90 label.comment = reader.ReadString();
91 break;
96 label.items = items.ToArray();
97 return label;
100 internal void ToXml(XmlWriter writer, string element)
102 writer.WriteStartElement(element);
103 writer.WriteAttributeString("date", LastModifiedDate.ToString("s"));
104 writer.WriteAttributeString("name", Name);
106 if (!String.IsNullOrEmpty(OwnerName)) writer.WriteAttributeString("owner", OwnerName);
107 if (!String.IsNullOrEmpty(Scope)) writer.WriteAttributeString("scope", Scope);
109 writer.WriteAttributeString("lid", LabelId.ToString());
110 writer.WriteEndElement();
113 public override string ToString()
115 StringBuilder sb = new StringBuilder();
117 sb.Append("VersionControlLabel instance ");
118 sb.Append(GetHashCode());
120 sb.Append("\n Comment: ");
121 sb.Append(Comment);
123 sb.Append("\n LastModifiedDate: ");
124 sb.Append(LastModifiedDate);
126 foreach (Item item in items)
128 sb.Append("\n Item: ");
129 sb.Append(item.ToString());
132 sb.Append("\n Name: ");
133 sb.Append(Name);
135 sb.Append("\n OwnerName: ");
136 sb.Append(OwnerName);
138 sb.Append("\n Scope: ");
139 sb.Append(Scope);
141 sb.Append("\n LabelId: ");
142 sb.Append(LabelId);
144 return sb.ToString();
147 public Uri ArtifactUri
149 get {
150 return new Uri("vstfs:///VersionControl/Label/" + LabelId);
154 public string Comment
156 get { return comment; }
159 public Item[] Items
161 get { return items; }
164 public int LabelId
166 get { return labelId; }
169 public DateTime LastModifiedDate
171 get { return lastModifiedDate; }
174 public string Name
176 get { return name; }
179 public string OwnerName
181 get { return ownerName; }
184 public string Scope
186 get { return scope; }
189 public VersionControlServer VersionControlServer
191 get { return versionControlServer; }