From a949a505a1d0f65be30e17b473a0a487039e56e0 Mon Sep 17 00:00:00 2001 From: Joel Reed Date: Mon, 30 Jul 2007 22:05:06 -0400 Subject: [PATCH] basic.shelveset.cmd --- ...eamFoundation.VersionControl.Client.dll.sources | 1 + .../Repository.cs | 67 ++++++--- .../Shelveset.cs | 158 +++++++++++++++++++++ .../VersionControlServer.cs | 5 + tools/tf/ShelvesetsCommand.cs | 86 +++++++++++ tools/tf/tf.exe.sources | 1 + 6 files changed, 296 insertions(+), 22 deletions(-) create mode 100644 class/Microsoft.TeamFoundation.VersionControl.Client/Shelveset.cs create mode 100644 tools/tf/ShelvesetsCommand.cs diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/Microsoft.TeamFoundation.VersionControl.Client.dll.sources b/class/Microsoft.TeamFoundation.VersionControl.Client/Microsoft.TeamFoundation.VersionControl.Client.dll.sources index 945a1dd..d1ed938 100644 --- a/class/Microsoft.TeamFoundation.VersionControl.Client/Microsoft.TeamFoundation.VersionControl.Client.dll.sources +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/Microsoft.TeamFoundation.VersionControl.Client.dll.sources @@ -66,6 +66,7 @@ Repository.cs RepositoryProperties.cs RequestType.cs SecurityChange.cs +Shelveset.cs TeamProjectFolderOptions.cs UpdateLocalVersionQueue.cs VersionControlException.cs diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/Repository.cs b/class/Microsoft.TeamFoundation.VersionControl.Client/Repository.cs index 479f00a..6ace51c 100644 --- a/class/Microsoft.TeamFoundation.VersionControl.Client/Repository.cs +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/Repository.cs @@ -476,28 +476,28 @@ namespace Microsoft.TeamFoundation.VersionControl.Client { XmlReader results = msg.ResponseReader(response); while (results.Read()) - { - if (results.NodeType == XmlNodeType.Element && - results.Name == "ArrayOfBranchRelative") - { - List branches = new List(); - while (results.Read()) - { + { + if (results.NodeType == XmlNodeType.Element && + results.Name == "ArrayOfBranchRelative") + { + List branches = new List(); + while (results.Read()) + { if (results.NodeType == XmlNodeType.EndElement && results.Name == "ArrayOfBranchRelative") break; - if (results.NodeType == XmlNodeType.Element && - results.Name == "BranchRelative") - branches.Add(BranchRelative.FromXml(this, results)); - } + if (results.NodeType == XmlNodeType.Element && + results.Name == "BranchRelative") + branches.Add(BranchRelative.FromXml(this, results)); + } - if (branches.Count > 0) - { - List items = new List(); - items.Add(new BranchHistoryTreeItem(branches.ToArray())); - tree.Add(items.ToArray()); - } - } - } + if (branches.Count > 0) + { + List items = new List(); + items.Add(new BranchHistoryTreeItem(branches.ToArray())); + tree.Add(items.ToArray()); + } + } + } } return tree.ToArray(); @@ -563,9 +563,9 @@ namespace Microsoft.TeamFoundation.VersionControl.Client } public ItemSet[] QueryItems(string workspaceName, string workspaceOwner, - ItemSpec[] itemSpecs, VersionSpec versionSpec, - DeletedState deletedState, ItemType itemType, - bool generateDownloadUrls) + ItemSpec[] itemSpecs, VersionSpec versionSpec, + DeletedState deletedState, ItemType itemType, + bool generateDownloadUrls) { Message msg = new Message(GetWebRequest (new Uri(Url)), "QueryItems"); @@ -794,6 +794,29 @@ namespace Microsoft.TeamFoundation.VersionControl.Client return changes.ToArray(); } + public Shelveset[] QueryShelvesets (string shelvesetName, string shelvesetOwner) + { + Message msg = new Message(GetWebRequest (new Uri(Url)), "QueryShelvesets"); + msg.Body.WriteElementString("shelvesetName", shelvesetName); + msg.Body.WriteElementString("shelvesetOwner", shelvesetOwner); + + List shelvesets = new List(); + using (HttpWebResponse response = Invoke(msg)) + { + XmlReader results = msg.ResponseReader(response); + + while (results.Read()) + { + if (results.NodeType == XmlNodeType.Element && + results.Name == "Shelveset") + shelvesets.Add(Shelveset.FromXml(this, results)); + } + } + + shelvesets.Sort(ShelvesetGenericComparer.Instance); + return shelvesets.ToArray(); + } + public Workspace QueryWorkspace(string workspaceName, string ownerName) { Message msg = new Message(GetWebRequest (new Uri(Url)), "QueryWorkspace"); diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/Shelveset.cs b/class/Microsoft.TeamFoundation.VersionControl.Client/Shelveset.cs new file mode 100644 index 0000000..3e21e56 --- /dev/null +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/Shelveset.cs @@ -0,0 +1,158 @@ +// +// Microsoft.TeamFoundation.VersionControl.Client.Shelveset +// +// Authors: +// Joel Reed (joelwreed@gmail.com) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +namespace Microsoft.TeamFoundation.VersionControl.Client +{ + internal class ShelvesetGenericComparer : IComparer + { + public static ShelvesetGenericComparer Instance = new ShelvesetGenericComparer(); + + public int Compare(Shelveset x, Shelveset y) + { + int cmp = String.Compare(x.Name, y.Name); + if (cmp != 0) return cmp; + return String.Compare(x.Name, y.OwnerName); + } + } + + public sealed class Shelveset + { + private string name; + private string comment; + private string ownerName; + private DateTime creationDate; + private VersionControlServer versionControlServer; + + internal static Shelveset FromXml(Repository repository, XmlReader reader) + { + string elementName = reader.Name; + + Shelveset shelveset = new Shelveset(); + shelveset.versionControlServer = repository.VersionControlServer; + + shelveset.creationDate = Convert.ToDateTime(reader.GetAttribute("date")); + shelveset.ownerName = reader.GetAttribute("owner"); + shelveset.name = reader.GetAttribute("name"); + + while (reader.Read()) + { + if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName) + break; + + if (reader.NodeType == XmlNodeType.Element) + { + switch (reader.Name) + { + case "Comment": + shelveset.comment = reader.ReadString(); + break; + } + } + } + + return shelveset; + } + + internal void ToXml(XmlWriter writer, string element) + { + writer.WriteStartElement(element); + writer.WriteAttributeString("date", CreationDate.ToString()); + writer.WriteElementString("owner", OwnerName); + writer.WriteEndElement(); + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + + sb.Append("Shelveset instance "); + sb.Append(GetHashCode()); + + sb.Append("\n Name: "); + sb.Append(Name); + + sb.Append("\n Comment: "); + sb.Append(Comment); + + sb.Append("\n OwnerName: "); + sb.Append(OwnerName); + + return sb.ToString(); + } + + public string Name + { + get { return name; } + } + + public string Comment + { + get { return comment; } + } + + public string OwnerName + { + get { return ownerName; } + } + + public DateTime CreationDate + { + get { return creationDate; } + } + + public VersionControlServer VersionControlServer + { + get { return versionControlServer; } + } + + internal class ShelvesetComparer : IComparer + { + public static ShelvesetComparer Instance = new ShelvesetComparer(); + + public int Compare(object xo, object yo) + { + Shelveset x = xo as Shelveset; + Shelveset y = yo as Shelveset; + return ShelvesetGenericComparer.Instance.Compare(x, y); + } + } + + public static IComparer NameComparer { + get { + return ShelvesetComparer.Instance; + } + } + + } +} diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlServer.cs b/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlServer.cs index f550223..c0a3670 100644 --- a/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlServer.cs +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlServer.cs @@ -293,6 +293,11 @@ namespace Microsoft.TeamFoundation.VersionControl.Client return Repository.QueryItemPermissions(identityNames, items, recursion); } + public Shelveset[] QueryShelvesets (string shelvesetName, string shelvesetOwner) + { + return repository.QueryShelvesets(shelvesetName, shelvesetOwner); + } + public Workspace[] QueryWorkspaces(string workspaceName, string ownerName, string computer) { diff --git a/tools/tf/ShelvesetsCommand.cs b/tools/tf/ShelvesetsCommand.cs new file mode 100644 index 0000000..95036a8 --- /dev/null +++ b/tools/tf/ShelvesetsCommand.cs @@ -0,0 +1,86 @@ +// +// ShelvesetsCommand.cs +// +// Authors: +// Joel Reed (joelwreed@gmail.com) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using Microsoft.TeamFoundation.Client; +using Microsoft.TeamFoundation.VersionControl.Client; +using Mono.GetOptions; + +[Command("shelvesets", "List shelvesets in server repository.")] +class ShelvesetsCommand : Command +{ + [Option("Format \"brief\" or \"detailed\".", "F", "format")] + public string OptionFormat = ""; + + [Option("Owner name", "O", "owner")] + public string OptionOwner; + + public ShelvesetsCommand(Driver driver, string[] args): base(driver, args) + { + } + + public void BriefOutput(Shelveset[] shelvesets) + { + foreach (Shelveset shelveset in shelvesets) + { + Console.WriteLine(shelveset); + } + } + + public void DetailedOutput(Shelveset[] shelvesets) + { + foreach (Shelveset shelveset in shelvesets) + { + Console.WriteLine(shelveset); + } + } + + public override void Run() + { + string name = ""; + if (Arguments.Length > 0) name = Arguments[0]; + + Shelveset[] shelvesets = VersionControlServer.QueryShelvesets(name, OwnerFromString(OptionOwner)); + + Console.WriteLine("here1"); + if (shelvesets.Length == 0) + { + Console.WriteLine("No shelveset matching {0} for owner {1} found in Team Foundation Server.", + name, OwnerFromString(OptionOwner)); + Environment.Exit(-1); + } + + Console.WriteLine("here2"); + bool detailed = OptionFormat.Equals("detailed", StringComparison.InvariantCultureIgnoreCase); + if (detailed) DetailedOutput(shelvesets); + else BriefOutput(shelvesets); + } +} diff --git a/tools/tf/tf.exe.sources b/tools/tf/tf.exe.sources index 260e36b..f1f54bd 100644 --- a/tools/tf/tf.exe.sources +++ b/tools/tf/tf.exe.sources @@ -25,6 +25,7 @@ LsFilesCommand.cs OnlineCommand.cs PermissionCommand.cs PropertiesCommand.cs +ShelvesetsCommand.cs RenameCommand.cs StatusCommand.cs TreeCleanCommand.cs -- 2.11.4.GIT