2 // Microsoft.TeamFoundation.VersionControl.Client.PendingChange
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.
33 using System
.Security
.Cryptography
;
35 namespace Microsoft
.TeamFoundation
.VersionControl
.Client
37 public class PendingChange
39 private ChangeType changeType
;
40 private VersionControlServer versionControlServer
;
41 private string serverItem
;
42 private string localItem
;
45 private DateTime creationDate
;
46 private byte[] uploadHashValue
;
47 private string downloadUrl
;
48 private ItemType itemType
= ItemType
.Any
;
50 // <PendingChange chg="Add Edit Encoding" hash="" uhash="" pcid="-339254" />
52 internal static PendingChange
FromXml(Repository repository
, XmlReader reader
)
54 PendingChange change
= new PendingChange();
55 change
.versionControlServer
= repository
.VersionControlServer
;
57 change
.serverItem
= reader
.GetAttribute("item");
58 change
.localItem
= TfsPath
.ToPlatformPath(reader
.GetAttribute("local"));
59 change
.itemId
= Convert
.ToInt32(reader
.GetAttribute("itemid"));
60 change
.encoding
= Convert
.ToInt32(reader
.GetAttribute("enc"));
61 change
.creationDate
= DateTime
.Parse(reader
.GetAttribute("date"));
63 string itype
= reader
.GetAttribute("type");
64 if (!String
.IsNullOrEmpty(itype
))
65 change
.itemType
= (ItemType
) Enum
.Parse(typeof(ItemType
), itype
, true);
67 change
.downloadUrl
= reader
.GetAttribute("durl");
69 string chgAttr
= reader
.GetAttribute("chg");
70 change
.changeType
= (ChangeType
) Enum
.Parse(typeof(ChangeType
), chgAttr
.Replace(" ", ","), true);
71 if (change
.changeType
== ChangeType
.Edit
) change
.itemType
= ItemType
.File
;
76 public override string ToString()
78 StringBuilder sb
= new StringBuilder();
80 sb
.Append("PendingChange instance ");
81 sb
.Append(GetHashCode());
83 sb
.Append("\n ServerItem: ");
84 sb
.Append(ServerItem
);
86 sb
.Append("\n LocalItem: ");
89 sb
.Append("\n ItemId: ");
92 sb
.Append("\n Encoding: ");
95 sb
.Append("\n Creation Date: ");
96 sb
.Append(CreationDate
);
98 sb
.Append("\n ChangeType: ");
99 sb
.Append(ChangeType
);
101 sb
.Append("\n ItemType: ");
104 sb
.Append("\n Download URL: ");
105 sb
.Append(downloadUrl
);
107 return sb
.ToString();
110 internal void UpdateUploadHashValue()
112 using (FileStream stream
= new FileStream(LocalItem
, FileMode
.Open
, FileAccess
.Read
))
114 MD5CryptoServiceProvider md5
= new MD5CryptoServiceProvider();
115 md5
.ComputeHash(stream
);
116 uploadHashValue
= md5
.Hash
;
120 public void DownloadBaseFile(string localFileName
)
122 if (itemType
== ItemType
.Folder
) return;
123 Uri artifactUri
= new Uri(String
.Format("{0}?{1}", VersionControlServer
.Repository
.ItemUrl
, downloadUrl
));
124 //Console.WriteLine(ToString());
125 //Console.WriteLine(artifactUri.ToString());
126 //Console.WriteLine("---------------------------------------------------");
127 Client
.DownloadFile
.WriteTo(localFileName
, VersionControlServer
.Repository
,
131 public byte[] UploadHashValue
134 if (uploadHashValue
== null) UpdateUploadHashValue();
135 return uploadHashValue
;
139 public DateTime CreationDate
141 get { return creationDate; }
146 get { return encoding; }
149 public string LocalItem
151 get { return localItem; }
156 get { return itemId; }
159 public ItemType ItemType
161 get { return itemType; }
166 get { return (changeType & ChangeType.Add) == ChangeType.Add; }
171 get { return (changeType & ChangeType.Branch) == ChangeType.Branch; }
176 get { return (changeType & ChangeType.Delete) == ChangeType.Delete; }
181 get { return (changeType & ChangeType.Edit) == ChangeType.Edit; }
184 public bool IsEncoding
186 get { return (changeType & ChangeType.Encoding) == ChangeType.Encoding; }
191 get { return (changeType & ChangeType.Lock) == ChangeType.Lock; }
196 get { return (changeType & ChangeType.Merge) == ChangeType.Merge; }
201 get { return (changeType & ChangeType.Rename) == ChangeType.Rename; }
204 public ChangeType ChangeType
206 get { return changeType; }
209 public string ServerItem
211 get { return serverItem; }
214 public VersionControlServer VersionControlServer
216 get { return versionControlServer; }
219 static public string GetLocalizedStringForChangeType(ChangeType changeType
)
221 return changeType
.ToString();