p4.net 无法连接 Perforce

发布于 2024-11-19 23:03:09 字数 3233 浏览 0 评论 0原文

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

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

作为报告工具,我使用 MS SQL Reporting services 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;
            }
    }


}

您的帮助,我们将

不胜感激

I am using p4.net API to generate some reports from the metadata.

In one of the reports, I need to generate then number of the changes lines for each changeset report.

As a reporting tool, I am using MS SQL Reporting services 2008, and I have written a custom dll that uses p4.net API to calculate the number of changed lines. it works on the local without any problem. However, when I run the code on the server, it calculates let's say first %20 part then starts throwing Unable to connect to the Perforce Server!
Unable to connect to Perforce! exception.

I try same credentials on the local, it works.. I use commandline with same credentials on the server, it works.

Could anyone help me with that please, if encountered before?

Here is the code I use. If needed

 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;
            }
    }


}

your help will be appreciated

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里南柯 2024-11-26 23:03:09

我已经解决了这个问题。我们发现该代码在大约两分钟内循环通过临时端口范围。一旦达到最大临时端口,它就会尝试再次使用同一端口。由于每个 perforce 命令都会创建一个新套接字,因此在处理大约 1000 个变更集后,可用端口就会耗尽。
我已经设置了 HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters default(1433,143) 的 ReservePorts 值,这给了我更大范围的临时端口。

并且还为 P4Conn 实现了单例模式,这有助于我不关闭连接。我只检查连接的有效性,如果连接无效则登录。

如果你们中有人需要任何有关此问题的帮助,请告诉我

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文