2 // Microsoft.TeamFoundation.VersionControl.Client.GetOperation
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.
35 namespace Microsoft
.TeamFoundation
.VersionControl
.Client
37 internal class GetOperation
: ILocalUpdateOperation
39 public ChangeType ChangeType
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
74 public int VersionLocal
79 public int VersionServer
84 public Uri ArtifactUri
86 get { return artifactUri; }
89 private ItemType itemType
= ItemType
.File
;
90 private int itemId
= 0;
93 private string slocal
;
94 private string tlocal
;
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
)
146 if (reader
.NodeType
== XmlNodeType
.Element
&& (!reader
.IsEmptyElement
))
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: ");
172 sb
.Append("\n slocal: ");
175 sb
.Append("\n tlocal: ");
178 sb
.Append("\n titem: ");
181 sb
.Append("\n sver: ");
184 sb
.Append("\n 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;
205 // if (String.IsNullOrEmpty(getOperation.slocal))
206 // getOperation.chg = ChangeType.Add;
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;