2

我正在使用 p4.net API 从元数据中生成一些报告。

在其中一份报告中,我需要为每个变更集报告生成变更行数。

作为报告工具,我使用的是 MS SQL 报告服务 2008,并且我编写了一个自定义 dll,它使用 p4.net API 来计算更改的行数。它在本地工作没有任何问题。但是,当我在服务器上运行代码时,它会计算假设第一个 %20 部分,然后开始抛出 Unable to connect to the Perforce Server!无法连接到 Perforce!例外。

我在本地尝试相同的凭据,它可以工作。我在服务器上使用具有相同凭据的命令行,它可以工作。

如果以前遇到过,有人可以帮我吗?

这是我使用的代码。如果需要的话

 public static class PerforceLib
{

    public static P4Connection p4conn = null;

    private static void  CheckConn()
    {
        try
        {
            if (p4conn == null)
            {

                p4conn = new P4Connection();
                p4conn.Port = "address";
                p4conn.User = "user";
                p4conn.Password = "pwd*";
                p4conn.Connect();
                p4conn.Login("pwd");
            }
            else if (p4conn != null)
            { 
                if(!p4conn.IsValidConnection(true, false))
                {
                    Log("Check CONN : Connection is not valid, reconnecting");
                    p4conn.Login("pwd*");
                }
            }

        }
        catch (Exception ex )
        {
            Log(ex.Message);
        }

    }



    public static int DiffByChangeSetNumber(string ChangeSetNumber)
    {
        try
        {
                CheckConn();
                P4Record set =   p4conn.Run("describe", "-s",ChangeSetNumber)[0];
                string[] files = set.ArrayFields["depotFile"].ToArray<string>();
                string[] revs = set.ArrayFields["rev"].ToArray<string>();
                string[] actions = set.ArrayFields["action"].ToArray<string>();


                int totalChanges = 0;
                List<P4File> lstFiles = new List<P4File>();


                for (int i = 0; i < files.Count(); i++)
                {
                    if (actions[i].ToString() == "edit")
                        lstFiles.Add(new P4File() { DepotFile = files[i].ToString(), Revision = revs[i].ToString(), Action = actions[i].ToString() });
                }



                foreach (var item in lstFiles)
                {
                    if (item.Revision != "1")
                    {
                        string firstfile = string.Format("{0}#{1}", item.DepotFile, (int.Parse(item.Revision) - 1).ToString());
                        string secondfile = string.Format("{0}#{1}", item.DepotFile, item.Revision);
                        P4UnParsedRecordSet rec = p4conn.RunUnParsed("diff2", "-ds", firstfile, secondfile);
                        if (rec.Messages.Count() > 1)
                        {
                            totalChanges = PerforceUtil.GetDiffResults(rec.Messages[1].ToString(), item.DepotFile);
                        }
                    }
                }
                GC.SuppressFinalize(lstFiles);
                Log(string.Format("{0} / {1}", ChangeSetNumber,totalChanges.ToString() + Environment.NewLine));
                return totalChanges;
            }
            catch (Exception ex)
            {
                Log(ex.Message + Environment.NewLine);
                return -1;
            }
    }


}

您的帮助将不胜感激

非常感谢

4

1 回答 1

1

I have solved this issue. we identified that the code is circling through the ephemeral port range in around two minutes. once it reaches the maximum ephemeral port, it was trying to use same port again. Due to each perforce command creates a new socket, available ports were running out after it processed about 1000 changesets. I have set the ReservedPorts value of HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters default(1433,143) that gave me larger range of ephemeral port.

and also implemented singleton pattern for P4Conn which helped as I dont close the connection. I only check the validity of the connection, and login if the connection is not valid.

Please let me know if any of you guys needs any help regarding this

于 2011-07-22T08:53:09.673 回答