private void RefreshProjectComboItems(TfsTeamProjectCollectionUri item) { IList<Project> projs = BuildProjectItems(item); _cboProjects.Items.Clear(); foreach (Project p in projs) { _cboProjects.Items.Add(p.Name); } _cboProjects.SelectedIndex = 0; }
private IList<Project> BuildProjectItems(TfsTeamProjectCollectionUri uri) { IList<Project> projs = new List<Project>(); if (!_projects.ContainsKey(uri)) { TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(uri.Value), CredentialCache.DefaultNetworkCredentials); tpc.Authenticate(); //运行路径(E:\VSTS\VS2015\ImportWorkItems\TFSideKicks\bin\Debug)下必须存在如下文件:Microsoft.WITDataStore64.dll,否则报错。另外“生成”Any CPU;去掉勾选“首选32位”选项 WorkItemStore workItemStore = tpc.GetService<WorkItemStore>(); foreach (Project item in workItemStore.Projects) { if (!item.Name.StartsWith("CDSS")) projs.Add(item); } _projects[uri] = projs; } return _projects[uri]; }
private void _btnShowHistory_Click(object sender, RoutedEventArgs e) { TfsTeamProjectCollectionUri uri = _cboTfsUris.SelectedItem as TfsTeamProjectCollectionUri; TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(uri.Value), CredentialCache.DefaultNetworkCredentials); tpc.Authenticate(); VersionControlServer version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer; //查询历史版本 var histories = version.QueryHistory("$/", VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 18, true, false); _tbStatus.Text = "查询历史记录结果:"; //遍历路径下的内容的所有历史版本 foreach (Changeset change in histories)//每个历史版本下修改了几个文件 { _tbStatus.Text += string.Format("\r\n{0} {1} {2:yyyy-MM-dd HH:mm:ss}: {3}", change.ChangesetId, change.CommitterDisplayName, change.CreationDate, change.Comment); } }
private void _cboTfsUris_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { TfsTeamProjectCollectionUri uri = _cboTfsUris.SelectedItem as TfsTeamProjectCollectionUri; RefreshProjectComboItems(uri); }
private bool SaveWorkItem(string workItemIds, string projectName) { WorkItemStore workItemStore; WorkItemCollection queryResults; WorkItem workItem; string updateSQL = string.Empty; TfsTeamProjectCollectionUri uri = _cboTfsUris.SelectedItem as TfsTeamProjectCollectionUri; TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(uri.Value), CredentialCache.DefaultNetworkCredentials); tpc.Authenticate(); // [System.Title], [System.WorkItemType], [System.State], [System.ChangedDate], [System.Id] string base_sql = string.Format("Select * From WorkItems Where [System.TeamProject] = '{0}' ", projectName); string sql; string query = string.Format("select e.FullName, b.* from tBug b, tbEmployee e where b.CodeEmployeeID = e.EmployeeID and b.BugId in ( {0} )", workItemIds); DataSet ds = SqlDbHelper.Query(query); string rets = string.Empty; foreach (DataRowView item in ds.Tables[0].DefaultView) { Debug.Print(item["BugID"].ToString()); sql = string.Format("{0} and [System.Title] = '{1}'", base_sql, item["BugID"].ToString()); workItemStore = tpc.GetService<WorkItemStore>(); queryResults = workItemStore.Query(sql); int cnt = queryResults.Count; if (cnt > 0) { workItem = queryResults[0]; if (!workItem.IsOpen) workItem.Open(); } else { Project project = workItemStore.Projects[projectName]; workItem = new WorkItem(int.Parse(item["CustomerCaseID"].ToString()) == -1 ? project.WorkItemTypes["Bug"] : project.WorkItemTypes["任务"]); workItem.Fields["团队项目"].Value = projectName; workItem.Fields["标题"].Value = item["BugID"].ToString(); } if (int.Parse(item["CustomerCaseID"].ToString()) == -1) { workItem.Fields["重现步骤"].Value = item["CaseDesc"].ToString(); } else { workItem.Fields["说明"].Value = item["CaseDesc"].ToString(); } workItem.Fields["指派给"].Value = item["FullName"].ToString(); ArrayList ar = workItem.Validate(); workItem.Save(); int workItemId = int.Parse(workItem.Fields["ID"].Value.ToString()); string s = string.Format("UPDATE tBug SET TFSWorkItemID = {0} WHERE BugID = {1};", workItemId, item["BugID"]); updateSQL = string.IsNullOrEmpty(updateSQL) ? s : string.Format("{0}\r\n {1}", updateSQL, s); rets = string.IsNullOrEmpty(rets) ? workItem.Fields["ID"].Value.ToString() : string.Format("{0}, {1}", rets, workItem.Fields["ID"].Value); } _txtTFSWorkItemIDs.Text = rets; if (!string.IsNullOrEmpty(updateSQL)) { if (SqlDbHelper.ExecuteSql(updateSQL) == 0) MessageBox.Show("更新JSDesk平台工作项失败!"); } return true; }