2 // Microsoft.TeamFoundation.VersionControl.Client.VersionControlLabel
5 // Joel Reed (joelwreed@gmail.com)
7 // Copyright (C) 2007 Joel Reed
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System
.Collections
.Generic
;
34 using System
.Web
.Services
;
36 namespace Microsoft
.TeamFoundation
.VersionControl
.Client
38 public sealed class VersionControlLabel
40 private string comment
;
43 private System
.DateTime lastModifiedDate
;
46 private string ownerName
;
47 private VersionControlServer versionControlServer
;
49 internal VersionControlLabel()
53 public VersionControlLabel (VersionControlServer versionControlServer
,
54 string name
, string ownerName
, string scope
,
57 this.versionControlServer
= versionControlServer
;
59 this.ownerName
= ownerName
;
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
>();
79 if (reader
.NodeType
== XmlNodeType
.EndElement
&& reader
.Name
== elementName
)
82 if (reader
.NodeType
== XmlNodeType
.Element
)
87 items
.Add(Item
.FromXml(repository
, reader
));
90 label
.comment
= reader
.ReadString();
96 label
.items
= items
.ToArray();
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: ");
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: ");
135 sb
.Append("\n OwnerName: ");
136 sb
.Append(OwnerName
);
138 sb
.Append("\n Scope: ");
141 sb
.Append("\n LabelId: ");
144 return sb
.ToString();
147 public Uri ArtifactUri
150 return new Uri("vstfs:///VersionControl/Label/" + LabelId
);
154 public string Comment
156 get { return comment; }
161 get { return items; }
166 get { return labelId; }
169 public DateTime LastModifiedDate
171 get { return lastModifiedDate; }
179 public string OwnerName
181 get { return ownerName; }
186 get { return scope; }
189 public VersionControlServer VersionControlServer
191 get { return versionControlServer; }