开发者

p4.net cannot connect Perforce

开发者 https://www.devze.com 2023-03-19 22:22 出处:网络
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.

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开发者_Python百科 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消