/// <summary>
		/// Creates XML element containing the information on the specified pending change.
		/// </summary>
		public static XElement ExportPendingChange(PendingChange change)
		{
			return new XElement(
				"change",
				new XElement("path", change.ServerItem),
				new XElement("checkoutDate", ExportDateTime(change.CreationDate)),
				new XElement("daysSinceCheckout", ExportTimeSpanDays(DateTime.Now - change.CreationDate)));
		}
 public changeItem(PendingChange change)
 {
     this.change = change;
     fileName = change.FileName;
     changeType = change.ChangeType.ToString();
     folder = change.LocalOrServerFolder;
     selected = true;
 }
        public TfsPendingChangeWrapper(PendingChange pendingChange)
        {
            if (pendingChange == null)
            {
                throw new ArgumentNullException("pendingChange");
            }

            _pendingChange = pendingChange;
        }
 private static DateTime GetLastChangeDate(PendingChange change)
 {
     if (change.IsDelete)
     {
         return change.CreationDate;
     }
     else
     {
         return File.GetLastWriteTime(change.LocalItem);
     }
 }
 private static byte[] GetMD5HashValue(PendingChange change)
 {
     if (change.IsDelete || !File.Exists(change.LocalItem) )
     {
         return change.UploadHashValue;
     }
     else
     {
         return MD5.Create().ComputeHash(File.ReadAllBytes(change.LocalItem));
     }
 }
 internal void UploadFile(Workspace workspace, PendingChange change)
 {
     if (change.ItemType != ItemType.File)
     {
         return;
     }
     if (change.ChangeType.HasFlag(ChangeType.Edit) || change.ChangeType.HasFlag(ChangeType.Add))
     {
         UploadFile(workspace.Name, workspace.OwnerName, change);
     }
 }
 public static bool DifferFrom(this PendingChange[] changes, PendingChange[] shelvedchanges)
 {
     var recentChanges = changes.OrderByDescending(c => GetLastChangeDate(c)).Take(10);
     var shelveditems = shelvedchanges.ToList().ToDictionary(c => c.ServerItem);
     foreach (var change in recentChanges)
     {
         if (!shelveditems.ContainsKey(change.ServerItem) || !shelveditems[change.ServerItem].UploadHashValue.SequenceEqual(GetMD5HashValue(change)))
         {
             return true;
         }
     }
     return false;
 }
Beispiel #8
0
        public PendingChange[] QueryPendingSets(string localWorkspaceName, string localWorkspaceOwner,
                                                string queryWorkspaceName, string ownerName,
                                                ItemSpec[] itemSpecs, bool generateDownloadUrls,
                                                out Failure[] failures)
        {
            Message msg = new Message(GetWebRequest(new Uri(Url)), "QueryPendingSets");

            msg.Body.WriteElementString("localWorkspaceName", localWorkspaceName);
            msg.Body.WriteElementString("localWorkspaceOwner", localWorkspaceOwner);
            msg.Body.WriteElementString("queryWorkspaceName", queryWorkspaceName);
            msg.Body.WriteElementString("ownerName", ownerName);

            msg.Body.WriteStartElement("itemSpecs");
            foreach (ItemSpec item in itemSpecs)
            {
                item.ToXml(msg.Body, "ItemSpec");
            }
            msg.Body.WriteEndElement();

            msg.Body.WriteElementString("generateDownloadUrls",
                                        generateDownloadUrls.ToString().ToLower());

            List <PendingChange> changes  = new List <PendingChange>();
            List <Failure>       faillist = new List <Failure>();

            using (HttpWebResponse response = Invoke(msg))
            {
                XmlReader results = msg.ResponseReader(response);

                while (results.Read())
                {
                    if (results.NodeType == XmlNodeType.Element)
                    {
                        switch (results.Name)
                        {
                        case "PendingChange":
                            changes.Add(PendingChange.FromXml(this, results));
                            break;

                        case "Failure":
                            faillist.Add(Failure.FromXml(this, results));
                            break;
                        }
                    }
                }
            }

            failures = faillist.ToArray();
            return(changes.ToArray());
        }
        public bool TryCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote = null, WorkItemCheckinInfo[] workItemChanges = null, PolicyOverrideInfo policyOverride = null)
        {
            try
            {
                _teamPilgrimTfsService.WorkspaceCheckin(workspace, changes, comment, checkinNote, workItemChanges, policyOverride);
                return true;
            }
            catch (Exception ex)
            {
                this.Logger().DebugException(ex);
                LastException = ex;
            }

            return false;
        }
        public void UploadFile(string workspaceName, string workspaceOwner, PendingChange change)
        {
            var    fileContent = File.ReadAllBytes(change.LocalItem);
            var    fileHash    = Hash(fileContent);
            string contentType = uncompressedContentType;

            using (var memory = new MemoryStream(fileContent))
            {
                byte[] buffer = new byte[ChunkSize];
                int    cnt;
                while ((cnt = memory.Read(buffer, 0, ChunkSize)) > 0)
                {
                    var range = GetRange(memory.Position - cnt, memory.Position, fileContent.Length);
                    UploadPart(change.ServerItem, workspaceName, workspaceOwner, fileContent.Length, fileHash, range, contentType, buffer, cnt);
                }
            }
        }
