show the difference between two versions for a specified path
[tfs.git] / class / Microsoft.TeamFoundation.VersionControl.Client / GetOperation.cs
blob5cbc53ca2026f494a2b77a3338b4d3e106b93fad
1 //
2 // Microsoft.TeamFoundation.VersionControl.Client.GetOperation
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.IO;
31 using System.Net;
32 using System.Text;
33 using System.Xml;
35 namespace Microsoft.TeamFoundation.VersionControl.Client
37 internal class GetOperation : ILocalUpdateOperation
39 public ChangeType ChangeType
41 get { return chg; }
44 public int DeletionId
46 get { return did; }
49 public int ItemId
51 get { return itemId; }
54 public ItemType ItemType
56 get { return itemType; }
59 public string TargetLocalItem
61 get { return tlocal; }
64 public string SourceLocalItem
66 get { return slocal; }
69 public string TargetServerItem
71 get { return titem; }
74 public int VersionLocal
76 get { return lver; }
79 public int VersionServer
81 get { return sver; }
84 public Uri ArtifactUri
86 get { return artifactUri; }
89 private ItemType itemType = ItemType.File;
90 private int itemId = 0;
91 private int did = 0;
93 private string slocal;
94 private string tlocal;
95 private string titem;
96 private int sver = 0;
97 private int lver = 0;
98 private ChangeType chg = ChangeType.None;
99 //private LockLevel @lock = LockLevel.None;
100 //private bool il = true;
101 //private int pcid = 0;
102 //private bool cnflct = false;
103 //private int cnflctitemid = 0;
104 private Uri artifactUri;
105 //private System.Byte[] hashValue;
107 internal static GetOperation FromXml(string itemUrl, XmlReader reader)
109 GetOperation getOperation = new GetOperation();
110 string elementName = reader.Name;
112 string stype = reader.GetAttribute("type");
113 if (!String.IsNullOrEmpty(stype))
114 getOperation.itemType = (ItemType) Enum.Parse(typeof(ItemType), stype, true);
116 getOperation.itemId = Convert.ToInt32(reader.GetAttribute("itemid"));
117 getOperation.slocal = TfsPath.ToPlatformPath(reader.GetAttribute("slocal"));
118 getOperation.tlocal = TfsPath.ToPlatformPath(reader.GetAttribute("tlocal"));
120 getOperation.titem = reader.GetAttribute("titem");
121 getOperation.sver = Convert.ToInt32(reader.GetAttribute("sver"));
122 getOperation.lver = Convert.ToInt32(reader.GetAttribute("lver"));
124 string chgAttr = reader.GetAttribute("chg");
125 if (!String.IsNullOrEmpty(chgAttr))
126 getOperation.chg = (ChangeType) Enum.Parse(typeof(ChangeType), chgAttr.Replace(" ", ","), true);
128 // setup download url if found
129 string durl = reader.GetAttribute("durl");
130 if (!String.IsNullOrEmpty(durl))
131 getOperation.artifactUri = new Uri(String.Format("{0}?{1}", itemUrl, durl));
133 // here's what you get if you remap a working folder from one
134 // team project to another team project with the same file
135 // first you get the update getOperation, then you get this later on
136 // <GetOperation type="File" itemid="159025" slocal="foo.xml" titem="$/bar/foo.xml" lver="12002"><HashValue /></GetOperation>
138 // look for a deletion id
139 getOperation.did = Convert.ToInt32(reader.GetAttribute("did"));
141 while (reader.Read())
143 if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName)
144 break;
146 if (reader.NodeType == XmlNodeType.Element && (!reader.IsEmptyElement))
148 switch (reader.Name)
150 case "HashValue":
151 break;
156 return getOperation;
159 public override string ToString()
161 StringBuilder sb = new StringBuilder();
163 sb.Append("GetOperation instance ");
164 sb.Append(GetHashCode());
166 sb.Append("\n type: ");
167 sb.Append(ItemType.ToString());
169 sb.Append("\n itemid: ");
170 sb.Append(ItemId);
172 sb.Append("\n slocal: ");
173 sb.Append(slocal);
175 sb.Append("\n tlocal: ");
176 sb.Append(tlocal);
178 sb.Append("\n titem: ");
179 sb.Append(titem);
181 sb.Append("\n sver: ");
182 sb.Append(sver);
184 sb.Append("\n lver: ");
185 sb.Append(lver);
187 sb.Append("\n did: ");
188 sb.Append(DeletionId);
190 sb.Append("\n ArtifactUri: ");
191 sb.Append(artifactUri);
193 sb.Append("\n ChangeType: ");
194 sb.Append(ChangeType.ToString());
196 return sb.ToString();
201 // if (getOperation.did != 0) getOperation.chg = ChangeType.Delete;
202 // //else if (getOperation.sver == 0) getOperation.chg = ChangeType.None;
203 // else
204 // {
205 // if (String.IsNullOrEmpty(getOperation.slocal))
206 // getOperation.chg = ChangeType.Add;
207 // else
208 // {
209 // // seems to be only way to tell if this is a rename operation
210 // if ((!String.IsNullOrEmpty(getOperation.tlocal))&&
211 // (getOperation.slocal != getOperation.tlocal))
212 // getOperation.chg = ChangeType.Rename;
213 // }
214 // }