Example #1
0
        private IP4CommandResult RunP4Command(string command, params string[] args)
        {
            var             cmd     = m_connectionManager.CreateCommand(command, args);
            P4CommandResult results = null;

            try
            {
                results = cmd.Run();
            }
            catch (P4Exception ex)
            {
                switch (ex.ErrorLevel)
                {
                case ErrorSeverity.E_WARN:
                    Outputs.WriteLine(OutputMessageType.Warning, ex.Message);
                    break;

                case ErrorSeverity.E_FAILED:
                    Outputs.WriteLine(OutputMessageType.Error, ex.Message);
                    break;

                case ErrorSeverity.E_INFO:
                    Outputs.WriteLine(OutputMessageType.Info, ex.Message);
                    break;
                }
                if (ThrowExceptions)
                {
                    throw;
                }

                return(new DummyCommandResult(false, args));
            }
            return(new P4CommandResultWrapper(cmd, results));
        }
        public void SubmitShelvedFromChangelist()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 13, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);
                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);
                        Utilities.SetClientRoot(rep, TestDir, unicode, ws_client);

                        Changelist change = new Changelist(5, true);
                        change.initialize(con);

                        // shelve the files in changelist 5
                        con.Client.ShelveFiles(new ShelveFilesCmdOptions(ShelveFilesCmdFlags.None,
                                                                         null, change.Id));

                        // revert the checked out file that was shelved
                        FileSpec file = new FileSpec(new DepotPath("//..."), null, null, null);
                        con.Client.RevertFiles(new RevertCmdOptions(RevertFilesCmdFlags.None, change.Id),
                                               file);

                        // submit the shelved file
                        SubmitCmdOptions submitOptions = new
                                                         SubmitCmdOptions(Perforce.P4.SubmitFilesCmdFlags.SubmitShelved,
                                                                          5, null, null, null);
                        change.Submit(submitOptions);

                        P4CommandResult last = rep.Connection.LastResults;
                        Assert.IsTrue(last.Success);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
        private void cmdThreadProc2()
        {
            try
            {
                P4Server server = serverMT.getServer();

                while (run)
                {
                    cmdCnt2++;
                    cmd2 = new P4Command(server, "dirs", false, "//depot/*");

                    DateTime StartedAt = DateTime.Now;

                    WriteLine(string.Format("Thread 2 starting command: {0:X8}, at {1}",
                                            cmd2.CommandId, StartedAt.ToLongTimeString()));

                    P4CommandResult result = cmd2.Run();

                    WriteLine(string.Format("Thread 2 Finished command: {0:X8}, at {1}, run time {2} Milliseconds",
                                            cmd2.CommandId, StartedAt.ToLongTimeString(), (DateTime.Now - StartedAt).TotalMilliseconds));

                    P4CommandResult lastResult = server.LastResults;

                    // Assert is not allowed on the non primary thread
                    Assert.AreEqual(result.Success, lastResult.Success);

                    if (!result.Success)
                    {
                        string msg = string.Format("Thread 2, fstat failed:{0}", (result.ErrorList != null && result.ErrorList.Count > 0) ? result.ErrorList[0].ErrorMessage : "<unknown error>");
                        WriteLine(msg);
                        throw new Exception(msg);
                    }
                    else
                    {
                        WriteLine(string.Format("Thread 2, dirs Success:{0}", (result.InfoOutput != null && result.InfoOutput.Count > 0) ? result.InfoOutput[0].Message : "<no output>"));
                    }
                    //Assert.IsTrue(result.Success);
                    if (delay != TimeSpan.Zero)
                    {
                        Thread.Sleep(delay);
                    }
                }
                WriteLine(string.Format("Thread 2 cleanly exited after running {0} commands", cmdCnt2));
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                return;
            }
            catch (Exception ex)
            {
                WriteLine(string.Format("cmdThreadProc2 failed with exception: {0}\r\n{1}", ex.Message, ex.StackTrace));
                runThreadExeptions.Add(new RunThreadException(2, ex));
                //Assert.Fail("cmdThreadProc2 failed with exception", ex.Message);
            }
        }
