private ITestManagementTeamProject2 GetTestProject() { var collectionUri = SpecFlow2TFSConfig.TFS_URL + "/" + SpecFlow2TFSConfig.COLLECTION.Substring(SpecFlow2TFSConfig.COLLECTION.LastIndexOf('\\') + 1); TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri)); WorkItemStore workItemStore = new WorkItemStore(tpc); Project project = null; foreach (Project p in workItemStore.Projects) { if (p.Name == SpecFlow2TFSConfig.PROJECT) { project = p; break; } } if (project == null) { throw new NullReferenceException("no project found for the name " + SpecFlow2TFSConfig.PROJECT); } // get test management service ITestManagementService2 test_service = (ITestManagementService2)tpc.GetService(typeof(ITestManagementService2)); ITestManagementTeamProject2 test_project = test_service.GetTeamProject(project); return test_project; }
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 Validation() { _tfsServer = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConfigurationManager.AppSettings["TfsServer"])); _vsoServer = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConfigurationManager.AppSettings["VsoServer"])); _vsoStore = _vsoServer.GetService<WorkItemStore>(); _tfsStore = _tfsServer.GetService<WorkItemStore>(); var actionValue = ConfigurationManager.AppSettings["Action"]; if (actionValue.Equals("validate", StringComparison.OrdinalIgnoreCase)) { _action = Action.Validate; } else { _action = Action.Compare; } var runDateTime = DateTime.Now.ToString("yyyy-MM-dd-HHmmss"); var dataFilePath = ConfigurationManager.AppSettings["DataFilePath"]; var dataDir = string.IsNullOrWhiteSpace(dataFilePath) ? Directory.GetCurrentDirectory() : dataFilePath; var dirName = string.Format("{0}\\Log-{1}",dataDir,runDateTime); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } _errorLog = new Logging(string.Format("{0}\\Error.txt", dirName)); _statusLog = new Logging(string.Format("{0}\\Status.txt", dirName)); _fullLog = new Logging(string.Format("{0}\\FullLog.txt", dirName)); _taskList = new List<Task>(); if (!_action.Equals(Action.Compare)) { return; } _valFieldErrorLog = new Logging(string.Format("{0}\\FieldError.txt", dirName)); _valTagErrorLog = new Logging(string.Format("{0}\\TagError.txt", dirName)); _valPostMigrationUpdateLog = new Logging(string.Format("{0}\\PostMigrationUpdate.txt", dirName)); _imageLog = new Logging(string.Format("{0}\\ItemsWithImage.txt", dirName)); _commonFields = new List<string>(); _itemTypesToValidate = new List<string>(); var fields = ConfigurationManager.AppSettings["CommonFields"].Split(','); foreach (var field in fields) { _commonFields.Add(field); } var types = ConfigurationManager.AppSettings["WorkItemTypes"].Split(','); foreach (var type in types) { _itemTypesToValidate.Add(type); } }
/// <summary> /// Method for processing work items down to the changesets that are related to them /// </summary> /// <param name="wi">Work Item to process</param> /// <param name="outputFile">File to write the dgml to</param> /// <param name="vcs">Version Control Server which contains the changesets</param> public void ProcessWorkItemRelationships(WorkItem[] wi, string outputFile, bool hideReverse, bool groupbyIteration, bool dependencyAnalysis, List<TempLinkType> selectedLinks, VersionControlServer vcs) { string projectName = wi[0].Project.Name; _workItemStubs = new List<WorkItemStub>(); _wis = wi[0].Store; _vcs = vcs; _tms = vcs.TeamProjectCollection.GetService<ITestManagementService>(); _tmp = _tms.GetTeamProject(projectName); _selectedLinks = selectedLinks; //Store options _hideReverse = hideReverse; _groupbyIteration = groupbyIteration; _dependencyAnalysis = dependencyAnalysis; for (int i = 0; i < wi.Length; i++) { ProcessWorkItemCS(wi[i]); } WriteChangesetInfo(outputFile, projectName); }
/// <summary> /// Main Execution. UI handled in separate method, as this is a procedural utility. /// </summary> /// <param name="args">Not used</param> private static void Main(string[] args) { string serverUrl, destProjectName, plansJSONPath, logPath, csvPath; UIMethod(out serverUrl, out destProjectName, out plansJSONPath, out logPath, out csvPath); teamCollection = new TfsTeamProjectCollection(new Uri(serverUrl)); workItemStore = new WorkItemStore(teamCollection); Trace.Listeners.Clear(); TextWriterTraceListener twtl = new TextWriterTraceListener(logPath); twtl.Name = "TextLogger"; twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime; ConsoleTraceListener ctl = new ConsoleTraceListener(false); ctl.TraceOutputOptions = TraceOptions.DateTime; Trace.Listeners.Add(twtl); Trace.Listeners.Add(ctl); Trace.AutoFlush = true; // Get Project ITestManagementTeamProject newTeamProject = GetProject(serverUrl, destProjectName); // Get Test Plans in Project ITestPlanCollection newTestPlans = newTeamProject.TestPlans.Query("Select * From TestPlan"); // Inform user which Collection/Project we'll be working in Trace.WriteLine("Executing alignment tasks in collection \"" + teamCollection.Name + "\",\n\tand Destination Team Project \"" + newTeamProject.TeamProjectName + "\"..."); // Get and print all test case information GetAllTestPlanInfo(newTestPlans, plansJSONPath, logPath, csvPath); Console.WriteLine("Alignment completed. Check log file in:\n " + logPath + "\nfor missing areas or other errors. Press enter to close."); Console.ReadLine(); }
private int GetAtivatedChildUsCount(WorkItemStore workItemStore, WorkItem wi) { var ids = new List<int>(); foreach (WorkItemLink item in wi.WorkItemLinks) { if (item.LinkTypeEnd.Name == "Child") { ids.Add(item.TargetId); } } var query = string.Format("SELECT [System.Id],[System.WorkItemType],[System.Title] FROM WorkItems WHERE [System.TeamProject] = 'PSG Dashboard' AND [System.WorkItemType] = 'User Story' AND [System.State] = 'Active' AND [System.Id] In ({0})", GetFormatedIds(ids)); var workItems = workItemStore.Query(query); var count = 0; foreach (WorkItem tWi in workItems) { if (tWi.Type.Name == "User Story") { count++; } } return count; }
/// <inheritdoc/> public async Task ConfigureAsync(TfsServiceProviderConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if(string.IsNullOrEmpty(configuration.WorkItemType)) { throw new ArgumentNullException(nameof(configuration.WorkItemType)); } this.logger.Debug("Configure of TfsSoapServiceProvider started..."); var networkCredential = new NetworkCredential(configuration.Username, configuration.Password); var tfsClientCredentials = new TfsClientCredentials(new BasicAuthCredential(networkCredential)) { AllowInteractive = false }; var tfsProjectCollection = new TfsTeamProjectCollection(this.serviceUri, tfsClientCredentials); this.workItemType = configuration.WorkItemType; tfsProjectCollection.Authenticate(); tfsProjectCollection.EnsureAuthenticated(); this.logger.Debug("Authentication successful for {serviceUri}.", this.serviceUri.AbsoluteUri); await Task.Run( () => { this.logger.Debug("Fetching workitem for id {parentWorkItemId}.", configuration.ParentWorkItemId); this.workItemStore = new WorkItemStore(tfsProjectCollection); this.parentWorkItem = this.workItemStore.GetWorkItem(configuration.ParentWorkItemId); this.logger.Debug("Found parent work item '{title}'.", this.parentWorkItem.Title); }); this.logger.Verbose("Tfs service provider configuration complete."); }
/// <summary> /// Search all work items /// </summary> /// <param name="store"></param> /// <param name="iterationPath"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> public WorkItemTimeCollection(WorkItemStore store, string iterationPath, DateTime startDate, DateTime endDate) { this.IterationPath = iterationPath; this.Data = new ObservableCollection<WorkItemTime>(); // Sets a list of dates to compute _trackDates.Add(startDate.Date); for (DateTime date = startDate.Date; date <= endDate.Date; date = date.AddDays(1)) { _trackDates.Add(date.AddHours(23).AddMinutes(59)); } // Gets all work items for each dates foreach (DateTime asOfDate in _trackDates) { // Execute the query var wiCollection = store.Query(this.GetQueryString(asOfDate)); // Iterate through all work items foreach (WorkItem wi in wiCollection) { WorkItemTime time = new WorkItemTime(asOfDate, wi); this.Data.Add(time); } } }
public static IQueryableWorkitemStore WorkItems(this WIT.WorkItemStore store, DateTime asof) { return(new QueryableWorkItemStore(new WorkItemQueryProvider(store) { AsOf = asof })); }
public List<Project> GetProjects() { if (tfs == null) throw new Exception("Not logged into server!"); if ( store==null ) store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); System.Collections.IEnumerator proColEnum = store.Projects.GetEnumerator(); projList = new List<Project>(); while (proColEnum.MoveNext()) { Project proj = null; try { proj = (Project)proColEnum.Current; projList.Add(proj); } catch (Exception e) { throw e; } } return projList; }
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)); } }
public void Close(string itemId, string comment) { using (var collection = new TfsTeamProjectCollection(locator.Location)) { var workItemId = int.Parse(itemId); var workItemStore = new WorkItemStore(collection, WorkItemStoreFlags.BypassRules); var workItem = workItemStore.GetWorkItem(workItemId); var workItemDefinition = workItem.Store.Projects[workItem.Project.Name].WorkItemTypes[workItem.Type.Name]; if (workItemDefinition == null) { throw new ArgumentException("Could not obtain work item definition to close work item"); } var definitionDocument = workItemDefinition.Export(false).InnerXml; var xDocument = XDocument.Parse(definitionDocument); var graphBuilder = new StateGraphBuilder(); var stateGraph = graphBuilder.BuildStateGraph(xDocument); var currentStateNode = stateGraph.FindRelative(workItem.State); var graphWalker = new GraphWalker<string>(currentStateNode); var shortestWalk = graphWalker.WalkToNode("Closed"); foreach (var step in shortestWalk.Path) { workItem.State = step.Value; workItem.Save(); } workItem.Fields[CoreField.Description].Value = comment + "<br /><br/>" + workItem.Fields[CoreField.Description].Value; workItem.Save(); } }
public ReviewItemCollectorStrategy(WorkItemStore store, VersionControlServer versionControlServer, IVisualStudioAdapter visualStudioAdapter, IReviewItemFilter filter) { this.store = store; this.versionControlServer = versionControlServer; this.visualStudioAdapter = visualStudioAdapter; this.filter = filter; }
public override void AddLinkToWorkItem(int parentId, int childWorkItemId, string comment) { using (var tfsProjectCollection = GetProjectCollection()) { var workItemStore = new WorkItemStore(tfsProjectCollection); var parentWorkItem = workItemStore.GetWorkItem(parentId); var linked = false; // Update if there's an existing link already foreach (var link in parentWorkItem.Links) { var relatedLink = link as RelatedLink; if (relatedLink != null && relatedLink.RelatedWorkItemId == childWorkItemId) { relatedLink.Comment = comment; linked = true; } } if (!linked) { parentWorkItem.Links.Add(new RelatedLink(childWorkItemId) { Comment = comment }); } parentWorkItem.Validate(); parentWorkItem.Save(); } }
public TFSWorkItemManager(Config.InstanceConfig config) { ValidateConfig(config); _config = config; // Init TFS service objects _tfsServer = ConnectToTfsCollection(); Logger.InfoFormat("Connected to TFS. Getting TFS WorkItemStore"); _tfsStore = _tfsServer.GetService<WorkItemStore>(); if (_tfsStore == null) { Logger.ErrorFormat("Cannot initialize TFS Store"); throw new Exception("Cannot initialize TFS Store"); } Logger.InfoFormat("Geting TFS Project"); _tfsProject = _tfsStore.Projects[config.TfsServerConfig.Project]; Logger.InfoFormat("Initializing WorkItems Cache"); InitWorkItemsCache(); _nameResolver = InitNameResolver(); }
public ConnectionResult Connect(string host, string user, string password) { string.Format("Connecting to TFS '{0}'", host).Debug(); try { _projectCollectionUri = new Uri(host); } catch (UriFormatException ex) { string.Format("Invalid project URL '{0}': {1}", host, ex.Message).Error(); return ConnectionResult.InvalidUrl; } //This is used to query TFS for new WorkItems try { if (_projectCollectionNetworkCredentials == null) { _projectCollectionNetworkCredentials = new NetworkCredential(user, password); // if this is hosted TFS then we need to authenticate a little different // see this for setup to do on visualstudio.com site: // http://blogs.msdn.com/b/buckh/archive/2013/01/07/how-to-connect-to-tf-service-without-a-prompt-for-liveid-credentials.aspx if (_projectCollectionUri.Host.ToLowerInvariant().Contains(".visualstudio.com")) { if (_basicAuthCredential == null) _basicAuthCredential = new BasicAuthCredential(_projectCollectionNetworkCredentials); if (_tfsClientCredentials == null) { _tfsClientCredentials = new TfsClientCredentials(_basicAuthCredential); _tfsClientCredentials.AllowInteractive = false; } } if (_projectCollection == null) { _projectCollection = _tfsClientCredentials != null ? new TfsTeamProjectCollection(_projectCollectionUri, _tfsClientCredentials) : new TfsTeamProjectCollection(_projectCollectionUri, _projectCollectionNetworkCredentials); } _projectCollectionWorkItemStore = new WorkItemStore(_projectCollection); } if (_projectCollectionWorkItemStore == null) _projectCollectionWorkItemStore = new WorkItemStore(_projectCollection); } catch (Exception e) { string.Format("Failed to connect: {0}", e.Message).Error(e); return ConnectionResult.FailedToConnect; } return ConnectionResult.Success; }
public ReviewModel() { teamProjectCollectionProvider = IoC.GetInstance<IVisualStudioAdapter>(); var tpc = teamProjectCollectionProvider.GetCurrent(); workItemStore = tpc.GetService<WorkItemStore>(); versionControlServer = tpc.GetService<VersionControlServer>(); }
/// <summary> /// Initializes a new instance of the <see cref="PooledWorkItemStore"/> class. /// </summary> /// <param name="workItemStoreConnectionPool">The work item store connection pool.</param> /// <param name="workItemStore">The work item store.</param> internal PooledWorkItemStore(WorkItemStoreConnectionPool workItemStoreConnectionPool, WorkItemStore workItemStore) { if (workItemStoreConnectionPool == null) throw new ArgumentNullException("workItemStoreConnectionPool"); if (workItemStore == null) throw new ArgumentNullException("workItemStore"); _workItemStoreConnectionPoolReference = new WeakReference(workItemStoreConnectionPool); _workItemStoreReference = new WeakReference(workItemStore); }
public QueryManager(Project project, TreeView tree, WorkItemStore itemStore) { ItemStore = itemStore; this.project = project; Tree = tree; project.QueryHierarchy.Refresh(); BuildQueryHierarchy(project.QueryHierarchy); }
public static IQueryableWorkitemStore WorkItems(this TFS.TfsTeamProjectCollection server, DateTime asof) { WIT.WorkItemStore store = new WIT.WorkItemStore(server); return(new QueryableWorkItemStore(new WorkItemQueryProvider(store) { AsOf = asof })); }
public void Initialize(TfsTeamProjectCollection tfs, string projectName) { _isInitialized = true; _workItemStore = tfs.GetService<WorkItemStore>(); _project = _workItemStore.Projects .Cast<Project>() .SingleOrDefault(p => p.Name.Equals(projectName)); }
public WorkItemRead(TfsTeamProjectCollection tfs, Project sourceProject) { this.tfs = tfs; projectName = sourceProject.Name; store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); queryCol = store.Projects[sourceProject.Name].QueryHierarchy; workItemTypes = store.Projects[sourceProject.Name].WorkItemTypes; }
public ShowChangesetItemsModel(WorkItemSelectionService workItemSelectionService, WorkItemCollector workItemCollector, WorkItemStore workItemStore, VersionControlServer versionControlServer, IVisualStudioAdapter visualStudioAdapter) { this.workItemSelectionService = workItemSelectionService; this.workItemCollector = workItemCollector; this.workItemStore = workItemStore; this.versionControlServer = versionControlServer; this.visualStudioAdapter = visualStudioAdapter; }
public Program(IBuildDetail[] builds, IEnumerable<string> options, IEnumerable<string> exclusions, WorkItemStore workItemStore, Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer versionControlServer, TestManagementService tms) { this.Builds = builds; this.NoteOptions = options; this.Exclusions = exclusions; this.WorkItemStore = workItemStore; this.VersionControlServer = versionControlServer; this.TestManagementService = tms; }
public WorkItemCollection GetWorkItems(WorkItemStore wit, string wiql) { Query qry = new Query(wit, wiql, null, false); ICancelableAsyncResult car = qry.BeginQuery(); WorkItemCollection items = qry.EndQuery(car); return items; }
public TaskListForm(WorkItemStore wis, string project, TaskTypes type) : this() { this.wis = wis; this.project = project; this.type = type; this.Text = string.Format("Select {0}", type); }
public IEnumerable<FeatureEntity> Get(string project, string rootQuery, string query) { if (string.IsNullOrEmpty(project)) throw new NullReferenceException("project"); if (string.IsNullOrEmpty(rootQuery)) throw new NullReferenceException("rootQuery"); if (string.IsNullOrEmpty(query)) throw new NullReferenceException("query"); var tpc = new TfsTeamProjectCollection(new Uri(TfsUrl)); var workItemStore = new WorkItemStore(tpc); var queryRoot = workItemStore.Projects[project].QueryHierarchy; var folder = (QueryFolder)queryRoot[rootQuery]; QueryDefinition queryDef = null; foreach (var q in query.Split('/')) { queryDef = (QueryDefinition)folder[q]; } if (queryDef == null) { throw new Exception(string.Format("Query {0} was not found on the root {1}", query, rootQuery)); } var queryResults = workItemStore.Query(queryDef.QueryText); var result = new List<FeatureEntity>(); foreach (WorkItem wi in queryResults) { try { var targetDate = (DateTime)wi["Target Date"]; var targetEndDate = (DateTime)wi["Target End Date"]; result.Add(new FeatureEntity { Start = targetDate, End = targetEndDate, Group = wi["Group"].ToString(), Title = wi.Title, Url = string.Format("{0}/{1}/_workitems#_a=edit&id={2}", TfsUrl, project, wi.Id), Risk = wi["Risk"] as string, Tags = wi.Tags, Priority = wi["Priority"].ToString(), Requestor = wi["Requestor"].ToString(), WIId = wi.Id, ChildUSCount = GetAtivatedChildUsCount(workItemStore, wi), Status = wi["Status"].ToString() }); } catch (Exception ex) { } } return result; }
private static WorkItem GetWorkItem(WorkItemStore workItemStore, string workItemType, int workItemId) { var queryResults = workItemStore.Query(string.Format(@" Select [State], [Title] From WorkItems Where [Work Item Type] = '{0}' And Id = {1} Order By [State] Asc, [Changed Date] Desc", workItemType, workItemId)); return queryResults.Count == 0 ? null : queryResults[0]; }
private List<WorkItemStub> _workItemStubs; //Stores the distinct list of all work items to be written to the dgml #endregion Fields #region Constructors public ProcessFullAnalysis(WorkItemStore wis, VersionControlServer vcs, string projectName, string outputFile) { _wis = wis; _vcs = vcs; _tms = vcs.TeamProjectCollection.GetService<ITestManagementService>(); _tmp = _tms.GetTeamProject(projectName); _projectName = projectName; _outputFile = outputFile; }
private Query GetRunnableQuery(WorkItemStore workItemStore) { var item = GetQuery(Properties.Settings.Default.QueryPath, Properties.Settings.Default.QueryName, workItemStore.Projects[Properties.Settings.Default.TeamProject].QueryHierarchy); var text = ((QueryDefinition)item).QueryText; var query = new Query(workItemStore, ReplaceMacros(text)); return query; }
private WorkItemCollection GetCreatedItem(WorkItemStore wit, string projectName, DateTime from) { string wiql = String.Format(@"SELECT [System.Id], [System.CreatedDate] FROM WorkItems WHERE [System.TeamProject] = '{0}' AND [System.CreatedDate] > '{1}' ORDER BY[System.Id]", projectName, from.ToShortDateString()); WorkItemCollection items = GetWorkItems(wit, wiql); return items; }
public EditLinkTypeDialog(WorkItemStore wistore) { InitializeComponent(); this.comboBox1.Items.AddRange(wistore.WorkItemLinkTypes.ToArray()); this.comboBox2.Items.AddRange(wistore.WorkItemLinkTypes.ToArray()); this.comboBox1.ValueMember = "ReferenceName"; this.comboBox2.ValueMember = "ReferenceName"; }
private void ConnectToWorkItemStore() { TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsServerUrl)); workItemStore = (TFS.WorkItemStore)tfs.GetService(typeof(TFS.WorkItemStore)); }
public static IQueryableWorkitemStore WorkItems(this WIT.WorkItemStore store) { return(new QueryableWorkItemStore(new WorkItemQueryProvider(store))); }
internal static Tfs.RegisteredLinkType Map(Tfs.WorkItemStore store, string linkTypeName) => store.RegisteredLinkTypes .OfType <Tfs.RegisteredLinkType>() .FirstOrDefault(x => x.Name == linkTypeName);
public WorkItemQueryProvider(WIT.WorkItemStore store) { Store = store; }
internal WorkItemStoreProxy(IInternalTfsTeamProjectCollection tfs, TfsWorkItem.WorkItemStore workItemStore, IQueryFactory queryFactory) { _tfs = tfs; _workItemStore = workItemStore; _queryFactory = queryFactory; }
private QueryFactory(Tfs.WorkItemStore store) { _store = store; }
public static QueryFactory GetInstance(Tfs.WorkItemStore store) { return(new QueryFactory(store)); }