TFS的二次开发中,调用VersionControlServer.ArtifactProvider.GetChangeset()方法异常

时间:2021-07-02 17:07:44
对TFS进行二次开发,想做一个通过输入WorkItem列表,然后得到这些WorkItem的ChangeSet列表。
UI如下:
TFS的二次开发中,调用VersionControlServer.ArtifactProvider.GetChangeset()方法异常
但在调用TFS的函数的过程中,发现在调用VersionControlServer.ArtifactProvider.GetChangeset()时,
如果WorkItem数量比较多,特别是某个WorkItem的ChangeSet又很多的时候,经常都会出现异常,异常信息如下:
Team Foundation Server vstfs:///VersionControl/Changeset/135900 does not exist or is not accessible at this time.
Technical information (for administrator):
  The operation has timed out

不知道哪位有没有遇到类似的问题,怎么解啊?
出现这种异常的原因有可能是哪种原因造成的?
期待有大婶帮忙,这个问题,困扰了我好几个月了。

环境:
TFS Server为TFS2008
现在程式引用的TFS DLL的版本为11.

关键代码如下:

       private void btnAddWI_Click(object sender, EventArgs e)
        {
            try
            {
                Boolean ReBindCS = false;
                ReBindCS = (lstWorkItem.Items.Count > 0 ? false : true);
                if (txtWorkItems.Text.Trim() != "")
                {
                    TfsTeamProjectCollection tfsTPC = new TfsTeamProjectCollection(new Uri(appContext.ServerURL), new TfsClientCredentials(new SimpleWebTokenCredential(appContext.UserName, appContext.Password)));
                    WorkItemStore wis = tfsTPC.GetService<WorkItemStore>();
                    VersionControlServer vcs = tfsTPC.GetService<VersionControlServer>();
                    txtWorkItems.Text = txtWorkItems.Text.Trim().Replace(",", ",");
                    string[] strWIs = txtWorkItems.Text.Trim().Split(',');
                    string strMsg = string.Empty;
                    foreach (string strWI in strWIs)
                    {
                        //TfsTeamProjectCollection tfsTPC = new TfsTeamProjectCollection(new Uri(appContext.ServerURL), new TfsClientCredentials(new SimpleWebTokenCredential(appContext.UserName, appContext.Password)));
                        //WorkItemStore wis = tfsTPC.GetService<WorkItemStore>();
                        //VersionControlServer vcs = tfsTPC.GetService<VersionControlServer>();
                        int intWI = 0;
                        string strSA = string.Empty;
                        string strHasSQL = string.Empty;
                        if (int.TryParse(strWI, out intWI))
                        {
                            try
                            {
                                WorkItem wi = wis.GetWorkItem(intWI);
                                if (wi != null)
                                {
                                    if (wi.Fields.Contains("Include SQL Script"))
                                        strHasSQL = wi.Fields["Include SQL Script"].Value.ToString();
                                    else
                                        strHasSQL = "No";
                                    if (wi.Fields.Contains("SA"))
                                        strSA = wi.Fields["SA"].Value.ToString();
                                    else
                                        strSA = "N/A";
                                    BSWorkItem bsWI = new BSWorkItem();
                                    bsWI.WorkItemID = strWI;
                                    bsWI.Description = wi.Title;
                                    bsWI.HasSQL = strHasSQL;
                                    bsWI.SA = strSA;
                                    if (appContext.BuildWorkItems == null)
                                    {
                                        appContext.BuildWorkItems = new List<BSWorkItem>();
                                    }
                                    ListViewItem lvi = lstWorkItem.Items.Add(strWI);
                                    lvi.SubItems.Add(strHasSQL);
                                    lvi.SubItems.Add(wi.Title);
                                    lvi.SubItems.Add(strSA);
                                    lvi.EnsureVisible();

                                    if (bsWI.Changesets == null)
                                    {
                                        bsWI.Changesets = new List<BSChangeset>();
                                    }
                                    Common.WriteLog("---------------------------------------------------");
                                    Common.WriteLog("[WI:" + wi.Id + "]");
                                    foreach (Link lnk in wi.Links)
                                    {
                                        Common.WriteLog("  ----------------------------------------------");
                                        Common.WriteLog("  [LK:" + lnk.Comment + "]");
                                        ExternalLink elk = (ExternalLink)lnk;
                                        Common.WriteLog("    [URL:" + elk.LinkedArtifactUri + "]");
                                        Stopwatch sw = new Stopwatch();
                                        sw.Start();
                                        //TfsTeamProjectCollection tfsTPC2 = new TfsTeamProjectCollection(new Uri(appContext.ServerURL), new TfsClientCredentials(new SimpleWebTokenCredential(appContext.UserName, appContext.Password)));
                                        //VersionControlServer vcs2 = tfsTPC2.GetService<VersionControlServer>();
                                        Changeset cs = vcs.ArtifactProvider.GetChangeset(new Uri(elk.LinkedArtifactUri));
                                        sw.Stop();
                                        Common.WriteLog("      [TM:" + sw.Elapsed.ToString() + "]");
                                        Common.WriteLog("      [CS:" + cs.ChangesetId.ToString() + "]");
                                        foreach (Change cg in cs.Changes)
                                        {
                                            Common.WriteLog("        ----------------------------------------------");
                                            Common.WriteLog("        [File:" + cg.Item.ArtifactUri + "]");
                                            BSChangeset bcs = new BSChangeset();
                                            bcs.ChangesetID = cs.ChangesetId.ToString();
                                            bcs.FileName = cg.Item.ServerItem.ToString();
                                            bcs.FileSaveMode = cg.ChangeType;
                                            bsWI.Changesets.Add(bcs);
                                        }
                                    }
                                    //foreach (var changeset in wi.Links.OfType<ExternalLink>().Select(link => vcs.ArtifactProvider.GetChangeset(new Uri(link.LinkedArtifactUri))))
                                    //{

                                    //    Common.WriteLog("  [CS:" + changeset.ChangesetId.ToString() + "]");
                                    //    foreach (Change cg in changeset.Changes)
                                    //    {
                                    //        Common.WriteLog("    [File:" + cg.Item.ArtifactUri + "]");
                                    //        BSChangeset cs = new BSChangeset();
                                    //        cs.ChangesetID = changeset.ChangesetId.ToString();
                                    //        cs.FileName = cg.Item.ServerItem.ToString();
                                    //        cs.FileSaveMode = cg.ChangeType;
                                    //        bsWI.Changesets.Add(cs);
                                    //    }
                                    //}
                                    appContext.BuildWorkItems.Add(bsWI);
                                }
                                else
                                {
                                    strMsg += (strMsg == "" ? "" : ",") + strWI;
                                }
                            }
                            catch (Exception exWI)
                            {
                                MessageBox.Show(exWI.Message);
                                strMsg += (strMsg == "" ? "" : ",") + strWI;
                                //throw;
                            }
                        }
                    }
                    if (ReBindCS)
                        lstWorkItem.Items[0].Selected = true;
                    //if (ReBindCS)
                    //    lstWorkItem_SelectedIndexChanged(sender, e);
                    txtWorkItems.Text = "";
                    //TF26198: The work item does not exist, or you do not have permission to access it.
                    if (strMsg != "")
                    {
                        MessageBox.Show("The work item:" + strMsg + " does not exist, or you do not have permission to access it.");
                    }
                }
            }
            catch (Exception exAll)
            {

                MessageBox.Show(exAll.Message);
            }

        }

1 个解决方案

#1


懂的人到哪去了?

#1


懂的人到哪去了?