use.username.instead.of.owner
[tfs.git] / sample.cs
blob8065492fd22efd29fba2c9d50bf18d4e35d1ce32
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.IO;
5 using System.Net;
6 using System.Text;
7 using Microsoft.TeamFoundation.Client;
8 using Microsoft.TeamFoundation.VersionControl.Client;
10 namespace BasicSccExample
12 class Example
14 static void PrintWorkspace(Workspace w)
16 Console.WriteLine(w.ToString());
19 static void Main(string[] args)
21 // Verify that we have the arguments we require.
22 if (args.Length < 3)
24 String appName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
25 Console.Error.WriteLine("Usage: {0} tfsServerName tfsTeamProjectPath", appName);
26 Console.Error.WriteLine("Example: {0} http://tfsserver:8080 $/MyProject", appName);
27 Environment.Exit(1);
30 // Get a reference to our Team Foundation Server.
31 string serverUri = "http://10.100.1.88:8080";
32 TeamFoundationServer tfs = new TeamFoundationServer(serverUri,
33 new NetworkCredential(args[0], args[1], args[2]));
35 // Get a reference to Version Control.
36 VersionControlServer versionControl = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));
38 string path;
40 Console.WriteLine("versionControl.GetWorkspace(name, owner):");
41 Workspace workspace = versionControl.GetWorkspace(Workstation.Current.Name, "jreed");
42 path = workspace.Folders[0].LocalItem;
43 PrintWorkspace(workspace);
44 Console.ReadLine();
48 Console.WriteLine("versionControl.GetWorkspace(path):");
49 Workspace workspace = versionControl.GetWorkspace(path);
50 PrintWorkspace(workspace);
51 Console.ReadLine();
55 WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(path);
56 Console.WriteLine("versionControl.GetWorkspace(info):");
57 Workspace workspace = versionControl.GetWorkspace(info);
58 PrintWorkspace(workspace);
59 Console.ReadLine();
62 // Listen for the Source Control events.
63 // versionControl.NonFatalError += Example.OnNonFatalError;
64 //versionControl.Getting += Example.OnGetting;
65 //versionControl.BeforeCheckinPendingChange += Example.OnBeforeCheckinPendingChange;
66 //versionControl.NewPendingChange += Example.OnNewPendingChange;
68 // Get the files from the repository.
69 //workspace.Get();
72 internal static void OnNonFatalError(Object sender, ExceptionEventArgs e)
74 if (e.Exception != null)
76 Console.Error.WriteLine("Non-fatal exception: " + e.Exception.Message);
78 else
80 Console.Error.WriteLine("Non-fatal failure: " + e.Failure.Message);
84 internal static void OnGetting(Object sender, GettingEventArgs e)
86 Console.WriteLine("Getting: " + e.TargetLocalItem + ", status: " + e.Status);
89 internal static void OnBeforeCheckinPendingChange(Object sender, ProcessingChangeEventArgs e)
91 Console.WriteLine("Checking in " + e.PendingChange.LocalItem);
94 internal static void OnNewPendingChange(Object sender, PendingChangeEventArgs e)
96 Console.WriteLine("Pending " + PendingChange.GetLocalizedStringForChangeType(e.PendingChange.ChangeType) +
97 " on " + e.PendingChange.LocalItem);