Tp.SourceControl.Testing.Repository.Tfs.TfsTestRepository.Commit C# (CSharp) Method

Commit() public method

public Commit ( string serverItemPath, string changedContent, string commitComment ) : string
serverItemPath string
changedContent string
commitComment string
return string
		public string Commit(string serverItemPath, string changedContent, string commitComment)
		{
			TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.TestCollection));
			var vcs = collection.GetService<VersionControlServer>();
			TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.TestCollectionProject);
			ItemSet itemSet = vcs.GetItems(tp.ServerItem, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.File);
			Item item = itemSet.Items.FirstOrDefault(x => x.ServerItem == serverItemPath);

			string localItem = _workspace.GetLocalItemForServerItem(item.ServerItem);
			int changesetId = _workspace.PendEdit(localItem);

			using (var file = File.OpenWrite(localItem))
			{
				var changes = new UTF8Encoding(true).GetBytes(changedContent);
				file.Seek(0, SeekOrigin.End);
				file.Write(changes, 0, changes.Length);
			}

			PendingChange[] pendingChanges = _workspace.GetPendingChanges().Where(x => x.ChangeType == ChangeType.Edit).ToArray();
			int changeset = _workspace.CheckIn(pendingChanges, ConfigHelper.Instance.Login, commitComment, null, null, null);

			Changeset latestChangeset = vcs.GetChangeset(changeset);

			collection.Dispose();

			return latestChangeset.ChangesetId.ToString(CultureInfo.InvariantCulture);
		}

Same methods

TfsTestRepository::Commit ( string commitComment ) : void