public BuildFetcher(String serverAddress, String projectName, ICredentials credentials) { this.projectName = projectName; tfsServer = new TeamFoundationServer(serverAddress, credentials); tfsServer.Authenticate(); buildServer = (IBuildServer) tfsServer.GetService(typeof (IBuildServer)); }
public TFS(string servername, string domain, string username, string password) { if (string.IsNullOrEmpty(servername)) { throw new ArgumentException("Parameter named:servername cannot be null or empty."); } if (string.IsNullOrEmpty(username)) { throw new ArgumentException("Parameter named:username cannot be null or empty."); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException("Parameter named:password cannot be null or empty."); } //ICredentialsProvider provider = new UICredentialsProvider(); //tfsServer = TeamFoundationServerFactory.GetServer(serverName, provider); //if (!tfsServer.HasAuthenticated) // tfsServer.Authenticate(); try { var tfsConfigurationServer = new TfsConfigurationServer(new Uri(servername), new NetworkCredential(username, password, domain)); store = (WorkItemStore) tfsConfigurationServer.GetService(typeof (WorkItemStore)); } catch (Exception) { var tfsServer = new TeamFoundationServer(servername, new NetworkCredential(username, password, domain)); store = (WorkItemStore) tfsServer.GetService(typeof (WorkItemStore)); } }
public TFS(string servername, string domain, string username, string password) { if (string.IsNullOrEmpty(servername)) { throw new ArgumentException("Parameter named:servername cannot be null or empty."); } if (string.IsNullOrEmpty(username)) { throw new ArgumentException("Parameter named:username cannot be null or empty."); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException("Parameter named:password cannot be null or empty."); } try { var tfsConfigurationServer = new TfsConfigurationServer(new Uri(servername), new NetworkCredential(username, password, domain)); store = (WorkItemStore) tfsConfigurationServer.GetService(typeof (WorkItemStore)); } catch (Exception) { var tfsServer = new TeamFoundationServer(servername, new NetworkCredential(username, password, domain)); store = (WorkItemStore) tfsServer.GetService(typeof (WorkItemStore)); } }
/// <summary> /// Tries the TFS mode. /// </summary> /// <param name="input">The input.</param> /// <returns>the number of checkedout files</returns> internal static int TryTFSMode(System.IO.FileInfo input) { try { var tfs = new TeamFoundationServer(Properties.Settings.Default.TFSServer, new NetworkCredential(Properties.Settings.Default.TFSLogin, Properties.Settings.Default.TFSPassword)); var version = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); var workspace = version.GetWorkspace(Properties.Settings.Default.TFSWorkspace, version.AuthorizedUser); int ans = workspace.PendEdit(input.FullName); return ans; } catch (Exception) { Console.WriteLine( string.Format( @" /!\The file {0} is read only please make sure the TFS app settings are OK Stack trace: ", input.FullName)); throw; } }
public void FixtureSetUp() { tfsUrl = Environment.GetEnvironmentVariable("TFS_URL"); if (String.IsNullOrEmpty(tfsUrl)) { Console.WriteLine("Warning: Environment variable TFS_URL not set."); Console.WriteLine(" Some tests cannot be executed without TFS_URL."); return; } string username = Environment.GetEnvironmentVariable("TFS_USERNAME"); if (String.IsNullOrEmpty(username)) { Console.WriteLine("Warning: No TFS user credentials specified."); return; } credentials = new NetworkCredential(username, Environment.GetEnvironmentVariable("TFS_PASSWORD"), Environment.GetEnvironmentVariable("TFS_DOMAIN")); // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); versionControlServer = (VersionControlServer) tfs.GetService(typeof(VersionControlServer)); workspace = versionControlServer.CreateWorkspace("WorkspaceTest", Environment.GetEnvironmentVariable("TFS_USERNAME")); }
public void FixtureSetUp() { tfsUrl = Environment.GetEnvironmentVariable("TFS_URL"); if (String.IsNullOrEmpty(tfsUrl)) { Console.WriteLine("Warning: Environment variable TFS_URL not set."); Console.WriteLine(" Some tests cannot be executed without TFS_URL."); return; } string username = Environment.GetEnvironmentVariable("TFS_USERNAME"); if (String.IsNullOrEmpty(username)) { Console.WriteLine("Warning: No TFS user credentials specified."); return; } credentials = new NetworkCredential(username, Environment.GetEnvironmentVariable("TFS_PASSWORD"), Environment.GetEnvironmentVariable("TFS_DOMAIN")); // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); versionControlServer = (VersionControlServer) tfs.GetService(typeof(VersionControlServer)); WorkingFolder[] folders = new WorkingFolder[1]; string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT")); folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory); workspace = versionControlServer.CreateWorkspace("UpdateWorkspaceInfoCache_Workspace", Environment.GetEnvironmentVariable("TFS_USERNAME"), "My Comment", folders, Environment.MachineName); }
public List<string> GetBuilds() { try { server = new TeamFoundationServer(CurrentProject.DomainUri); server.Authenticate(); IBuildServer buildStore = (IBuildServer)server.GetService(typeof(IBuildServer)); IBuildDetail[] buildList = buildStore.QueryBuilds(CurrentProject.ProjectName, "Daily Build"); List<string> builds = new List<string>(); foreach (IBuildDetail bd in buildList) { builds.Add(bd.BuildNumber); } builds.Reverse(); return builds; } catch { return new List<string>(); } }
public void GetService_VersionControlServer() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer)); Assert.IsNotNull(vcs); }
private void BuildStoreWorker_DoWork(object sender, DoWorkEventArgs e) { TeamFoundationServer server = new TeamFoundationServer(_teamFoundationServerUri, CredentialCache.DefaultCredentials); server.EnsureAuthenticated(); while (!this.CancellationPending) { BuildStore store = (BuildStore)server.GetService(typeof(BuildStore)); BuildData[] builds = store.GetListOfBuilds(_teamProjectName, _teamBuildTypeName); this.ReportProgress(0, builds); Thread.Sleep(30000); } }
public void GetService_CommonStructureService() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) { return; } TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); Assert.IsNotNull(css); }
public void GetProject() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService) tfs.GetService(typeof(ICommonStructureService)); ProjectInfo p1 = css.GetProjectFromName(Environment.GetEnvironmentVariable("TFS_PROJECT")); ProjectInfo p2 = css.GetProject(p1.Uri); Assert.IsNotNull(p2.Name); Assert.IsNotNull(p2.Status); Assert.IsNotNull(p2.Uri); }
public void GetProjectFromName() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) { return; } TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); ProjectInfo pinfo = css.GetProjectFromName(Environment.GetEnvironmentVariable("TFS_PROJECT")); Assert.IsNotNull(pinfo.Name); Assert.IsNotNull(pinfo.Status); Assert.IsNotNull(pinfo.Uri); }
public void ListProjects() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) { return; } TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); ProjectInfo[] projects = css.ListProjects(); foreach (ProjectInfo pinfo in projects) { Assert.IsNotNull(pinfo.Name); } }
public WorkItemFetcher(String serverAddress, String projectName, ICredentials credentials, Dictionary<String, String> configuration) { String configValue = ""; WORK_REMAINING_FIELD = (configuration.TryGetValue("tfswi-remaining-field", out configValue)) ? configValue : WORK_REMAINING_FIELD; ESTIMATED_EFFORT_FIELD = (configuration.TryGetValue("tfswi-estimated-field", out configValue)) ? configValue : ESTIMATED_EFFORT_FIELD; this.projectName = projectName; tfsServer = new TeamFoundationServer(serverAddress, credentials); tfsServer.Authenticate(); workItemStore = tfsServer.GetService(typeof (WorkItemStore)) as WorkItemStore; }
public bool Connect() { try { // //Trace.Write(WindowsIdentity.GetCurrent().Name); server = new TeamFoundationServer(ServerName, Credentials); store = server.GetService(typeof(WorkItemStore)) as WorkItemStore; project = store.Projects[ProjectName]; //TODO: Validar conexão return true; } catch (Exception xa) { throw xa; } }
public void Workspace_Get() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer)); WorkingFolder[] folders = new WorkingFolder[1]; string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT")); folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory); Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace", Environment.GetEnvironmentVariable("TFS_USERNAME"), "My Comment", folders, Environment.MachineName); Workspace w2 = vcs.GetWorkspace("CreateDelete1_Workspace"); Assert.AreEqual("My Comment", w2.Comment); w1.Delete(); }
public void GetProjectProperties() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) { return; } TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); ProjectInfo p1 = css.GetProjectFromName(Environment.GetEnvironmentVariable("TFS_PROJECT")); string projectName = ""; string state = ""; int templateId = 0; ProjectProperty[] properties = null; css.GetProjectProperties(p1.Uri, out projectName, out state, out templateId, out properties); Assert.IsNotNull(projectName); }
static void Main(string[] args) { string projectName = args[0]; TeamFoundationServer tfs = new TeamFoundationServer(TFSSERVER); VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); PendingSet[] sets = versionControl.GetPendingSets(new String[] { "$/Projects/" + projectName }, RecursionType.Full); Console.WriteLine(versionControl.AuthenticatedUser + " pending changes for " + projectName + ":"); int total = 0; foreach (PendingSet set in sets) { if (set.Type == PendingSetType.Workspace && set.OwnerName == versionControl.AuthenticatedUser) { foreach (PendingChange pc in set.PendingChanges) { Console.WriteLine(pc.ServerItem); total++; } } } Console.WriteLine(total.ToString() + " total changes."); }
protected IEnumerable<MSChangeset> QueryAllChangesetsFromRevision(int revisionId) { var tfsClient = new TeamFoundationServer(repositoryUrl, credentials); tfsClient.Authenticate(); var vcs = (VersionControlServer) tfsClient.GetService(typeof (VersionControlServer)); var version = VersionSpec.Latest; var versionTo = VersionSpec.Latest; var versionFrom = new ChangesetVersionSpec(revisionId); const int deletionId = 0; const string user = null; IEnumerable changesets = vcs.QueryHistory(repositoryPath, version, deletionId, RecursionType.Full, user, versionFrom, versionTo, int.MaxValue, true, false); var retvalue = new List<MSChangeset>(); foreach (object item in changesets) retvalue.Add(item as MSChangeset); return retvalue; }
/// <summary> /// Create initial connection to the TFS 2008 Build Server. /// </summary> public void Connect() { TeamFoundationServer tfs = new TeamFoundationServer(TfsUrl); IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer)); buildQueue = buildServer.CreateQueuedBuildsView(TeamProject); // We are only interested in builds when they are finished or as they are in progress buildQueue.StatusFilter = QueueStatus.Completed | QueueStatus.InProgress; // Hook up our build queue listener. buildQueue.StatusChanged += new StatusChangedEventHandler(buildQueue_StatusChanged); try { buildQueue.Connect(); } catch (Exception ex) { } }
public override bool Execute() { try { TeamFoundationServer server = new TeamFoundationServer(tfsUrl, CredentialCache.DefaultNetworkCredentials); IGroupSecurityService gss = (IGroupSecurityService)server.GetService(typeof(IGroupSecurityService)); Identity ident = gss.ReadIdentity(SearchFactor.AccountName, WindowsAccountName, QueryMembership.None); MailAddress = ident.MailAddress; DisplayName = ident.DisplayName; return true; } catch (Exception ex) { Log.LogErrorFromException(ex, true); return false; } }
private string CreateTestRun() { bool projectFound = false; try { if (store == null) { server = new TeamFoundationServer(CurrentProject.DomainUri); server.Authenticate(); store = (WorkItemStore)server.GetService(typeof(WorkItemStore)); } } catch (Exception e) { return "Unable to connect to the TFS server: " + CurrentProject.DomainName + ". The error was: " + e.Message; } // Select the TFS project to connect to foreach (Project item in store.Projects) { if (item.Name.ToLower() == CurrentProject.ProjectName.ToLower()) { project = item; projectFound = true; break; } } if (projectFound) { WorkItemCollection workItemList = RetrieveTestCases(); foreach (WorkItem workItem in workItemList) { if (workItem.State != "Obsolete") { workItem.Open(); if (_settings.ExecutedByField != "") { workItem.Fields[_settings.ExecutedByField].Value = store.TeamFoundationServer.AuthenticatedUserDisplayName; } if (_settings.ExecutionStatusField != "") { workItem.Fields[_settings.ExecutionStatusField].Value = "Not Run"; } if (_settings.ExecutionEnvironmentField != "") { workItem.Fields[_settings.ExecutionEnvironmentField].Value = ""; } if (_settings.ExecutedInBuild != "") { workItem.Fields[_settings.ExecutedInBuild].Value = buildToPublish; } if (_settings.ExecutionTimeField != "") { workItem.Fields[_settings.ExecutionTimeField].Value = DateTime.Now.ToString(); } try { workItem.Save(); } catch { return "ERROR: Unable to create run"; } } } return "Run for build " + buildToPublish + " was created successfully."; } else { return "The project " + CurrentProject.ProjectName + " was not found."; } }
public void Workspace_GetViaInfo() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer)); WorkingFolder[] folders = new WorkingFolder[1]; string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT")); folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory); Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace", Environment.GetEnvironmentVariable("TFS_USERNAME"), "My Comment", folders, Environment.MachineName); //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME")); WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); Workspace w2 = info.GetWorkspace(tfs); // does info.GetWorkspace talk to the server and get the // mapped paths or no? ANSWER: NO IT DOESN'T string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt"); Assert.AreEqual(null, serverItem2); w1.Delete(); }
public void Workspace_RefreshMappings2() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer)); WorkingFolder[] folders = new WorkingFolder[1]; string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT")); folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory); Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace", Environment.GetEnvironmentVariable("TFS_USERNAME"), "My Comment", folders, Environment.MachineName); //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME")); WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); Workspace w2 = info.GetWorkspace(tfs); // this will talk to the server and get the mapped paths // BUT it will fail because we don't pass a full path like in RefreshMappings1 w2.RefreshMappings(); string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt"); Assert.IsNull(serverItem2); w1.Delete(); }
public void ConnectToTfsServer(string hostname, string teamCollection, string projectName, string buildDefinitionName = null) { _hostname = hostname; _isWebServer = _hostname.Contains("://"); try { string url; if (_isWebServer) { _hostname = _hostname.TrimEnd('\\', '/'); url = _hostname + "/" + teamCollection; _urlPrefix = hostname + "/" + teamCollection + "/" + projectName + "/_build#buildUri="; } else { url = "http://" + _hostname + ":8080/tfs/" + teamCollection; _urlPrefix = "http://" + hostname + ":8080/tfs/Build/Build.aspx?artifactMoniker="; } // Get a connection to the desired Team Foundation Server _tfServer = TeamFoundationServerFactory.GetServer(url, new UICredentialsProvider()); // Get a reference to a build service _buildServer = _tfServer.GetService<IBuildServer>(); // Retrieve a list of build definitions var buildDefs = _buildServer.QueryBuildDefinitions(projectName); if (buildDefs.Length != 0) { if (string.IsNullOrWhiteSpace(buildDefinitionName)) _buildDefinition = buildDefs[0]; else { foreach (var buildDefinition in buildDefs) { if (string.Compare(buildDefinition.Name, buildDefinitionName, true) == 0) { _buildDefinition = buildDefinition; return; } } } } } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
public void Workspace_TryGetWorkingFolderForServerItem() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer)); WorkingFolder[] folders = new WorkingFolder[2]; string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT")); folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory); string deeper = Path.Combine(Environment.CurrentDirectory, "deeper"); folders[1] = new WorkingFolder(serverItem + "/deeper", deeper); Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace", Environment.GetEnvironmentVariable("TFS_USERNAME"), "My Comment", folders, Environment.MachineName); WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); Workspace w2 = info.GetWorkspace(tfs); // this will talk to the server and get the mapped paths w2.RefreshMappings(); { string serverItem1 = String.Format("{0}/deeper/foo.txt", serverItem); WorkingFolder folder = w2.TryGetWorkingFolderForServerItem(serverItem1); Assert.AreEqual(deeper, folder.LocalItem); } { string serverItem1 = String.Format("junk/deeper/foo.txt", serverItem); WorkingFolder folder = w2.TryGetWorkingFolderForServerItem(serverItem1); Assert.IsNull(deeper); } w1.Delete(); }
public void ListProjects() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService) tfs.GetService(typeof(ICommonStructureService)); ProjectInfo[] projects = css.ListProjects(); foreach (ProjectInfo pinfo in projects) { Assert.IsNotNull(pinfo.Name); } }
public void GetService_CommonStructureService() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService) tfs.GetService(typeof(ICommonStructureService)); Assert.IsNotNull(css); }
public void GetProjectProperties() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) return; TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService) tfs.GetService(typeof(ICommonStructureService)); ProjectInfo p1 = css.GetProjectFromName(Environment.GetEnvironmentVariable("TFS_PROJECT")); string projectName = ""; string state = ""; int templateId = 0; ProjectProperty[] properties = null; css.GetProjectProperties(p1.Uri, out projectName, out state, out templateId, out properties); Assert.IsNotNull(projectName); }
private void QueryKicker() { TeamFoundationServer tfs = new TeamFoundationServer(Config["TFS.Server"]); VersionControlServer vc = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); string today = "D" + DateTime.Today.Month + "/" + DateTime.Today.Day + "/" + DateTime.Today.Year; //should only run thought this once b/c MaxCount is set to 1 C:\\Projects\\BillingAdmin\\Branches\\Development foreach (Changeset cs in vc.QueryHistory( "$/" + team_Project + "/Branches/" + build_Branch +"/*.*", VersionSpec.ParseSingleSpec(today, null), 0, RecursionType.Full, null, VersionSpec.ParseSingleSpec(today, null), null, 1, false, false)) #region QueryHistory Parameter list //public IEnumerable QueryHistory ( // string path, // VersionSpec version, // int deletionId, // RecursionType recursion, // string user, // VersionSpec versionFrom, // VersionSpec versionTo, // int maxCount, // bool includeChanges, // bool slotMode //) #endregion { nameOfKicker = RemoveDomainFromUsername(cs.Committer.ToString()); } tfs.Dispose(); }
private void GetKicker() { TeamFoundationServer tfs = new TeamFoundationServer(Config["TFS.Server"]); VersionControlServer vc = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); TeamProject tp = vc.GetTeamProject(team_Project); Changeset cs = tp.VersionControlServer.GetChangeset(tp.VersionControlServer.GetLatestChangesetId()); nameOfKicker = RemoveDomainFromUsername(cs.Committer.ToString()); }
// Crappy // http://www.codeproject.com/Questions/499216/ReadingplusaplusdocumentplusfromplusTFSplusserverp public static void CrappyKeepTrack() { Uri uri = new Uri("http://corfoundation:8080/tfs/COR-DEV-Produktion/"); using (Microsoft.TeamFoundation.Client.TeamFoundationServer tfs = Microsoft.TeamFoundation.Client.TeamFoundationServerFactory.GetServer(uri)) { Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore wit = (Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore)tfs.GetService(typeof(Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore)); Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemCollection result = wit.Query("SELECT * FROM WorkItems"); foreach (Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem wi in result) { foreach (Microsoft.TeamFoundation.WorkItemTracking.Client.Attachment attachment in wi.Attachments) { //do something Console.WriteLine(attachment.Name); } // Next attachment } // Next wi } // End Using tfs } // End Sub CrappyKeepTrack
//string tfsUrl = "http://*****:*****@"$/FORIS/Production/4.3 A1.1 Prd"; string localPath = @"c:\dev2\"; if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } List<WorkingFolder> wFolders = new List<WorkingFolder> { new WorkingFolder(serverPath, localPath) }; //vcs.CreateWorkspace("Tools.Net TfsCompare", Thread.CurrentPrincipal.Identity.ToString(), //"Created by Tools.Net Compare", wFolders, Environment.MachineName); try { //int currentOldest = vcs.GetLatestChangesetId(); //int notBefore = 237311; //if (notBefore >= currentOldest) //{ // // return notBefore; //} // LabelVersionSpec lSpecFrom = new LabelVersionSpec(); bool foundChanges = false; DateVersionSpec dSpecFrom = new DateVersionSpec(new DateTime(2009, 3, 12)); DateVersionSpec dSpecTo = new DateVersionSpec(DateTime.Now); foreach (Changeset latest in vcs.QueryHistory(serverPath, VersionSpec.Latest, 0, RecursionType.Full, null, dSpecFrom, dSpecTo, 1000, true, true)) { // we want to use the oldest starting point - if result is newer then use the older System.Console.WriteLine("Changeset found:" + latest.ChangesetId + " at date: " + latest.CreationDate); foreach (Change c in latest.Changes) { System.Console.WriteLine("\t" + c.Item.ServerItem); } } } catch (Exception ex) { System.Console.WriteLine(ex.ToString()); } System.Console.ReadKey(); }
private WorkItemStore ConnectToTfs() { tfs = TeamFoundationServerFactory.GetServer(options.ServerName); tfs.EnsureAuthenticated(); return (WorkItemStore) tfs.GetService(typeof (WorkItemStore)); }
static void Main(string[] args) { bool _debug = false; // string[] requiredOpts = new string[10] { "/teamproject", "/workspace", "/dir", "/id" }; if (args.Length < 1) { throw new ArgumentException("A start-up parameter is required."); } Dictionary<string, string> opts = new Dictionary<string,string>(); foreach (string a in args) { if (a.Contains("=")) { opts[a.Split('=')[0].ToLower()] = a.Split('=')[1]; } else { opts[a] = null; } if (_debug) { foreach (string k in opts.Keys) { Console.WriteLine(k + " => " + opts[k]); } } } if (opts.ContainsKey("/whatif")) { _debug = true; } TeamFoundationServer tfs = new TeamFoundationServer("HTTP://as73tfs01:8080"); VersionControlServer vc = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); TeamProject tp = vc.GetTeamProject(opts["/teamproject"]); Workspace ws = vc.GetWorkspace(opts["/workspace"]); Directory.SetCurrentDirectory(opts["/dir"]); foreach (string file in Directory.GetFiles(opts["/dir"])) { //Console.WriteLine(file + " => " + Path.GetExtension(file).ToString()); if(Path.GetExtension(file).Contains(opts["/id"])) { if (opts.ContainsKey("/pre") && !Path.GetFileName(file).Contains(opts["/pre"])) { if (_debug) { Console.WriteLine(Path.GetFileName(file) + " => " + opts["/pre"] + Path.GetFileName(file)); } else { ws.PendRename(Path.GetFileName(file), opts["/pre"] + Path.GetFileName(file)); } } if (opts.ContainsKey("/post") && !Path.GetFileName(file).Contains(opts["/post"])) { if (_debug) { Console.WriteLine(Path.GetFileName(file) + " => " + opts["/post"] + Path.GetFileName(file)); } else { ws.PendRename(Path.GetFileName(file), Path.GetFileName(file) + opts["/post"]); } } } //end if (file } //end foreach }