示例#1
0
        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;
        }
示例#2
0
        private IList <Project> BuildProjectItems(TfsTeamProjectCollectionUri uri)
        {
            IList <Project> projs = new List <Project>();

            if (!_projects.ContainsKey(uri))
            {
                VssCredentials           credential = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(true));//初始化用户
                TfsTeamProjectCollection tpc        = new TfsTeamProjectCollection(new Uri(uri.Value), credential);
                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]);
        }
示例#3
0
        private void _cboTfsUris_SelectedIndexChanged(object sender, EventArgs e)
        {
            TfsTeamProjectCollectionUri item = _cboTfsUris.SelectedItem as TfsTeamProjectCollectionUri;

            RefreshProjectComboItems(item);
        }
示例#4
0
        private bool SaveWorkItem(string workItemIds, string projectName, out string errMsg)
        {
            WorkItemStore      workItemStore;
            WorkItemCollection queryResults;
            WorkItem           wi;

            errMsg = null;
            string updateSQL = string.Empty;

            TfsTeamProjectCollectionUri uri     = _cboTfsUris.SelectedItem as TfsTeamProjectCollectionUri;
            VssCredentials           credential = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(true));//初始化用户
            TfsTeamProjectCollection tpc        = new TfsTeamProjectCollection(new Uri(uri.Value), credential);

            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)
                {
                    wi = queryResults[0];
                    if (!wi.IsOpen)
                    {
                        wi.Open();
                    }
                }
                else
                {
                    Project project = workItemStore.Projects[projectName];
                    wi = new WorkItem(int.Parse(item["CustomerCaseID"].ToString()) == -1 ? project.WorkItemTypes["Bug"] : project.WorkItemTypes["任务"]);
                    wi.Fields["团队项目"].Value = projectName;
                    wi.Fields["标题"].Value   = item["BugID"].ToString();
                }
                if (int.Parse(item["CustomerCaseID"].ToString()) == -1)
                {
                    wi.Fields["重现步骤"].Value = item["CaseDesc"].ToString();
                }
                else
                {
                    wi.Fields["说明"].Value = item["CaseDesc"].ToString();
                }
                wi.Fields["指派给"].Value = item["FullName"].ToString();
                ArrayList ar = wi.Validate();
                if (ar.Count == 0)
                {
                    wi.Save();
                }
                else
                {
                    foreach (Field fd in ar)
                    {
                        errMsg = string.IsNullOrEmpty(errMsg) ? fd.Name : errMsg + ", " + fd.Name;
                    }
                    errMsg = string.Format("工作项字段“{0}”赋值错误,不能保存!", errMsg);
                    return(false);
                }

                int    workItemId = int.Parse(wi.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) ? wi.Fields["ID"].Value.ToString() : string.Format("{0}, {1}", rets, wi.Fields["ID"].Value);
            }
            _txtTFSWorkItemIDs.Text = rets;
            if (!string.IsNullOrEmpty(updateSQL))
            {
                if (SqlDbHelper.ExecuteSql(updateSQL) == 0)
                {
                    System.Windows.Forms.MessageBox.Show("更新JSDesk平台工作项失败!");
                }
            }

            return(true);
        }