Beispiel #11
0
        private void UploadFile(string workspaceName, string ownerName, PendingChange change,
                                string commandName)
        {
            FileInfo fi  = new FileInfo(change.LocalItem);
            long     len = fi.Length;

            UploadFile upload = new UploadFile(uploadUrl, Credentials, commandName);

            upload.AddValue(RepositoryConstants.ServerItemField, change.ServerItem);
            upload.AddValue(RepositoryConstants.WorkspaceNameField, workspaceName);
            upload.AddValue(RepositoryConstants.WorkspaceOwnerField, ownerName);
            upload.AddValue(RepositoryConstants.LengthField, len.ToString());
            upload.AddValue(RepositoryConstants.HashField, Convert.ToBase64String(change.UploadHashValue));

            // send byte range
            // TODO: handle files to large to fit in a single POST
            upload.AddValue(RepositoryConstants.RangeField,
                            String.Format("bytes=0-{0}/{1}", len - 1, len));

            upload.AddFile(change.LocalItem);

            WebResponse response;

            try
            {
                response = upload.Send();
            }
            catch (WebException ex)
            {
                response = ex.Response;
                HttpWebResponse http_response = response as HttpWebResponse;
                if (http_response == null || http_response.StatusCode != HttpStatusCode.InternalServerError)
                {
                    throw ex;
                }
            }

            // Get the stream associated with the response.
            //Stream receiveStream = response.GetResponseStream ();
            //StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
            //Console.WriteLine (readStream.ReadToEnd ());

            response.Close();
            //readStream.Close();
        }
 internal PendingChangeEventArgs(Workspace workspace, PendingChange pendingChange)
 {
     this.workspace = workspace;
         this.pendingChange = pendingChange;
 }
Beispiel #13
0
 public void ShelveFile(string workspaceName, string ownerName, PendingChange change)
 {
     UploadFile(workspaceName, ownerName, change, "Shelve");
 }
        public bool TryShelve(Workspace workspace, Shelveset shelveset, PendingChange[] pendingChanges, ShelvingOptions shelvingOptions)
        {
            try
            {
                _teamPilgrimTfsService.WorkspaceShelve(workspace, shelveset, pendingChanges, shelvingOptions);
                return true;
            }
            catch (Exception ex)
            {
                this.Logger().DebugException(ex);
                LastException = ex;
            }

            return false;
        }
Beispiel #15
0
        //        <PendingChange chg="Add Edit Encoding" hash="" uhash="" pcid="-339254" />
        internal static PendingChange FromXml(Repository repository, XmlReader reader)
        {
            PendingChange change = new PendingChange();
            change.versionControlServer = repository.VersionControlServer;

            change.serverItem = reader.GetAttribute("item");
            change.localItem = TfsPath.ToPlatformPath(reader.GetAttribute("local"));
            change.itemId = Convert.ToInt32(reader.GetAttribute("itemid"));
            change.encoding = Convert.ToInt32(reader.GetAttribute("enc"));
            change.creationDate = DateTime.Parse(reader.GetAttribute("date"));

            string itype = reader.GetAttribute("type");
            if (!String.IsNullOrEmpty(itype))
                    change.itemType = (ItemType) Enum.Parse(typeof(ItemType), itype, true);

            change.downloadUrl = reader.GetAttribute("durl");

            string chgAttr = reader.GetAttribute("chg");
            change.changeType = (ChangeType) Enum.Parse(typeof(ChangeType), chgAttr.Replace(" ", ","), true);
            if (change.changeType == ChangeType.Edit) change.itemType = ItemType.File;

            return change;
        }
 public void WorkspaceShelve(Workspace workspace, Shelveset shelveset, PendingChange[] pendingChanges, ShelvingOptions shelvingOptions)
 {
     workspace.Shelve(shelveset, pendingChanges, shelvingOptions);
 }
