show the difference between two versions for a specified path
[tfs.git] / class / Microsoft.TeamFoundation.VersionControl.Client / Shelveset.cs
blob17dbe8ebb7d8a1dcaddbe1e78da1edfa48381199
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.Globalization;
33 using System.Text;
34 using System.Xml;
36 namespace Microsoft.TeamFoundation.VersionControl.Client
38 internal class ShelvesetGenericComparer : IComparer<Shelveset>
40 public static ShelvesetGenericComparer Instance = new ShelvesetGenericComparer();
42 public int Compare(Shelveset x, Shelveset y)
44 int cmp = String.Compare(x.Name, y.Name);
45 if (cmp != 0) return cmp;
46 return String.Compare(x.Name, y.OwnerName);
50 public sealed class Shelveset
52 private static readonly string[] DateTimeFormats = { "yyyy-MM-ddTHH:mm:ss.FFFFFFFZ", "yyyy-MM-ddTHH:mm:ssZ" };
53 private string name;
54 private string comment = String.Empty;
55 private string ownerName;
56 private DateTime creationDate = new DateTime(0);
57 private VersionControlServer versionControlServer;
59 public Shelveset (VersionControlServer versionControlServer,
60 string name, string ownerName)
62 this.versionControlServer = versionControlServer;
63 this.name = name;
64 this.ownerName = ownerName;
67 internal static Shelveset FromXml(Repository repository, XmlReader reader)
69 string elementName = reader.Name;
70 string ownerName = reader.GetAttribute("owner");
71 string name = reader.GetAttribute("name");
73 Shelveset shelveset = new Shelveset(repository.VersionControlServer, name, ownerName);
74 shelveset.creationDate = DateTime.ParseExact(reader.GetAttribute("date"), DateTimeFormats, null, DateTimeStyles.None);
76 while (reader.Read())
78 if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName)
79 break;
81 if (reader.NodeType == XmlNodeType.Element)
83 switch (reader.Name)
85 case "Comment":
86 shelveset.comment = reader.ReadString();
87 break;
92 return shelveset;
95 internal void ToXml(XmlWriter writer, string element)
97 writer.WriteStartElement(element);
98 writer.WriteAttributeString("date", CreationDate.ToString("s"));
99 writer.WriteAttributeString("name", Name);
100 writer.WriteAttributeString("owner", OwnerName);
101 writer.WriteEndElement();
104 public override string ToString()
106 StringBuilder sb = new StringBuilder();
108 sb.Append("Shelveset instance ");
109 sb.Append(GetHashCode());
111 sb.Append("\n Name: ");
112 sb.Append(Name);
114 sb.Append("\n Comment: ");
115 sb.Append(Comment);
117 sb.Append("\n OwnerName: ");
118 sb.Append(OwnerName);
120 return sb.ToString();
123 public string Name
125 get { return name; }
128 public string Comment
130 get { return comment; }
133 public string OwnerName
135 get { return ownerName; }
138 public DateTime CreationDate
140 get { return creationDate; }
143 public VersionControlServer VersionControlServer
145 get { return versionControlServer; }
148 internal class ShelvesetComparer : IComparer
150 public static ShelvesetComparer Instance = new ShelvesetComparer();
152 public int Compare(object xo, object yo)
154 Shelveset x = xo as Shelveset;
155 Shelveset y = yo as Shelveset;
156 return ShelvesetGenericComparer.Instance.Compare(x, y);
160 public static IComparer NameComparer {
161 get {
162 return ShelvesetComparer.Instance;