Example #4
0
        public void RunTest1()
        {
            bool unicode = false;

            string serverAddr = "localhost:6666";
            string user       = "******";
            string pass       = string.Empty;
            string ws_client  = "admin_space";

            // turn off exceptions for this test
            ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel;

            P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC;

            Process p4d = null;

            for (int i = 0; i < 2; i++)              // run once for ascii, once for unicode
            {
                try
                {
                    p4d = Utilities.DeployP4TestServer(TestDir, unicode);
                    using (P4Server server = new P4Server(serverAddr, user, pass, ws_client))
                    {
                        if (unicode)
                        {
                            Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode");
                        }
                        else
                        {
                            Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode");
                        }

                        P4Command target = new P4Command(server, "help", false, null);

                        P4CommandResult results = target.Run(new String[] { "print" });
                        Assert.IsTrue(results.Success);

                        P4ClientInfoMessageList helpTxt = target.InfoOutput;

                        Assert.IsNotNull(helpTxt);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
            // reset the exception level
            P4Exception.MinThrowLevel = oldExceptionLevel;
        }
Example #5
0
        public static List <KeyValuePair <string, string> > GetClientSpec(RepoStorage repo)
        {
            P4Command       cmd     = repo.rep.Connection.CreateCommand("spec", true, "-o", "client");
            P4CommandResult results = cmd.Run();
            List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >();

            if (results.TaggedOutput != null)
            {
                foreach (KeyValuePair <string, string> kvp in results.TaggedOutput[0])
                {
                    list.Add(kvp);
                }
            }
            return(list);
        }
Example #6
0
        public bool Connect(Repository InRepo, bool IsFromPersistance)
        {
            try
            {
                InRepo.Connection.Connect(new Options());
                InRepo.Connection.Login(PasswordBox.Text);

                P4Command       Command = new P4Command(InRepo, "info", true, null);
                P4CommandResult Result  = Command.Run();

                if (Result.Success)
                {
                    if (!IsFromPersistance)
                    {
                        SaveToSettings();
                    }

                    OnP4Connected.Invoke(InRepo);

                    this.Close();
                    MessageBox.Show("Successfully connected to Perforce", "Success");

                    return(true);
                }
            }
            catch (P4Exception Ex)
            {
                if (Ex.Message.Contains("Password"))
                {
                    string EnteredPassword = MainForm.ShowDialog("Enter Password: "******"");

                    if (EnteredPassword != "")
                    {
                        PasswordBox.Text = EnteredPassword;
                        Connect(InRepo, IsFromPersistance);
                    }
                }
                else
                {
                    MessageBox.Show(Ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            return(false);
        }
Example #7
0
        /// <summary>Simple login check using `p4 login -s`</summary>
        /// <para>Return 'true' if logged in (with or without a password).</para>
        public bool isLoggedIn()
        {
            try
            {
                string[]        loginOptions = new string[] { "-s" };
                P4.P4Command    LoginCmd     = new P4Command(Repository, "login", true, loginOptions);
                P4CommandResult LoginResults = LoginCmd.Run();

                if ((LoginResults == null) || (LoginResults.TaggedOutput == null))
                {
                    return(false);
                }

                string validated;
                LoginResults.TaggedOutput[0].TryGetValue("2FA", out validated);
                if (validated == "required")
                {
                    P4ClientError err = new P4ClientError(ErrorSeverity.E_FAILED,
                                                          "Second factor authentication required! Run 'p4 login2'.");
                    err.ErrorCode = 807673723;
                    P4Exception ex = new P4Exception(err);
                    throw ex;
                }

                // logged in. May not have a ticket if no password was required.
                return(true);
            }
            catch (P4.P4Exception ex)
            {
                if (ex.ErrorCode == P4.P4ClientError.MsgServer_Login2Required)
                {
                    throw ex;
                }
                return(false);
            }
        }
Example #8
0
 public P4CommandResultWrapper(P4Command p4Command, P4CommandResult p4Result) { m_p4Command = p4Command;  m_p4Result = p4Result; }
        public void DeleteGroupTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            string targetGroup = "deleteme";

            for (int i = 0; i < 2; i++)             // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 7, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        Group u = new Group();
                        u.Id        = targetGroup;
                        u.UserNames = new List <string> {
                            "Alex"
                        };
                        u.OwnerNames = new List <string> {
                            "Alex"
                        };
                        u.MaxResults = 9999;

                        Group newGuy = rep.CreateGroup(u, null);

                        IList <Group> u2 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));

                        Assert.IsNotNull(u2);
                        Assert.AreEqual(2, u2.Count);

                        rep.DeleteGroup(u, null);

                        u2 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));

                        Assert.IsNotNull(u2);
                        Assert.AreEqual(1, u2.Count);

                        Group u3 = new Group();
                        u3.Id        = targetGroup;
                        u3.UserNames = new List <string> {
                            "Alex"
                        };
                        u3.OwnerNames = new List <string> {
                            "admin"
                        };
                        u3.MaxResults = 9999;

                        newGuy = rep.CreateGroup(u3, null);
                        try
                        {
                            Assert.Inconclusive("NewGuy {0}", newGuy.Id);
                        }
                        catch { }
                        if (newGuy == null)
                        {
                            P4CommandResult res = con.LastResults;

                            Assert.IsNotNull(res.ErrorList);
                            foreach (P4ClientError e in res.ErrorList)
                            {
                                Assert.Fail("CreateGroup returned null: {0}:{1}", e.ErrorCode, e.ErrorMessage);
                            }
                        }
                        Assert.IsNotNull(newGuy);

                        IList <Group> u4 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));

                        Assert.IsNotNull(u4);
                        if (con.ApiLevel >= 38)
                        {
                            Assert.AreEqual(2, u4.Count);
                        }
                        else
                        {
                            Assert.AreEqual(1, u4.Count);
                        }
                        // delete the group when the user is an owner but not a superuser
                        GroupCmdOptions opts = new GroupCmdOptions(GroupCmdFlags.OwnerAccess);

                        rep.DeleteGroup(u3, opts);

                        u4 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));

                        Assert.IsNotNull(u4);
                        Assert.AreEqual(1, u4.Count);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
