Project: Tf.Undo.Checkout.Remote.Workspace


Undo checkout on remote TFS workspaces from other users:
void Main()
{
	var path = "$/file_path";
	var username = @"username_cp"; //if CodePlex: snd\username_cp
	var password = "PASSWORD";
	var workspace = "WORKSPACE";
	var workspaceUser = "workspace.user_cp"; //if CodePlex: name_cp, the blocking user
	var serverUrl = @"serverUrl"; //if CodePlex: tfs.codeplex.com\TFSXX where XX is the server number
	
	UndoCheckoutFile(
		path, 
		username, 
		password,
		workspace,
		workspaceUser,
		serverUrl); 
}

public void UndoCheckoutFile(
	string path,
	string username, 
	string password, 
	string workspace,
	string workspaceUser,
	string serverUrl)
{
	var tf = 
		"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\tf.exe";
	
	var tfCommandFormat =
		"undo /workspace:{0};{1}" +
		" \"{2}\"" +
		" /s:{3}" +
		" /login:{4},{5}";

	var tfCommand =
		string.Format(
			tfCommandFormat,
			workspace,
			workspaceUser,
			path,
			serverUrl,
			username, 
			password).Dump();
			
	Console.WriteLine();
		
	var processStartInfo = 
		new ProcessStartInfo(tf)
			{
				Arguments = tfCommand,					
				RedirectStandardInput = false,
				RedirectStandardOutput = true,
				RedirectStandardError = true,
				CreateNoWindow = true,
				WindowStyle = ProcessWindowStyle.Hidden,
				UseShellExecute = false
			};
			
	
	using (var process = Process.Start(processStartInfo))
	{
		process.BeginErrorReadLine();
		process.BeginOutputReadLine();
		process.OutputDataReceived += (s, e) => {if (e.Data != null) Console.WriteLine(e.Data); };
		process.ErrorDataReceived += (s, e) => {if (e.Data != null) Console.WriteLine(e.Data); };

		process.WaitForExit();
	}
}

Last edited Mar 2, 2013 at 2:58 PM by teoarch, version 5

Comments

No comments yet.