Beispiel #17
0
 public void ShelveFile(string workspaceName, string ownerName, PendingChange change)
 {
     UploadFile(workspaceName, ownerName, change, "Shelve");
 }
        public void WorkspaceCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote, WorkItemCheckinInfo[] workItemChanges, PolicyOverrideInfo policyOverride)
        {
            this.Logger().Trace("WorkspaceCheckin");

            workspace.CheckIn(changes, comment, checkinNote, workItemChanges, policyOverride);
        }
Beispiel #19
0
 public IPendingChange Wrap(PendingChange pendingChange)
 {
     return new WrapperForPendingChange(pendingChange);
 }
Beispiel #20
0
        public void Shelve(Shelveset shelveset, PendingChange[] changes,
												ShelvingOptions options)
        {
            List<string> serverItems = new List<string>();

            foreach (PendingChange change in changes)
                {
                    // upload new or changed files only
                    if ((change.ItemType == ItemType.File) &&
                            (change.IsAdd || change.IsEdit ))
                        {
                            Repository.ShelveFile(Name, OwnerName, change);
                        }

                    serverItems.Add(change.ServerItem);
                }

            Repository.Shelve(this, shelveset, serverItems.ToArray(), options);
        }
Beispiel #21
0
        private void UploadFile(string workspaceName, string ownerName, PendingChange change,
														string commandName)
        {
            FileInfo fi = new FileInfo(change.LocalItem);
            long len = fi.Length;

            UploadFile upload = new UploadFile(uploadUrl, Credentials, commandName);
            upload.AddValue(RepositoryConstants.ServerItemField, change.ServerItem);
            upload.AddValue(RepositoryConstants.WorkspaceNameField, workspaceName);
            upload.AddValue(RepositoryConstants.WorkspaceOwnerField, ownerName);
            upload.AddValue(RepositoryConstants.LengthField, len.ToString());
            upload.AddValue(RepositoryConstants.HashField, Convert.ToBase64String(change.UploadHashValue));

            // send byte range
            // TODO: handle files to large to fit in a single POST
            upload.AddValue(RepositoryConstants.RangeField,
                                            String.Format("bytes=0-{0}/{1}", len-1, len));

            upload.AddFile(change.LocalItem);

            WebResponse response;

            try
                {
                    response = upload.Send();
                }
            catch (WebException ex)
                {
                    response = ex.Response;
                    HttpWebResponse http_response = response as HttpWebResponse;
                    if (http_response == null || http_response.StatusCode != HttpStatusCode.InternalServerError)
                        throw ex;
                }

            // Get the stream associated with the response.
            //Stream receiveStream = response.GetResponseStream ();
            //StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
            //Console.WriteLine (readStream.ReadToEnd ());

            response.Close();
            //readStream.Close();
        }
Beispiel #22
0
        // Copy from Microsoft.TeamFoundation.VersionControl.Controls.PendingChanges.ChangesetDataProvider.ResetDataFromChangeset,
        // Microsoft.TeamFoundation.VersionControl.Controls
        private static List<PendingChange> GetChangesetPendingChanges(Change[] changes)
        {
            var pendingChanges = new List<PendingChange>(changes.Length);
            foreach (var change in changes)
            {
                if (ChangeType.SourceRename != (change.ChangeType & (ChangeType.Add | ChangeType.Branch | ChangeType.Rename | ChangeType.SourceRename)))
                {
                    var pendingChange = new PendingChange(change);
                    if (change.MergeSources != null)
                    {
                        foreach (var mergeSource in change.MergeSources)
                        {
                            if (mergeSource.IsRename)
                            {
                                pendingChange.UpdateSourceItems(null, mergeSource.ServerItem);
                                break;
                            }
                        }
                    }
                    pendingChanges.Add(pendingChange);
                }
            }

            return pendingChanges;
        }
Beispiel #23
0
 internal PendingChangeEventArgs(Workspace workspace, PendingChange pendingChange)
 {
     this.workspace     = workspace;
     this.pendingChange = pendingChange;
 }
 internal void OnUndonePendingChange(Workspace workspace, PendingChange change)
 {
     if (null != UndonePendingChange) UndonePendingChange(workspace, new PendingChangeEventArgs(workspace, change));
 }