Example #10
0
 public P4CommandResultWrapper(P4Server server, uint commandId, P4CommandResult p4Result)
 {
     m_server = server;
     m_commandId = commandId;
     m_p4Result = p4Result;
 }
Example #11
0
        private void cmdThreadProc4()
        {
            try
            {
                WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
                P4Server server = serverMT.getServer();
                while (run)
                {
                    using (P4Server _P4Server = new P4Server("localhost:6666", null, null, null))
                    {
                        string val          = P4Server.Get("P4IGNORE");
                        bool   _p4IgnoreSet = !string.IsNullOrEmpty(val);

                        if (_p4IgnoreSet)
                        {
                            WriteLine(string.Format("P4Ignore is set, {0}", val));
                        }
                        else
                        {
                            WriteLine("P4Ignore is not set");
                        }

                        Assert.IsTrue(_P4Server.ApiLevel > 0);
                    }
                    cmd4 = new P4Command(server, "fstat", false, "//depot/...");

                    DateTime StartedAt = DateTime.Now;

                    ReportCommandStart(cmd4, StartedAt);
                    P4CommandResult result = cmd4.Run();
                    ReportCommandStop(cmd4, StartedAt);

                    P4CommandResult lastResult = server.LastResults;

                    Assert.AreEqual(result.Success, lastResult.Success);
                    if (result.InfoOutput != null)
                    {
                        Assert.AreEqual(result.InfoOutput.Count, lastResult.InfoOutput.Count);
                    }
                    else
                    {
                        Assert.IsNull(lastResult.InfoOutput);
                    }
                    if (result.ErrorList != null)
                    {
                        Assert.AreEqual(result.ErrorList.Count, lastResult.ErrorList.Count);
                    }
                    else
                    {
                        Assert.IsNull(result.ErrorList);
                    }
                    if (result.TextOutput != null)
                    {
                        Assert.AreEqual(result.TextOutput, lastResult.TextOutput);
                    }
                    else
                    {
                        Assert.IsNull(lastResult.TextOutput);
                    }
                    if (result.TaggedOutput != null)
                    {
                        Assert.AreEqual(result.TaggedOutput.Count, lastResult.TaggedOutput.Count);
                    }
                    else
                    {
                        Assert.IsNull(lastResult.TaggedOutput);
                    }
                    Assert.AreEqual(result.Cmd, lastResult.Cmd);
                    if (result.CmdArgs != null)
                    {
                        Assert.AreEqual(result.CmdArgs.Length, lastResult.CmdArgs.Length);
                    }
                    else
                    {
                        Assert.IsNull(lastResult.CmdArgs);
                    }
                    if (!result.Success)
                    {
                        WriteLine(string.Format("Thread 4, fstat failed:{0}", (result.ErrorList != null && result.ErrorList.Count > 0)?result.ErrorList[0].ErrorMessage :"<unknown error>"));
                    }
                    else
                    {
                        WriteLine(string.Format("Thread 4, fstat Success:{0}", (result.InfoOutput != null && result.InfoOutput.Count > 0) ? result.InfoOutput[0].Message : "<no output>"));
                    }
                    if (delay != TimeSpan.Zero)
                    {
                        Thread.Sleep(delay);
                    }
                }
                WriteLine("Thread 4 cleanly exited");
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                return;
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Example #12
0
        private void cmdThreadProc6()
        {
            try
            {
                WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
                P4Server server = serverMT.getServer();
                while (run)
                {
                    cmd6 = new P4Command(server, "edit", false, "-n", "//depot/...");

                    DateTime StartedAt = DateTime.Now;
                    ReportCommandStart(cmd6, StartedAt);
                    P4CommandResult result = cmd6.Run();
                    ReportCommandStop(cmd6, StartedAt);

                    P4CommandResult lastResult = server.LastResults;

                    Assert.AreEqual(result.Success, lastResult.Success);
                    if (result.InfoOutput != null)
                    {
                        Assert.AreEqual(result.InfoOutput.Count, lastResult.InfoOutput.Count);
                    }
                    else
                    {
                        Assert.IsNull(lastResult.InfoOutput);
                    }
                    if (result.ErrorList != null)
                    {
                        Assert.AreEqual(result.ErrorList.Count, lastResult.ErrorList.Count);
                    }
                    else
                    {
                        Assert.IsNull(result.ErrorList);
                    }
                    if (result.TextOutput != null)
                    {
                        Assert.AreEqual(result.TextOutput, lastResult.TextOutput);
                    }
                    else
                    {
                        Assert.IsNull(lastResult.TextOutput);
                    }
                    if (result.TaggedOutput != null)
                    {
                        Assert.AreEqual(result.TaggedOutput.Count, lastResult.TaggedOutput.Count);
                    }
                    else
                    {
                        Assert.IsNull(lastResult.TaggedOutput);
                    }
                    Assert.AreEqual(result.Cmd, lastResult.Cmd);
                    if (result.CmdArgs != null)
                    {
                        Assert.AreEqual(result.CmdArgs.Length, lastResult.CmdArgs.Length);
                    }
                    else
                    {
                        Assert.IsNull(lastResult.CmdArgs);
                    }

                    if (!result.Success)
                    {
                        WriteLine(string.Format("Thread 6, edit failed:{0}", (result.ErrorList != null && result.ErrorList.Count > 0) ? result.ErrorList[0].ErrorMessage : "<unknown error>"));
                    }
                    else
                    {
                        WriteLine(string.Format("Thread 6, edit Success:{0}", (result.InfoOutput != null && result.InfoOutput.Count > 0) ? result.InfoOutput[0].Message : "<no output>"));
                    }
                    if (delay != TimeSpan.Zero)
                    {
                        Thread.Sleep(delay);
                    }
                }
                WriteLine("Thread 6 cleanly exited");
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                return;
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Example #13
0
        public User Show(RepoStorage repo)
        {
            SetPasswordOnly = false;
            Repo            = repo;
            string oldPasswd = null;

            User newUser = new User();

            do
            {
                if (this.ShowDialog() == DialogResult.OK)
                {
                    if (!SetPasswordOnly)
                    {
                        string name = userNameTB.Text;
                        if (name.Contains(" "))
                        {
                            name = Regex.Replace(name, " ", "_");
                        }
                        Options        opts  = new Options();
                        IList <string> users = new List <string>();
                        users.Add(userNameTB.Text);
                        if (Repo.rep.GetUsers(users, opts) != null)
                        {
                            string msg = string.Format(Properties.Resources.NewUserDlg_UserExistsWarning, userNameTB.Text);
                            MessageBox.Show(msg, Properties.Resources.P4EXP, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            continue;
                        }

                        // Set connection options
                        Options options = new Options();
                        options["ProgramName"]    = Properties.Resources.P4EXP;
                        options["ProgramVersion"] = P4EXPProgram.ProductVersion;

                        newUser.Id                   = name;
                        newUser.FullName             = fullNameTB.Text;
                        newUser.EmailAddress         = emailTB.Text;
                        Repo.rep.Connection.UserName = newUser.Id;
                        Repo.rep.Connection.Connect(options);

                        //scm.Connection.User = newUser.Id;//.Repository.Connection.UserName = newUser.Id;
                        //scm.Connection.Connect(null);//.Repository.Connection.Connect(null);
                    }
                    if (!string.IsNullOrEmpty(fullNameTB.Text))
                    {
                        newUser.Password = password1TB.Text;
                    }
                    try
                    {
                        if (SetPasswordOnly)
                        {
                            SetPasswordOnly = false;
                            Repo.rep.Connection.SetPassword(null, password1TB.Text);
                        }
                        else
                        {
                            SetPasswordOnly = false;
                            newUser         = Repo.rep.CreateUser(newUser);
                        }
                        return(newUser);
                    }
                    catch (P4Exception p4ex)
                    {
                        // if from Connection.SetPassword(), error has not been shown
                        if (P4ClientError.IsBadPasswdError(p4ex.ErrorCode))
                        {
                            SetPasswordOnly = true;
                        }
                        if ((p4ex.ErrorCode == P4ClientError.MsgServer_PasswordTooShort) ||
                            (p4ex.ErrorCode == P4ClientError.MsgServer_PasswordTooSimple))
                        {
                            MessageBox.Show(Properties.Resources.NewUserDlg_PasswordTooShortOrSimple, Properties.Resources.P4EXP,
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show(p4ex.Message);
                            //scm.ShowException(p4ex);
                        }
                    }

                    P4CommandResult results = Repo.rep.Connection.LastResults;
                    oldPasswd = password1TB.Text;
                }
                else
                {
                    return(null);
                }
            } while (true);
        }
        public void GetChangelistWithUTCConversionTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";


            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 6, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);
                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);
                        Utilities.SetClientRoot(rep, TestDir, unicode, ws_client);

                        P4Command cmd  = new P4Command(rep, "change", true, "5");
                        Options   opts = new Options();
                        opts["-o"] = null;
                        Changelist fromChangeCommand = new Changelist();

                        P4CommandResult results = cmd.Run(opts);
                        if (results.Success)
                        {
                            fromChangeCommand.initialize(rep.Connection);
                            fromChangeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                        server.Metadata.DateTimeOffset, FormBase.DSTMismatch(server.Metadata));
                        }

                        SubmitResults sr = fromChangeCommand.Submit(null);

                        int submitted = 17;
                        if (unicode)
                        {
                            submitted = 13;
                        }

                        cmd               = new P4Command(rep, "change", true, submitted.ToString());
                        opts              = new Options();
                        opts["-o"]        = null;
                        fromChangeCommand = new Changelist();

                        results = cmd.Run(opts);
                        if (results.Success)
                        {
                            fromChangeCommand.initialize(rep.Connection);
                            fromChangeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                        server.Metadata.DateTimeOffset, FormBase.DSTMismatch(server.Metadata));
                        }

                        Changelist fromDescribeCommand = rep.GetChangelist(submitted, null);

                        Assert.AreEqual(fromDescribeCommand.ModifiedDate, fromChangeCommand.ModifiedDate);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
        private void cmdThreadProc4()
        {
            try
            {
                P4Server server = serverMT.getServer();

                while (run)
                {
                    cmdCnt4++;

                    string val          = P4Server.Get("P4IGNORE");
                    bool   _p4IgnoreSet = !string.IsNullOrEmpty(val);

                    if (_p4IgnoreSet)
                    {
                        WriteLine(string.Format("P4Ignore is set, {0}", val));
                    }
                    else
                    {
                        WriteLine("P4Ignore is not set");
                    }

                    cmd4 = new P4Command(server, "fstat", false, "//depot/...");

                    DateTime StartedAt = DateTime.Now;

                    WriteLine(string.Format("Thread 4 starting command: {0:X8}, at {1}",
                                            cmd4.CommandId, StartedAt.ToLongTimeString()));

                    P4CommandResult result = cmd4.Run();

                    WriteLine(string.Format("Thread 4 Finished command: {0:X8}, at {1}, run time {2} Milliseconds",
                                            cmd4.CommandId, StartedAt.ToLongTimeString(), (DateTime.Now - StartedAt).TotalMilliseconds));

                    P4CommandResult lastResult = server.LastResults;
                    if (!result.Success)
                    {
                        string msg = string.Format("Thread 4, fstat failed:{0}", (result.ErrorList != null && result.ErrorList.Count > 0) ? result.ErrorList[0].ErrorMessage : "<unknown error>");
                        WriteLine(msg);
                        throw new Exception(msg);
                    }
                    else
                    {
                        WriteLine(string.Format("Thread 4, fstat Success:{0}", (result.InfoOutput != null && result.InfoOutput.Count > 0) ? result.InfoOutput[0].Message : "<no output>"));
                    }
                    //Assert.IsTrue(result.Success);
                    if (delay != TimeSpan.Zero)
                    {
                        Thread.Sleep(delay);
                    }
                }
                WriteLine(string.Format("Thread 4 cleanly exited after running {0} commands", cmdCnt4));
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                return;
            }
            catch (Exception ex)
            {
                WriteLine(string.Format("cmdThreadProc4 failed with exception: {0}\r\n{1}", ex.Message, ex.StackTrace));
                runThreadExeptions.Add(new RunThreadException(4, ex));
                //Assert.Fail("cmdThreadProc4 failed with exception", ex.Message);
            }
        }
Example #16
0
 public P4CommandResultWrapper(P4Server server, uint commandId, P4CommandResult p4Result)
 {
     m_server    = server;
     m_commandId = commandId;
     m_p4Result  = p4Result;
 }
        public void GetChangelistWithUTCConversionNoTZDetailsTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";


            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 6, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        P4Command  cmd = new P4Command(rep, "describe", true, "5");
                        Changelist fromDescribeCommand = new Changelist();

                        P4CommandResult results = cmd.Run(null);
                        if (results.Success)
                        {
                            fromDescribeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                          string.Empty, FormBase.DSTMismatch(server.Metadata));
                        }

                        DateTime unconverted = fromDescribeCommand.ModifiedDate;

                        fromDescribeCommand = new Changelist();
                        results             = cmd.Run(null);
                        if (results.Success)
                        {
                            fromDescribeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                          "-200", FormBase.DSTMismatch(server.Metadata));
                        }

                        Assert.AreEqual(unconverted.AddHours(-2), fromDescribeCommand.ModifiedDate);

                        fromDescribeCommand = new Changelist();
                        results             = cmd.Run(null);
                        if (results.Success)
                        {
                            fromDescribeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                          "+200", FormBase.DSTMismatch(server.Metadata));
                        }

                        Assert.AreEqual(unconverted.AddHours(2), fromDescribeCommand.ModifiedDate);

                        fromDescribeCommand = new Changelist();
                        results             = cmd.Run(null);
                        if (results.Success)
                        {
                            fromDescribeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                          "200", FormBase.DSTMismatch(server.Metadata));
                        }

                        Assert.AreEqual(unconverted.AddHours(2), fromDescribeCommand.ModifiedDate);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
        private void cmdThreadProc6a()
        {
            try
            {
                P4Server server = serverMT.getServer();

                cmdCnt6++;
                cmd6 = new P4Command(server, "edit", false, "-n", "//depot/...");

                DateTime StartedAt = DateTime.Now;
                WriteLine(string.Format("{2} starting command: {0:X8}, at {1}",
                                        cmd6.CommandId, StartedAt.ToLongTimeString(), t6Name));

                P4CommandResult result = cmd6.Run();

                WriteLine(string.Format("{3} Finished command: {0:X8}, at {1}, run time {2} Milliseconds",
                                        cmd6.CommandId, StartedAt.ToLongTimeString(), (DateTime.Now - StartedAt).TotalMilliseconds, t6Name));

                P4CommandResult lastResult = server.LastResults;

                Assert.AreEqual(result.Success, lastResult.Success);
                if (result.InfoOutput != null)
                {
                    Assert.AreEqual(result.InfoOutput.Count, lastResult.InfoOutput.Count);
                }
                else
                {
                    Assert.IsNull(lastResult.InfoOutput);
                }
                if (result.ErrorList != null)
                {
                    Assert.AreEqual(result.ErrorList.Count, lastResult.ErrorList.Count);
                }
                else
                {
                    Assert.IsNull(result.ErrorList);
                }
                if (result.TextOutput != null)
                {
                    Assert.AreEqual(result.TextOutput, lastResult.TextOutput);
                }
                else
                {
                    Assert.IsNull(lastResult.TextOutput);
                }
                if (result.TaggedOutput != null)
                {
                    Assert.AreEqual(result.TaggedOutput.Count, lastResult.TaggedOutput.Count);
                }
                else
                {
                    Assert.IsNull(lastResult.TaggedOutput);
                }
                Assert.AreEqual(result.Cmd, lastResult.Cmd);
                if (result.CmdArgs != null)
                {
                    Assert.AreEqual(result.CmdArgs.Length, lastResult.CmdArgs.Length);
                }
                else
                {
                    Assert.IsNull(lastResult.CmdArgs);
                }

                if (!result.Success)
                {
                    string msg = string.Format("Thread 6, fstat failed:{0}", (result.ErrorList != null && result.ErrorList.Count > 0) ? result.ErrorList[0].ErrorMessage : "<unknown error>");
                    WriteLine(msg);
                    throw new Exception(msg);
                }
                else
                {
                    WriteLine(string.Format("{1}, edit Success:{0}", (result.InfoOutput != null && result.InfoOutput.Count > 0) ? result.InfoOutput[0].Message : "<no output>", t6Name));
                }
                //Assert.IsTrue(result.Success);
                if (delay != TimeSpan.Zero)
                {
                    Thread.Sleep(delay);
                }

                WriteLine(string.Format("{1} cleanly exited after running 1 of {0} commands", cmdCnt6, t6Name));
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                return;
            }
            catch (Exception ex)
            {
                WriteLine(string.Format("cmdThreadProc6 failed with exception: {0}\r\n{1}", ex.Message, ex.StackTrace));
                runThreadExeptions.Add(new RunThreadException(6, ex));
                //Assert.Fail("cmdThreadProc6a failed with exception", ex.Message);
            }
        }
Example #19
0
 public P4CommandResultWrapper(P4Command p4Command, P4CommandResult p4Result)
 {
     m_p4Command = p4Command;  m_p4Result = p4Result;
 }