private static WorkItem GetWorkItem(TfsTeamProjectCollection teamProjectCollection, string project, int id) { var workItemStore = new WorkItemStore(teamProjectCollection); WorkItemCollection workItemCollection = workItemStore.Query ( "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] " + "FROM WorkItems WHERE [System.TeamProject] = '" + project + "' AND [System.Id] = " + id ); return workItemCollection.Count > 0 ? workItemCollection[0] : null; }
private void SaveLinks(WorkItemsStageConfiguration mapping, WitMappingIndex index, WorkItemStore destWIStore, IEnumerable <WorkItem> changedWorkItems, bool testOnly) { if (testOnly) { eventSink.SavingSkipped(); } else { var errors = destWIStore.BatchSave(changedWorkItems.ToArray(), SaveFlags.MergeAll); ExamineSaveErrors(errors, index); }//if }
/// <summary> /// Get a work item from its Id. /// </summary> /// <param name="wis">A WorkItemStore instance</param> /// <param name="id">Work item Id.</param> /// <returns>A WorkItem instance.</returns> private static WorkItem GetWorkItem(WorkItemStore wis, int id) { var wi = wis.GetWorkItem(id); return(wi); }
private void SaveWorkItems3Passes(WorkItemsStageConfiguration mapping, WitMappingIndex index, bool testOnly, WorkItemStore destWIStore, List <WorkItem> newWorkItems, List <WorkItem> updatedWorkItems, List <WorkItem> validWorkItems) { eventSink.SaveFirstPassSavingNewWorkItems(newWorkItems); //HACK: force all new workitems to the Initial state var realStates = new Dictionary <WorkItem, string>(); newWorkItems.ForEach(w => { realStates.Add(w, w.State); w.State = GetInitialState(w); }); validWorkItems.AddRange(SaveWorkItems(mapping, index, destWIStore, newWorkItems, testOnly)); eventSink.SaveSecondPassUpdatingNewWorkItemsState(newWorkItems); // and now update the no-more-new WI with the real state newWorkItems.ForEach(w => { w.State = realStates[w]; }); validWorkItems.AddRange(SaveWorkItems(mapping, index, destWIStore, newWorkItems, testOnly)); eventSink.SaveThirdPassSavingUpdatedWorkItems(updatedWorkItems); // existing WI do not need tricks validWorkItems.AddRange(SaveWorkItems(mapping, index, destWIStore, updatedWorkItems, testOnly)); }
private List <WorkItem> SaveWorkItems(WorkItemsStageConfiguration mapping, WitMappingIndex index, WorkItemStore destWIStore, List <WorkItem> changedWorkItems, bool testOnly) { var failedWorkItems = new List <WorkItem>(); if (testOnly) { eventSink.SavingSkipped(); } else { var errors = destWIStore.BatchSave(changedWorkItems.ToArray(), SaveFlags.MergeAll); failedWorkItems = ExamineSaveErrors(errors, index); }//if var validWorkItems = changedWorkItems.Except(failedWorkItems); // some succeeded: their Ids could be changed, so refresh index if (!testOnly) { UpdateIndex(index, validWorkItems, mapping); foreach (var item in validWorkItems) { this.ChangeLog.AddEntry( new WorkItemChangeEntry( index.GetSourceIdFromTargetId(item.Id), item.Id, item.IsNew ? WorkItemChangeEntry.Change.New : WorkItemChangeEntry.Change.Update)); } //for } //if return(validWorkItems.ToList()); }
private void MyIssuesForm_Load(object sender, EventArgs e) { workItemStore = ConnectToTfs(); PopulateComboBoxWithSavedQueries(queryComboBox); }
internal WorkItemsStageConfigurationChecker(WorkItemStore sourceWIStore, string sourceProjectName, WorkItemStore destWIStore, string destProjectName, IEngineEvents eventSink) { this.sourceWIStore = sourceWIStore; this.sourceProjectName = sourceProjectName; this.destWIStore = destWIStore; this.destProjectName = destProjectName; this.eventSink = eventSink; }
public WorkItem GetItem(string id, out string url) { url = null; TFSPicker.ConnectByImplementingCredentialsProvider connect = new TFSPicker.ConnectByImplementingCredentialsProvider(); ICredentials iCred = new NetworkCredential(Username, Password); connect.setLoginDetails(Username, Password, RepositoryUrl); connect.GetCredentials(new Uri(RepositoryUrl), iCred); TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(RepositoryUrl)); configurationServer.Credentials = iCred; if (TFSPicker.IsBasicAuth) { configurationServer.ClientCredentials = new TfsClientCredentials(new BasicAuthCredential(iCred)); } else { configurationServer.ClientCredentials = new TfsClientCredentials(new WindowsCredential(iCred)); } try { configurationServer.EnsureAuthenticated(); } catch { System.Threading.Thread.Sleep(1000); configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(RepositoryUrl)); configurationServer.Credentials = iCred; if (TFSPicker.IsBasicAuth) { configurationServer.ClientCredentials = new TfsClientCredentials(new BasicAuthCredential(iCred)); } else { configurationServer.ClientCredentials = new TfsClientCredentials(new WindowsCredential(iCred)); } configurationServer.EnsureAuthenticated(); } CatalogNode catalogNode = configurationServer.CatalogNode; ReadOnlyCollection <CatalogNode> tpcNodes = catalogNode.QueryChildren(new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); foreach (CatalogNode tpcNode in tpcNodes) { TfsTeamProjectCollection tpc = configurationServer.GetTeamProjectCollection(new Guid(tpcNode.Resource.Properties["InstanceId"])); //TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(string.Concat(RepositoryUrl, '/', tpcNode.Resource.DisplayName)), iCred); if (TFSPicker.IsBasicAuth) { tpc.ClientCredentials = new TfsClientCredentials(new BasicAuthCredential(iCred)); } WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore)); WorkItemCollection queryResults = workItemStore.Query(string.Format("Select [Id], [Work Item Type], [Title], [State] From WorkItems WHERE [Id] = '{0}' Order By [Id] Asc", id)); if (queryResults.Count >= 1) { var item = queryResults[0]; try { TswaClientHyperlinkService hyperlinkService = (TswaClientHyperlinkService)tpc.GetService(typeof(TswaClientHyperlinkService)); url = hyperlinkService.GetWorkItemEditorUrl(item.Id).ToString(); } catch { } return(item); } } return(null); }
public ActionResult Search(string id, string search) { try { ItemWidgetArguments args = new ItemWidgetArguments(UserContext, GeminiContext, Cache, System.Web.HttpContext.Current.Request, CurrentIssue); TFSPicker tfsPicker = new TFSPicker(); tfsPicker.AuthenticateUser(args); UserWidgetDataDetails loginDetails = tfsPicker.getLoginDetails(); TFSPicker.ConnectByImplementingCredentialsProvider connect = new TFSPicker.ConnectByImplementingCredentialsProvider(); ICredentials iCred = new NetworkCredential(loginDetails.Username, loginDetails.Password); connect.setLoginDetails(loginDetails.Username, loginDetails.Password, loginDetails.RepositoryUrl); connect.GetCredentials(new Uri(loginDetails.RepositoryUrl), iCred); TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(loginDetails.RepositoryUrl)); configurationServer.Credentials = iCred; if (TFSPicker.IsBasicAuth) { configurationServer.ClientCredentials = new TfsClientCredentials(new BasicAuthCredential(iCred)); } else { configurationServer.ClientCredentials = new TfsClientCredentials(new WindowsCredential(iCred)); } try { configurationServer.EnsureAuthenticated(); } catch { System.Threading.Thread.Sleep(1000); configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(loginDetails.RepositoryUrl)); configurationServer.Credentials = iCred; if (TFSPicker.IsBasicAuth) { configurationServer.ClientCredentials = new TfsClientCredentials(new BasicAuthCredential(iCred)); } else { configurationServer.ClientCredentials = new TfsClientCredentials(new WindowsCredential(iCred)); } configurationServer.EnsureAuthenticated(); } CatalogNode catalogNode = configurationServer.CatalogNode; ReadOnlyCollection <CatalogNode> tpcNodes = catalogNode.QueryChildren(new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); string url = string.Empty; List <WorkItem2> queryResults = new List <WorkItem2>(); TfsTeamProjectCollection tpc = null; string query = "Select [Id], [Work Item Type], [Title], [State] From WorkItems Where [Title] Contains '" + search + "' Order By [Id] Asc"; if (search.Trim().Length == 0) { query = "Select [Id], [Work Item Type], [Title], [Description] From WorkItems Order By [Id] Asc"; } foreach (CatalogNode tpcNode in tpcNodes) { tpc = configurationServer.GetTeamProjectCollection(new Guid(tpcNode.Resource.Properties["InstanceId"])); //tpc = new TfsTeamProjectCollection(new Uri(string.Concat(loginDetails.RepositoryUrl, '/', tpcNode.Resource.DisplayName)), iCred); if (TFSPicker.IsBasicAuth) { tpc.ClientCredentials = new TfsClientCredentials(new BasicAuthCredential(iCred)); } WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore)); var result = workItemStore.Query(query); if (result != null) { TswaClientHyperlinkService hyperlinkService = null; try { hyperlinkService = ((TswaClientHyperlinkService)tpc.GetService(typeof(TswaClientHyperlinkService))); } catch { } foreach (WorkItem res in result) { WorkItem2 item = new WorkItem2() { Item = res, BaseUrl = string.Concat(tpcNode.Resource.DisplayName, '/', res.AreaPath) }; try { if (hyperlinkService != null) { item.FullUrl = hyperlinkService.GetWorkItemEditorUrl(res.Id); } } catch { } queryResults.Add(item); } } } Dictionary <string, WorkItem> details = new Dictionary <string, WorkItem>(); if (queryResults.Count > 0) { IssueWidgetData <List <string> > data = GeminiContext.IssueWidgetStore.Get <List <string> >(id.ToInt(), Constants.AppId, Constants.ControlId); if (data == null || data.Value == null) { data = new IssueWidgetData <List <string> >(); data.AppId = Constants.AppId; data.ControlId = Constants.ControlId; data.IssueId = id.ToInt(); data.Value = new List <string>(); } foreach (WorkItem2 item in queryResults) { //check if we are not already there! if (data.Value.Contains(item.Item.Id.ToString())) { continue; } /*if (isTfs2012) * {*/ if (item.FullUrl != null && item.FullUrl.ToString().HasValue()) { url = item.FullUrl.ToString(); } else { url = string.Format("{0}/{1}/_workitems#_a=edit&id={2}", loginDetails.RepositoryUrl, item.BaseUrl, item.Item.Id); } details.Add(url, item.Item); } } Dictionary <string, TfsPickerItem> tfsPickerModel = ConvertWorkItemsToTfsPickerItems(details); dataView = Content(BaseController.RenderPartialViewToString(this, AppManager.Instance.GetAppUrl("782D003D-D9F0-455F-AF09-74417D6DFD2B", "views/search.cshtml"), tfsPickerModel)); } catch (Exception ex) { Pair <int, string> authenticationModel = new Pair <int, string>(CurrentIssue.Entity.Id, string.Concat(UserContext.Url, "/apps/tfspicker/authenticate/", CurrentIssue.Entity.Id)); dataView = Content(BaseController.RenderPartialViewToString(this, AppManager.Instance.GetAppUrl("782D003D-D9F0-455F-AF09-74417D6DFD2B", "views/authenticationForm.cshtml"), authenticationModel)); successView = false; messageView = ex.Message; GeminiApp.LogException(new Exception(ex.Message) { Source = "TFS Picker" }, false); } return(JsonSuccess(new { success = successView, data = dataView, message = messageView })); }
/// <summary> /// Main function /// </summary> /// <param name="args">The Parameters of Main</param> private static void Main(string[] args) { // ISH3\ISH3_KBL\KBL_RS2\Test // [0] Check_Power_D0i1 // FAIL string logPath = Directory.GetCurrentDirectory(); string logfile = Path.Combine(logPath, "log-file.txt"); if (File.Exists(logfile)) { File.Delete(logfile); } log = LogManager.GetLogger("testApp.Logging"); try { Uri tfsUri = new Uri(ConfigurationManager.AppSettings["TfsUri"]); //Uri tfsUri = new Uri("https://tfs-alm.intel.com:8088/tfs/"); TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); // Get the catalog of team project collections ReadOnlyCollection <CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); var collectionNode = collectionNodes.Single(); // Use the InstanceId property to get the team project collection Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId); log.InfoFormat("Collecton: {0}", teamProjectCollection.Name); //log.Info("---------------------------------"); log.Info("*********************************"); WorkItemStore workItemStore = teamProjectCollection.GetService <WorkItemStore>(); if (args[0] != null && args[1] != null && args[2] != null) { iterationPath = args[0]; testExcutionName = args[1]; testExcutionState = args[2]; projectName = GetProjectName(iterationPath); } else { throw new Exception("Parameter errors!"); } if (!GetCmdStringResult(testExcutionState)) { throw new Exception(string.Format("The state {0} you input is not correct!", testExcutionState)); } string sql = string.Format("select [System.Id] from WorkItems where [System.TeamProject] = '{0}' and [System.WorkItemType] = 'Test Execution' and [System.State] <> 'Removed' and [System.Title] = '{1}' and [System.IterationPath] under '{2}'", projectName, testExcutionName, iterationPath); WorkItemCollection workItemCollection = workItemStore.Query(sql); if (workItemCollection.Count > 0) { foreach (WorkItem workItem in workItemCollection) { if (workItem.IsValid()) { if (string.Compare(workItem.Title, testExcutionName, true) == 0) { if (!UpdateWorkItemState(workItem)) { throw new Exception(string.Format("The state {0} you input is not correct!", testExcutionState)); } else { workItem.Open(); //log.InfoFormat("Update ID:{0} Title:{1} IterationPath:{2} State:{3} successfully!", workItem.Id, workItem.Title, workItem.IterationPath, workItem.State); log.Info("Update Spcificed Test Execution Successfully!"); log.Info("ID:" + workItem.Id); log.Info("Title:" + workItem.Title); log.Info("IterationPath:" + workItem.IterationPath); log.Info("State:" + workItem.State); //log.Info("Bug ID:" + workItem.Fields["Bug ID"].Value); //log.Info("Bug DB:" + workItem.Fields["Bug DB"].Value); //log.Info("Kit - Rev:" + workItem.Fields["Kit - Rev"].Value); log.Info("--------------------------------------------"); workItem.Close(); } } } else { throw new Exception("This Test execution is not a valid workitem!"); } } } else { throw new Exception("Not find the specified test execution!"); } } catch (Exception e) { log.Info(e.Message.ToString()); } }
/// <summary> /// Returns all work items for a specific iteration path and dates range. /// </summary> /// <param name="store"></param> /// <param name="iterationPath"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public static WorkItemTimeCollection GetWorkItems(this WorkItemStore store, string iterationPath, DateTime startDate, DateTime endDate) { return(new Data.WorkItemTimeCollection(store, iterationPath, startDate, endDate)); }
public ChangeRequest(WorkItem workItem, WorkItemStore workItemStore) : base(workItem, workItemStore) { Type = "ChangeRequest"; }