when parsing changeset and shelveset datetimes don't
[tfs.git] / class / Microsoft.TeamFoundation.VersionControl.Client / Shelveset.cs
blobfe166b798a7d6aef08616effadd45354b6bad6e6
1 //
2 // Microsoft.TeamFoundation.VersionControl.Client.Shelveset
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;
31 using System.Collections.Generic;
32 using System.Text;
33 using System.Xml;
35 namespace Microsoft.TeamFoundation.VersionControl.Client
37 internal class ShelvesetGenericComparer : IComparer<Shelveset>
39 public static ShelvesetGenericComparer Instance = new ShelvesetGenericComparer();
41 public int Compare(Shelveset x, Shelveset y)
43 int cmp = String.Compare(x.Name, y.Name);
44 if (cmp != 0) return cmp;
45 return String.Compare(x.Name, y.OwnerName);
49 public sealed class Shelveset
51 private string name;
52 private string comment = String.Empty;
53 private string ownerName;
54 private DateTime creationDate = new DateTime(0);
55 private VersionControlServer versionControlServer;
57 public Shelveset (VersionControlServer versionControlServer,
58 string name, string ownerName)
60 this.versionControlServer = versionControlServer;
61 this.name = name;
62 this.ownerName = ownerName;
65 internal static Shelveset FromXml(Repository repository, XmlReader reader)
67 string elementName = reader.Name;
68 string ownerName = reader.GetAttribute("owner");
69 string name = reader.GetAttribute("name");
71 Shelveset shelveset = new Shelveset(repository.VersionControlServer, name, ownerName);
72 shelveset.creationDate = DateTime.ParseExact(reader.GetAttribute("date"), "yyyy-MM-ddTHH:mm:ss.FFFFFFFZ", null);
74 while (reader.Read())
76 if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName)
77 break;
79 if (reader.NodeType == XmlNodeType.Element)
81 switch (reader.Name)
83 case "Comment":
84 shelveset.comment = reader.ReadString();
85 break;
90 return shelveset;
93 internal void ToXml(XmlWriter writer, string element)
95 writer.WriteStartElement(element);
96 writer.WriteAttributeString("date", CreationDate.ToString("s"));
97 writer.WriteAttributeString("name", Name);
98 writer.WriteAttributeString("owner", OwnerName);
99 writer.WriteEndElement();
102 public override string ToString()
104 StringBuilder sb = new StringBuilder();
106 sb.Append("Shelveset instance ");
107 sb.Append(GetHashCode());
109 sb.Append("\n Name: ");
110 sb.Append(Name);
112 sb.Append("\n Comment: ");
113 sb.Append(Comment);
115 sb.Append("\n OwnerName: ");
116 sb.Append(OwnerName);
118 return sb.ToString();
121 public string Name
123 get { return name; }
126 public string Comment
128 get { return comment; }
131 public string OwnerName
133 get { return ownerName; }
136 public DateTime CreationDate
138 get { return creationDate; }
141 public VersionControlServer VersionControlServer
143 get { return versionControlServer; }
146 internal class ShelvesetComparer : IComparer
148 public static ShelvesetComparer Instance = new ShelvesetComparer();
150 public int Compare(object xo, object yo)
152 Shelveset x = xo as Shelveset;
153 Shelveset y = yo as Shelveset;
154 return ShelvesetGenericComparer.Instance.Compare(x, y);
158 public static IComparer NameComparer {
159 get {
160 return ShelvesetComparer.Instance;