private static bool GetSettings(string filePath) { if (!File.Exists(filePath)) { WriteLog(LogLevel.Error, string.Format("The file provided cannot be found ({0})", filePath)); return(false); } _config = new PermissionCopyConfiguration(); try { // Read configuration file and transfor to PermissionCopyConfiguration object XmlSerializer x = new XmlSerializer(_config.GetType()); using (StreamReader sr = new StreamReader(filePath)) { _config = (PermissionCopyConfiguration)x.Deserialize(sr); _tfs = new TfsTeamProjectCollection(new Uri(_config.vstsUri)); _ims = (IIdentityManagementService)_tfs.GetService <IIdentityManagementService>(); _wistore = new WorkItemStore(_tfs, WorkItemStoreFlags.BypassRules); _es = (IEventService)_tfs.GetService <IEventService>(); _excludedGroups = _config.excludedGroups; _securityServiceGroup = _config.vstsSecurityServiceGroup; _userMappings = _config.userMappings; } } catch (Exception ex) { WriteLog(LogLevel.Error, string.Format("An error occurred reading the configuration file. Please verify the format. The error is:\n{0}", ex.ToString())); return(false); } _ics = (ICommonStructureService4)_tfs.GetService <ICommonStructureService4>(); _teamProjects = _ics.ListAllProjects().ToList(); return(true); }
public void IncludeAllAreas() { try { TfsTeamProjectCollection tpc = TfsConnect(); ICommonStructureService4 css = tpc.GetService <ICommonStructureService4>(); ProjectInfo project = css.GetProjectFromName(TeamProject); TeamSettingsConfigurationService teamConfigService = tpc.GetService <TeamSettingsConfigurationService>(); var teamConfigs = teamConfigService.GetTeamConfigurationsForUser(new string[] { project.Uri }); foreach (TeamConfiguration teamConfig in teamConfigs) { if (teamConfig.IsDefaultTeam) { TeamSettings settings = teamConfig.TeamSettings; foreach (TeamFieldValue tfv in settings.TeamFieldValues) { tfv.IncludeChildren = true; teamConfigService.SetTeamSettings(teamConfig.TeamId, settings); } } } Console.WriteLine(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); throw; } }
public TeamWrapper(Uri collectionUri, string teamProjectName) { this.teamProjectCollection = new TfsTeamProjectCollection(collectionUri); this.teamService = this.teamProjectCollection.GetService <TfsTeamService>(); this.identityManagementService = this.teamProjectCollection.GetService <IIdentityManagementService>(); ICommonStructureService4 cssService = this.teamProjectCollection.GetService <ICommonStructureService4>(); this.projectInfo = cssService.GetProjectFromName(teamProjectName); }
private static void CreateIterationNodes(XmlNode node, ICommonStructureService4 css, NodeInfo pathRoot) { int myNodeCount = node.ChildNodes.Count; for (int i = 0; i < myNodeCount; i++) { XmlNode childNode = node.ChildNodes[i]; NodeInfo createdNode; var name = childNode.Attributes["Name"].Value; try { var uri = css.CreateNode(name, pathRoot.Uri); Console.WriteLine("NodeCreated:" + uri); createdNode = css.GetNode(uri); } catch (Exception) { //node already exists createdNode = css.GetNodeFromPath(pathRoot.Path + @"\" + name); //continue; } DateTime?startDateToUpdate = null; if (!createdNode.StartDate.HasValue) { var startDate = childNode.Attributes["StartDate"]; DateTime startDateParsed; if (startDate != null && DateTime.TryParse(startDate.Value, out startDateParsed)) { startDateToUpdate = startDateParsed; } } DateTime?finishDateToUpdate = null; if (!createdNode.FinishDate.HasValue) { DateTime finishDateParsed; var finishDate = childNode.Attributes["FinishDate"]; if (finishDate != null && DateTime.TryParse(finishDate.Value, out finishDateParsed)) { finishDateToUpdate = finishDateParsed; } } if (startDateToUpdate.HasValue || finishDateToUpdate.HasValue) { css.SetIterationDates(createdNode.Uri, startDateToUpdate, finishDateToUpdate); } if (createdNode != null && node.HasChildNodes) { foreach (XmlNode subChildNode in childNode.ChildNodes) { CreateIterationNodes(subChildNode, css, createdNode); } } } }
public GroupManager(string teamProjectCollectionUrl, string teamProjectName) { _teamProjectCollectionUrl = teamProjectCollectionUrl; _teamProjectName = teamProjectName; _tfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_teamProjectCollectionUrl)); _tfsTeamProjectCollection.EnsureAuthenticated(); _commonStructureService4 = _tfsTeamProjectCollection.GetService <ICommonStructureService4>(); _projectInfo = _commonStructureService4.GetProjectFromName(_teamProjectName); _identityManagementService = _tfsTeamProjectCollection.GetService <IIdentityManagementService>(); }
public CachedCapacitySearcher( MemoryCache cache, TfsTeamProjectCollection connection, WorkItemStore itemStore = null, IIdentityManagementService2 managementService = null, TfsTeamService teamService = null, WorkHttpClient workClient = null, ICommonStructureService4 structureService = null) : base(connection, itemStore, managementService, teamService, workClient, structureService) { _cache = cache; }
// source tree, target tfs public void GenerateIterations(XmlNode tree, string sourceProjectName) { ICommonStructureService4 css = (ICommonStructureService4)tfs.GetService(typeof(ICommonStructureService4)); string rootNodePath = string.Format("\\{0}\\Iteration", projectName); var pathRoot = css.GetNodeFromPath(rootNodePath); string firstReleaseName = tree.FirstChild.FirstChild.Attributes["Name"].Value; css.CreateNode(firstReleaseName, pathRoot.Uri, DateTime.Parse(tree.FirstChild.FirstChild.Attributes["StartDate"].Value), DateTime.Parse(tree.FirstChild.FirstChild.Attributes["FinishDate"].Value)); string firstReleaseNodePath = string.Format("\\{0}\\Iteration\\{1}", projectName, firstReleaseName); var firstReleasePathRoot = css.GetNodeFromPath(firstReleaseNodePath); if (tree.FirstChild != null) { int myNodeCount = tree.FirstChild.FirstChild.ChildNodes[0].ChildNodes.Count; for (int i = 0; i < myNodeCount; i++) { XmlNode Node = tree.FirstChild.FirstChild.ChildNodes[0].ChildNodes[i]; try { css.CreateNode(Node.Attributes["Name"].Value, firstReleasePathRoot.Uri, DateTime.Parse(Node.Attributes["StartDate"].Value), DateTime.Parse(Node.Attributes["FinishDate"].Value)); } catch (Exception ex) { //node already exists logger.Info("RK: Iteration already exists: " + ex); continue; } } } else { try { logger.Info("RK: " + tree.Name); } catch (Exception ex) { logger.Info("RK: " + ex); } try { logger.Info("RK2: " + tree.Attributes["Name"].Value); } catch (Exception ex) { logger.Info("RK: " + ex); } } RefreshCache(); }
public void GenerateIterations(XmlNode tree, string sourceProjectName) { ICommonStructureService4 css = (ICommonStructureService4)tfs.GetService(typeof(ICommonStructureService4)); string rootNodePath = string.Format("\\{0}\\Iteration", projectName); var pathRoot = css.GetNodeFromPath(rootNodePath); if (tree.FirstChild != null) { var firstChild = tree.FirstChild; CreateIterationNodes(firstChild, css, pathRoot); } RefreshCache(); }
public CapacitySearcher(TfsTeamProjectCollection connection, WorkItemStore itemStore = null, IIdentityManagementService2 managementService = null, TfsTeamService teamService = null, WorkHttpClient workClient = null, ICommonStructureService4 structureService = null) { _connection = connection; _itemStore = itemStore; _managementService = managementService; _teamService = teamService; _workClient = workClient; _structureService = structureService; }
public TeamManager(string teamProjectCollectionUrl, string teamProjectName, string softwareProjectName, string softwareProjectDescription) { _teamProjectCollectionUrl = teamProjectCollectionUrl; _teamProjectName = teamProjectName; _softwareProjectName = softwareProjectName; _softwareProjectDescription = softwareProjectDescription; _tfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_teamProjectCollectionUrl)); _tfsTeamProjectCollection.EnsureAuthenticated(); _commonStructureService4 = _tfsTeamProjectCollection.GetService <ICommonStructureService4>(); _tfsTeamService = _tfsTeamProjectCollection.GetService <TfsTeamService>(); _teamSettingsConfigurationService = _tfsTeamProjectCollection.GetService <TeamSettingsConfigurationService>(); _projectInfo = _commonStructureService4.GetProjectFromName(_teamProjectName); }
public static IEnumerable <IterationItem> GetIterationsWithDates(this ICommonStructureService4 css, string projectUri) { NodeInfo[] structures = css.ListStructures(projectUri); NodeInfo iterations = structures.FirstOrDefault(n => n.StructureType.Equals("ProjectLifecycle")); List <IterationItem> schedule = null; if (iterations != null) { string projectName = css.GetProject(projectUri).Name; XmlElement iterationsTree = css.GetNodesXml(new[] { iterations.Uri }, true); GetIterationDates(iterationsTree.ChildNodes[0], projectName, ref schedule); } return(schedule); }
private static void FillIterations(ICommonStructureService4 pCss, Node pNode, List <Iteration> pIts) { var _nodeInfo = pCss.GetNode(pNode.Uri.AbsoluteUri); pIts.Add(new Iteration { Path = _nodeInfo.Path, DateFrom = (_nodeInfo.StartDate == null) ? DateTime.MinValue : (DateTime)_nodeInfo.StartDate, DateTo = (_nodeInfo.FinishDate == null) ? DateTime.MinValue : (DateTime)_nodeInfo.FinishDate }); if (pNode.HasChildNodes) { foreach (Node _node in pNode.ChildNodes) { FillIterations(pCss, _node, pIts); } } }
public override int Execute(StageConfiguration configuration) { var config = ((AreasAndIterationsStageConfiguration)configuration); bool areas = options.HasFlag(StageOptions.Areas); bool iterations = options.HasFlag(StageOptions.Iterations); this.testMode = configuration.TestOnly; var sourceWIStore = sourceConn.Collection.GetService <WorkItemStore>(); var destWIStore = destConn.Collection.GetService <WorkItemStore>(); var sourceProject = sourceWIStore.Projects[sourceConn.ProjectName]; var destProject = destWIStore.Projects[destConn.ProjectName]; eventSink.ReadingAreaAndIterationInfoFromSource(); sourceCSS = sourceConn.Collection.GetService <ICommonStructureService4>(); destCSS = destConn.Collection.GetService <ICommonStructureService4>(); foreach (NodeInfo info in destCSS.ListStructures(destProject.Uri.ToString())) { if (info.StructureType == "ProjectModelHierarchy") { rootAreaNode = info; } else if (info.StructureType == "ProjectLifecycle") { rootIterationNode = info; } } if (areas) { eventSink.SyncingAreas(); SyncNodes(sourceProject.AreaRootNodes); } if (iterations) { eventSink.SyncingIterations(); SyncNodes(sourceProject.IterationRootNodes); } return(saveErrors); }
public TeamManager(Dto.ProjectDetail projectDetail, TfsApi.Contracts.ITfsCredentials tfsCredentials) { this.tfsCredentials = tfsCredentials; this.projectDetail = projectDetail; this.tfsTeamProjectCollection = TfsApi.Administration.TfsTeamProjectCollectionFactory.GetTeamProjectCollection(this.projectDetail.CollectionUri, this.tfsCredentials); this.teamSettingsConfigurationService = this.tfsTeamProjectCollection.GetService<TeamSettingsConfigurationService>(); this.commonStructureService = (ICommonStructureService4)this.tfsTeamProjectCollection.GetService(typeof(ICommonStructureService4)); this.projectInfo = this.commonStructureService.GetProjectFromName(this.projectDetail.ProjectName); this.groupSecurityService = (IGroupSecurityService)this.tfsTeamProjectCollection.GetService<IGroupSecurityService>(); this.TfsTeamService = (Microsoft.TeamFoundation.Client.TfsTeamService)this.tfsTeamProjectCollection.GetService(typeof(Microsoft.TeamFoundation.Client.TfsTeamService)); }
public AreaManager(ProjectDetail projectDetail, ITfsCredentials tfsCredentials) { this.projectDetail = projectDetail; this.tfsTeamProjectCollection = TfsApi.Administration.TfsTeamProjectCollectionFactory.GetTeamProjectCollection(this.projectDetail.CollectionUri, tfsCredentials); this.teamConfig = this.tfsTeamProjectCollection.GetService<TeamSettingsConfigurationService>(); this.commonStructureService = (ICommonStructureService4)this.tfsTeamProjectCollection.GetService(typeof(ICommonStructureService4)); this.projectInfo = this.commonStructureService.GetProjectFromName(this.projectDetail.ProjectName); foreach (TeamConfiguration item in this.teamConfig.GetTeamConfigurationsForUser(new[] { this.projectInfo.Uri })) { this.teamConfiguration = item; break; } }
public AreaManager(ProjectDetail projectDetail, ITfsCredentials tfsCredentials) { this.projectDetail = projectDetail; this.tfsTeamProjectCollection = TfsApi.Administration.TfsTeamProjectCollectionFactory.GetTeamProjectCollection(this.projectDetail.CollectionUri, tfsCredentials); this.teamConfig = this.tfsTeamProjectCollection.GetService <TeamSettingsConfigurationService>(); this.commonStructureService = (ICommonStructureService4)this.tfsTeamProjectCollection.GetService(typeof(ICommonStructureService4)); this.projectInfo = this.commonStructureService.GetProjectFromName(this.projectDetail.ProjectName); foreach (TeamConfiguration item in this.teamConfig.GetTeamConfigurationsForUser(new[] { this.projectInfo.Uri })) { this.teamConfiguration = item; break; } }
public TeamManager(Dto.ProjectDetail projectDetail, TfsApi.Contracts.ITfsCredentials tfsCredentials) { this.tfsCredentials = tfsCredentials; this.projectDetail = projectDetail; this.tfsTeamProjectCollection = TfsApi.Administration.TfsTeamProjectCollectionFactory.GetTeamProjectCollection(this.projectDetail.CollectionUri, this.tfsCredentials); this.teamSettingsConfigurationService = this.tfsTeamProjectCollection.GetService <TeamSettingsConfigurationService>(); this.commonStructureService = (ICommonStructureService4)this.tfsTeamProjectCollection.GetService(typeof(ICommonStructureService4)); this.projectInfo = this.commonStructureService.GetProjectFromName(this.projectDetail.ProjectName); this.groupSecurityService = (IGroupSecurityService)this.tfsTeamProjectCollection.GetService <IGroupSecurityService>(); this.TfsTeamService = (Microsoft.TeamFoundation.Client.TfsTeamService) this.tfsTeamProjectCollection.GetService(typeof(Microsoft.TeamFoundation.Client.TfsTeamService)); }
public void SetPlanningIterations() { TfsTeamProjectCollection tpc = TfsConnect(); ICommonStructureService4 css = tpc.GetService <ICommonStructureService4>(); ProjectInfo project = css.GetProjectFromName(TeamProject); TeamSettingsConfigurationService teamConfigService = tpc.GetService <TeamSettingsConfigurationService>(); var teamConfigs = teamConfigService.GetTeamConfigurationsForUser(new string[] { project.Uri }); foreach (TeamConfiguration teamConfig in teamConfigs) { if (teamConfig.IsDefaultTeam) { TeamSettings settings = teamConfig.TeamSettings; settings.IterationPaths = PlanningSprints.ToArray(); teamConfigService.SetTeamSettings(teamConfig.TeamId, settings); Console.Write(new string('.', PlanningSprints.Count)); } } Console.WriteLine(string.Format(" ({0} iterations)", PlanningSprints.Count)); }
public Server(Uri tfsUrl, string projectName, System.Net.ICredentials credentials) { this.ResetDetails(); try { teamUri = tfsUrl; this.projectName = projectName; tpc = new TfsTeamProjectCollection(teamUri, credentials); tpc.Connect(ConnectOptions.IncludeServices); workItemStore = tpc.GetService <WorkItemStore>(); linkTypes = new List <WorkItemLinkType>(workItemStore.WorkItemLinkTypes); this.executor = new TFS.Execution.Executor(); this.isValid = true; css4 = tpc.GetService <ICommonStructureService4>(); } catch { this.ResetDetails(); } }
private void CreateNode(ICommonStructureService4 css, string nodeName, NodeInfo rootNode) { char _delimeter = '|'; var name = String.Empty; DateTime?startDate = null; DateTime?endDate = null; if (nodeName.Contains(_delimeter)) { var parts = nodeName.Split(_delimeter); name = parts[0]; startDate = DateTime.Parse(parts[1]); endDate = DateTime.Parse(parts[2]); } else { name = nodeName; } if (!name.Contains("\\")) { try { var iterationUri = css.CreateNode(name, rootNode.Uri); css.SetIterationDates(iterationUri, startDate, endDate); } catch (Exception ex) when(ex.ToString().Contains("TF200020")) { Console.WriteLine("Node Exists. Skipping..."); } } else { int lastBackslash = name.LastIndexOf("\\"); NodeInfo info = css.GetNodeFromPath(rootNode.Path + "\\" + name.Substring(0, lastBackslash)); var iterationUri = css.CreateNode(name.Substring(lastBackslash + 1), info.Uri); css.SetIterationDates(iterationUri, startDate, endDate); } }
public void Connect(string url, string project, string workItemQuery, string ignoreRemainingArea, string activeState, string closedState) { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException("url"); } if (string.IsNullOrWhiteSpace(project)) { throw new ArgumentNullException("project"); } if (string.IsNullOrWhiteSpace(workItemQuery)) { throw new ArgumentNullException("workItemQuery"); } if (string.IsNullOrWhiteSpace(ignoreRemainingArea)) { throw new ArgumentNullException("ignoreRemainingArea"); } if (string.IsNullOrWhiteSpace(activeState)) { throw new ArgumentNullException("activeState"); } if (string.IsNullOrWhiteSpace(closedState)) { throw new ArgumentNullException("closedState"); } _url = url; _project = project; _ignoreRemainingArea = ignoreRemainingArea; _activeState = activeState; _closedState = closedState; _tfs = new TfsTeamProjectCollection(new Uri(url)); _tfs.EnsureAuthenticated(); _workItemStore = _tfs.GetService <WorkItemStore>(); _commonStructureService = _tfs.GetService <ICommonStructureService4>(); _workitemQueryText = GetWorkitemQueryText(workItemQuery); }
protected override void EntryForProcessorType(IProcessor processor) { if (processor is null) { IMigrationEngine engine = Services.GetRequiredService <IMigrationEngine>(); if (_sourceCommonStructureService is null) { _sourceCommonStructureService = (ICommonStructureService4)engine.Source.GetService <ICommonStructureService4>(); _sourceProjectInfo = _sourceCommonStructureService.GetProjectFromName(engine.Source.Config.AsTeamProjectConfig().Project); _sourceRootNodes = _sourceCommonStructureService.ListStructures(_sourceProjectInfo.Uri); _sourceLanguageMaps = engine.Source.Config.AsTeamProjectConfig().LanguageMaps; _sourceProjectName = engine.Source.Config.AsTeamProjectConfig().Project; } if (_targetCommonStructureService is null) { _targetCommonStructureService = (ICommonStructureService4)engine.Target.GetService <ICommonStructureService4>(); _targetLanguageMaps = engine.Target.Config.AsTeamProjectConfig().LanguageMaps; _targetProjectName = engine.Target.Config.AsTeamProjectConfig().Project; } } else { if (_sourceCommonStructureService is null) { var source = (TfsWorkItemEndpoint)processor.Source; _sourceCommonStructureService = (ICommonStructureService4)source.TfsCollection.GetService <ICommonStructureService>(); _sourceProjectInfo = _sourceCommonStructureService.GetProjectFromName(source.Project); _sourceRootNodes = _sourceCommonStructureService.ListStructures(_sourceProjectInfo.Uri); _sourceLanguageMaps = source.Options.LanguageMaps; _sourceProjectName = source.Project; } if (_targetCommonStructureService is null) { var target = (TfsWorkItemEndpoint)processor.Target; _targetCommonStructureService = (ICommonStructureService4)target.TfsCollection.GetService <ICommonStructureService4>(); _targetLanguageMaps = target.Options.LanguageMaps; _targetProjectName = target.Project; } } }
public IterationModel GetIteration(Guid collectionId, int projectId, string iterationPath) { using (var server = GetServer()) { TfsTeamProjectCollection collection = server.GetTeamProjectCollection(collectionId); WorkItemStore wiStore = collection.GetService <WorkItemStore>(); string query = @"SELECT * " + "FROM WorkItems " + "WHERE ([System.WorkItemType] = 'Bug' OR [System.WorkItemType] = 'Product Backlog Item' OR [System.WorkItemType] = 'Task') " + "AND [System.IterationPath] = '@IterationPath' " + "ORDER BY [System.WorkItemType]"; query = query.Replace("@IterationPath", iterationPath); var items = wiStore.Query(query); ICommonStructureService4 css = collection.GetService <ICommonStructureService4>(); var path = GetFullIterationPath(iterationPath); NodeInfo pathRoot = css.GetNodeFromPath(path); IterationModel model = Map(pathRoot); model.WorkItems = Map(items); return(model); } }
private void Init() { if (TfsAddress == null || TfsAddress == string.Empty) { return; } string serverName = Regex.Replace(TfsAddress.ToLower(), @"\A[h][t][t][p][:]\/\/|[:][8][0][8][0]\S+\z", string.Empty); Uri tfsUri = new Uri(TfsAddress); TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); ReadOnlyCollection <CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren( new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); ProjectCollections = new Dictionary <string, TfsTeamProjectCollection>(); TeamProjects = new Dictionary <string, ProjectInfo[]>(); foreach (CatalogNode collectionNode in collectionNodes) { #region Init TeamProject // Use the InstanceId property to get the team project collection Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); TfsTeamProjectCollection projectCollection = configurationServer.GetTeamProjectCollection(collectionId); string nodeCollectionName = projectCollection.Uri.ToString().Replace(tfsUri + "/", string.Empty); #region Acting behalf of PM user //var identityService = teamProjectCollection.GetService<IIdentityManagementService>(); //var identity = identityService.ReadIdentity( // IdentitySearchFactor.AccountName, // "ProjectManager", // MembershipQuery.None, // ReadIdentityOptions.None); //var impersonatedTeamProjectCollection = new TfsTeamProjectCollection(teamProjectCollection.Uri, identity.Descriptor); //teamProjectCollection = impersonatedTeamProjectCollection; #endregion ProjectCollections.Add(nodeCollectionName, projectCollection); // Retrieve team projects ICommonStructureService4 css4 = projectCollection.GetService <ICommonStructureService4>(); ProjectInfo[] projectInfos = css4.ListAllProjects(); TeamProjects.Add(nodeCollectionName, projectInfos); WorkItemStore = projectCollection.GetService <WorkItemStore>(); //WorkItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore)); if (WorkItemStore == null) { throw new Exception("WorkItemStore not found!"); } CommonStructureService4 = projectCollection.GetService <ICommonStructureService4>(); #region Identities IIdentityManagementService identityManagementSrv = WorkItemStore.TeamProjectCollection.GetService <IIdentityManagementService>(); TeamFoundationIdentity _usersGroup = identityManagementSrv .ReadIdentity(IdentitySearchFactor.AccountName, "[" + nodeCollectionName + "]\\Project Collection Valid Users", MembershipQuery.Expanded, ReadIdentityOptions.None); TeamFoundationIdentity[] groupMember = identityManagementSrv.ReadIdentities(_usersGroup.Members, MembershipQuery.None, ReadIdentityOptions.None) .Where(member => member.IsContainer == false && member.UniqueName != "Domain\\UserName" && Regex.IsMatch(member.UniqueName, @"\G(\A[D][o][m][a][i][n]\\\D+\z)", RegexOptions.IgnoreCase)).ToArray(); #endregion if (!ProjectCollections.Any()) { string exceptionMessage = string.Format("Tfs team project collection with \"{0}\" name not found", nodeCollectionName); string projectCollectionsText = "projectCollections : \n" + ProjectCollections.Keys.Aggregate((str, next) => str = str + Environment.NewLine + next); string logText = string.Format("{0}\n\n{1}", exceptionMessage, projectCollectionsText); throw new Exception(exceptionMessage); } #endregion #region Init VersionControl VersionControlServer = projectCollection.GetService <VersionControlServer>(); #endregion #region Init Workspace string workspaceName = string.Format("{0}", Environment.MachineName); Workspace = VersionControlServer.GetWorkspace(workspaceName, VersionControlServer.AuthorizedUser); #endregion } }
private void CreateNode(ICommonStructureService4 css, string nodeName, NodeInfo rootNode) { char _delimeter = '|'; var name = String.Empty; DateTime? startDate = null; DateTime? endDate = null; if (nodeName.Contains(_delimeter)) { var parts = nodeName.Split(_delimeter); name = parts[0]; startDate = DateTime.Parse(parts[1]); endDate = DateTime.Parse(parts[2]); } else { name = nodeName; } if (!name.Contains("\\")) { try { var iterationUri = css.CreateNode(name, rootNode.Uri); css.SetIterationDates(iterationUri, startDate, endDate); } catch(Exception ex) when (ex.ToString().Contains("TF200020")) { Console.WriteLine("Node Exists. Skipping..."); } } else { int lastBackslash = name.LastIndexOf("\\"); NodeInfo info = css.GetNodeFromPath(rootNode.Path + "\\" + name.Substring(0, lastBackslash)); var iterationUri = css.CreateNode(name.Substring(lastBackslash + 1), info.Uri); css.SetIterationDates(iterationUri, startDate, endDate); } }
internal void UpdateIteration(string iterationPath, DateTime dateTime1, DateTime dateTime2) { ICommonStructureService4 css = tfs.GetService <ICommonStructureService4>(); css.SetIterationDates(iterationPath, dateTime1, dateTime2); }
public void CreateIterations() { try { TfsTeamProjectCollection tpc = TfsConnect(); DateTime startDate = DateTime.Today; int count = 0; // Get service and hierarchy ICommonStructureService4 css = tpc.GetService <ICommonStructureService4>(); ProjectInfo project = css.GetProjectFromName(TeamProject); NodeInfo[] hierarchy = css.ListStructures(project.Uri); XmlElement tree; if (hierarchy[0].Name.ToLower() == "iteration") { tree = css.GetNodesXml(new string[] { hierarchy[0].Uri }, true); } else { tree = css.GetNodesXml(new string[] { hierarchy[1].Uri }, true); } string parentUri = tree.FirstChild.Attributes["NodeID"].Value; int lastSprint = 1; for (int release = 1; release <= TotalReleases; release++) { string releaseUri = css.CreateNode("Release " + release.ToString(), parentUri); css.SetIterationDates(releaseUri, startDate, startDate.AddDays(SprintsPerRelease * WeeksPerSprint * 7 - 1)); for (int sprint = 1; sprint <= SprintsPerRelease; sprint++) { string sprintUri; count++; Console.Write("."); if (ResetSprintsEachRelease) { sprintUri = css.CreateNode("Sprint " + sprint.ToString(), releaseUri); } else { sprintUri = css.CreateNode("Sprint " + lastSprint, releaseUri); } css.SetIterationDates(sprintUri, startDate, startDate.AddDays(WeeksPerSprint * 7 - 1)); startDate = startDate.AddDays(WeeksPerSprint * 7); lastSprint++; } } // RefreshCache and SyncToCache WorkItemStore store = new WorkItemStore(tpc); store.RefreshCache(); store.SyncToCache(); Console.WriteLine(string.Format(" ({0} releases, {1} sprints created)", TotalReleases, count)); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); throw; } }
public TfsConnection() { _projectTeamDictionary = new Dictionary <ProjectInfo, List <TeamFoundationTeam> >(); try { TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(Settings.TfsConnectionUri), new Credentials()); tpc.EnsureAuthenticated(); ICommonStructureService4 css = tpc.GetService <ICommonStructureService4>(); if (Settings.ProjectNames.IsNullOrEmpty()) { _projectTeamDictionary = css.ListAllProjects() .GroupBy(projectInfo => projectInfo) .ToDictionary(projectInfo => projectInfo.Key, projectInfo => new List <TeamFoundationTeam>()); } else { string[] projectNames = Settings.ProjectNames.Split(','); foreach (string projectName in projectNames) { if (!_projectTeamDictionary.ContainsKey(css.GetProjectFromName(projectName))) { _projectTeamDictionary.Add(css.GetProjectFromName(projectName), new List <TeamFoundationTeam>()); } } } foreach (ProjectInfo projectInfo in _projectTeamDictionary.Keys) { TfsTeamService tts = tpc.GetService <TfsTeamService>(); List <TeamFoundationTeam> teamList = new List <TeamFoundationTeam>(); teamList = tts.QueryTeams(projectInfo.Uri).ToList(); if (Settings.TeamNames.IsNullOrEmpty()) { foreach (TeamFoundationTeam team in teamList) { Console.WriteLine(" Team: " + team.Name); List <TeamFoundationIdentity> members = team.GetMembers(tpc, MembershipQuery.Expanded).ToList(); if (members.Exists(member => member.TeamFoundationId.Equals(tpc.AuthorizedIdentity.TeamFoundationId))) { _projectTeamDictionary[projectInfo].Add(team); } } } else { string[] teamNames = Settings.TeamNames.Split(','); foreach (string teamName in teamNames) { _projectTeamDictionary[projectInfo].AddRange(teamList.FindAll(x => x.Name.Equals(teamName))); } } } } catch (Microsoft.TeamFoundation.TeamFoundationServiceUnavailableException tfsUnavailableException) { throw new Microsoft.TeamFoundation.TeamFoundationServiceUnavailableException(tfsUnavailableException.Message); } }
private void BuildIterationTree(Dictionary <string, IterationInfo> result, NodeCollection nodes, ICommonStructureService4 css) { foreach (Node node in nodes) { var nodeInfo = css.GetNode(node.Uri.ToString()); result.Add(node.Path, new IterationInfo(nodeInfo)); BuildIterationTree(result, node.ChildNodes, css); } }
public void Connect(string url, string project, string workItemQuery, string ignoreRemainingArea, string activeState, string closedState) { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException("url"); } if (string.IsNullOrWhiteSpace(project)) { throw new ArgumentNullException("project"); } if (string.IsNullOrWhiteSpace(workItemQuery)) { throw new ArgumentNullException("workItemQuery"); } if (string.IsNullOrWhiteSpace(ignoreRemainingArea)) { throw new ArgumentNullException("ignoreRemainingArea"); } if (string.IsNullOrWhiteSpace(activeState)) { throw new ArgumentNullException("activeState"); } if (string.IsNullOrWhiteSpace(closedState)) { throw new ArgumentNullException("closedState"); } _url = url; _project = project; _ignoreRemainingArea = ignoreRemainingArea; _activeState = activeState; _closedState = closedState; _tfs = new TfsTeamProjectCollection(new Uri(url)); _tfs.EnsureAuthenticated(); _workItemStore = _tfs.GetService<WorkItemStore>(); _commonStructureService = _tfs.GetService<ICommonStructureService4>(); _workitemQueryText = GetWorkitemQueryText(workItemQuery); }
private static void CreateIterationNodes(XmlNode node, ICommonStructureService4 css, NodeInfo pathRoot) { int myNodeCount = node.ChildNodes.Count; for (int i = 0; i < myNodeCount; i++) { XmlNode childNode = node.ChildNodes[i]; NodeInfo createdNode; var name = childNode.Attributes["Name"].Value; try { var uri = css.CreateNode(name, pathRoot.Uri); Console.WriteLine("NodeCreated:" + uri); createdNode = css.GetNode(uri); } catch (Exception) { //node already exists createdNode = css.GetNodeFromPath(pathRoot.Path + @"\" + name); //continue; } DateTime? startDateToUpdate = null; if (!createdNode.StartDate.HasValue) { var startDate = childNode.Attributes["StartDate"]; DateTime startDateParsed; if (startDate != null && DateTime.TryParse(startDate.Value, out startDateParsed)) startDateToUpdate = startDateParsed; } DateTime? finishDateToUpdate = null; if (!createdNode.FinishDate.HasValue) { DateTime finishDateParsed; var finishDate = childNode.Attributes["FinishDate"]; if (finishDate != null && DateTime.TryParse(finishDate.Value, out finishDateParsed)) finishDateToUpdate = finishDateParsed; } if (startDateToUpdate.HasValue || finishDateToUpdate.HasValue) css.SetIterationDates(createdNode.Uri, startDateToUpdate, finishDateToUpdate); if (createdNode != null && node.HasChildNodes) { foreach (XmlNode subChildNode in childNode.ChildNodes) { CreateIterationNodes(subChildNode, css, createdNode); } } } }
private static IEnumerable<ScheduleInfo> GetIterationDates(ICommonStructureService4 css, string projectUri) { NodeInfo[] structures = css.ListStructures(projectUri); NodeInfo iterations = structures.FirstOrDefault(n => n.StructureType.Equals("ProjectLifecycle")); List<ScheduleInfo> schedule = null; if (iterations != null) { string projectName = css.GetProject(projectUri).Name; XmlElement iterationsTree = css.GetNodesXml(new[] { iterations.Uri }, true); GetIterationDates(iterationsTree.ChildNodes[0], projectName, ref schedule); } return schedule.Where(s => s.StartDate != null && s.EndDate != null); }