Beispiel #25
0
 public void CheckInFile(string workspaceName, string ownerName, PendingChange change)
 {
     UploadFile(workspaceName, ownerName, change, "Checkin");
 }
        public bool TryEvaluateCheckin(out CheckinEvaluationResult checkinEvaluationResult, Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote = null, WorkItemCheckinInfo[] workItemChanges = null)
        {
            try
            {
                checkinEvaluationResult = _teamPilgrimTfsService.EvaluateCheckin(workspace, changes, comment, checkinNote, workItemChanges);
                return true;
            }
            catch (Exception ex)
            {
                this.Logger().DebugException(ex);
                LastException = ex;
            }

            checkinEvaluationResult = null;
            return false;
        }
        public CheckinEvaluationResult EvaluateCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote, WorkItemCheckinInfo[] workItemChanges)
        {
            this.Logger().Trace("EvaluateCheckin");

            return workspace.EvaluateCheckin(CheckinEvaluationOptions.All, changes, changes, comment, checkinNote, workItemChanges);
        }
        public bool TryGetPendingChanges(out PendingChange[] pendingChanges, Workspace workspace, string[] items)
        {
            try
            {
                pendingChanges = workspace.GetPendingChanges(items);
                return true;
            }
            catch (Exception ex)
            {
                this.Logger().DebugException(ex);
                LastException = ex;
            }

            pendingChanges = null;
            return false;
        }
Beispiel #29
0
        public int CheckIn(PendingChange[] changes, string comment)
        {
            if (changes.Length == 0) return 0;

            List<string> serverItems = new List<string>();
            SortedList<string, PendingChange> changesByServerPath = new SortedList<string, PendingChange>();

            foreach (PendingChange change in changes)
                {
                    // upload new or changed files only
                    if ((change.ItemType == ItemType.File) &&
                            (change.IsAdd || change.IsEdit ))
                        {
                            Repository.CheckInFile(Name, OwnerName, change);
                            SetFileAttributes(change.LocalItem);
                        }

                    serverItems.Add(change.ServerItem);
                    changesByServerPath.Add(change.ServerItem, change);
                }

            SortedList<string, bool> undoneServerItems = new SortedList<string, bool>();
            int cset = Repository.CheckIn(this, serverItems.ToArray(), comment, ref undoneServerItems);

            foreach (string undoneItem in undoneServerItems.Keys)
                {
                    PendingChange change = changesByServerPath[undoneItem];
                    VersionControlServer.OnUndonePendingChange(this, change);
                }

            return cset;
        }
Beispiel #30
0
 public void CheckInFile(string workspaceName, string ownerName, PendingChange change)
 {
     UploadFile(workspaceName, ownerName, change, "Checkin");
 }
 public PendingChangeModel(PendingChange change)
 {
     _change = change;
 }
 /// <summary>
 /// Returns the full file path of the pending change file.
 /// </summary>
 /// <param name="pendingChange">The pending change file</param>
 /// <returns>The full file path of the given pending change</returns>
 private static string GetFullFilePath(PendingChange pendingChange)
 {
     return (pendingChange != null) ? string.Format(CultureInfo.CurrentCulture, @"{0}/{1}", pendingChange.LocalOrServerFolder, pendingChange.FileName) : string.Empty;
 }
        //		public void ShelveFile(string workspaceName, string ownerName, PendingChange change)
        //		{
        //			UploadFile(workspaceName, ownerName, change);
        //		}
        private void UploadFile(string workspaceName, string ownerName, PendingChange change)
        {
            var uploadService = this.Collection.GetService <UploadService>();

            uploadService.UploadFile(workspaceName, ownerName, change);
        }
        private long ShowCheckinDialog(Workspace workspace, PendingChange[] pendingChanges,
            WorkItemCheckedInfo[] checkedInfos, string checkinComment)
        {
            using (var parentForm = new ParentForm())
            {
                parentForm.Show();

                var dialog = Activator.CreateInstance(GetCheckinDialogType(), new object[] { workspace.VersionControlServer });

                return dialog.Call<int>("Show", parentForm.Handle, workspace, pendingChanges, pendingChanges,
                                        checkinComment, null, null, checkedInfos);
            }
        }