Beispiel #1
0
        // return false if user canceled login
        private bool CheckLogin(Connection connection)
        {
            bool result       = true;
            bool requireLogin = false;

            try
            {
                var cmd = new P4Command(connection, "login", true, "-s");
                cmd.Run(null);
            }
            catch (P4Exception ex)
            {
                if (ex.ErrorLevel >= ErrorSeverity.E_FAILED) //"Perforce password (P4PASSWD) invalid or unset.\n"}    int
                {
                    requireLogin = true;
                }
            }

            LoginDialog loginDialog = null;

            while (requireLogin)
            {
                if (loginDialog == null)
                {
                    loginDialog = new LoginDialog();
                    string message = string.Format("For user {0} with workspace {1} on server {2}.".Localize(),
                                                   connection.UserName, connection.Client.Name, connection.Server.Address.Uri);

                    loginDialog.SetConnectionLabel(message);
                    if ((MainForm != null) && (MainForm.Icon != null))
                    {
                        loginDialog.Icon = MainForm.Icon;
                    }
                }

                DialogResult dr = loginDialog.ShowDialog(MainForm);
                if (dr == DialogResult.OK)
                {
                    try
                    {
                        var credential = connection.Login(loginDialog.Password);
                        requireLogin = credential == null;
                    }
                    catch (P4Exception e)
                    {
                        ShowErrorMessage(e.Message);
                        if (ThrowExceptions)
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
        private void btn_download_Click(object sender, EventArgs e)
        {
            this.tb_runinfo.Text = "------------------------------------ START ------------------------------------\r\n";
            var server    = this.comBox_Server.Text;
            var user      = this.comBox_User.Text;
            var workspace = this.comBox_Workspace.Text;
            var password  = this.tb_Password.Text;

            this.panel_set.Enabled    = false;
            this.btn_download.Enabled = false;

            try
            {
                Server     conServer = new Server(new ServerAddress(server));
                Repository rep       = new Repository(conServer);
                Connection con       = rep.Connection;
                con.UserName    = user;
                con.Client      = new Client();
                con.Client.Name = workspace;
                con.Connect(null);
                Credential cred = con.Login(password, null, null);

                foreach (var file in ls_filelist)
                {
                    addRunInfo(file);
                    P4Command cmd  = new P4Command(rep, "sync", true, file);
                    Options   opts = new Options();
                    opts["-f"] = null;
                    var    results     = cmd.Run(opts);
                    String str_msgtext = "";
                    foreach (var msg in results.TaggedOutput)
                    {
                        if (msg.ContainsKey("totalFileCount"))
                        {
                            str_msgtext = str_msgtext + "\t" + "Total File Count: " + msg["totalFileCount"] + "\r\n";
                        }

                        if (msg.ContainsKey("change"))
                        {
                            str_msgtext = str_msgtext + "\t" + "ChangeList: " + msg["change"] + "\r\n";
                        }
                    }
                    this.tb_runinfo.Text = this.tb_runinfo.Text + "\r\n" + str_msgtext;
                }

                this.tb_runinfo.Text += "\r\n------------------------------------ END ------------------------------------";
                MessageBox.Show("Download completed!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (P4Exception p4ex)
            {
                this.tb_runinfo.Text += "\r\n------------------------------------ ERROR ------------------------------------";
                MessageBox.Show(p4ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.panel_set.Enabled    = true;
            this.btn_download.Enabled = true;
        }
        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);
            }
        }
Beispiel #4
0
        public void ArgsTest()
        {
            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);

                        StringList expected = new StringList(new string[] { "a", "b", "c" });
                        target.Args = expected;

                        StringList actual = target.Args;

                        Assert.AreEqual(expected, actual);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
            // reset the exception level
            P4Exception.MinThrowLevel = oldExceptionLevel;
        }
Beispiel #5
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;
        }
Beispiel #6
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);
        }
        private void RefreshConnectionImpl()
        {
            DisconnectImpl();
            Init();

            _perforceRoot = _repository.GetClientMetadata().Root;

            var error_msg_start = GetStateDescription(ConnectionState.Connected);

            if (!IsPerforceRootFound())
            {
                DisconnectImpl();
                throw new P4Exception(ErrorSeverity.E_FAILED, error_msg_start + " \nError: \nWorkspace root is unset or doesn't exist");
            }

            if (!_connection.connectionEstablished() || _connection.GetActiveTicket() == null)
            {
                DisconnectImpl();
                throw new P4Exception(ErrorSeverity.E_FAILED, error_msg_start);
            }

            // check ticket exists and valid.
            var cmd = new P4Command(_connection, "login", true, new string[] { "-s" }); // p4 login -s get status of the ticket

            try
            {
                // P4Exception will be thrown in case user is not logged in
                cmd.Run();
            }
            catch (P4Exception ex)
            {
                DisconnectImpl();
                throw new P4Exception(ErrorSeverity.E_FAILED, error_msg_start + " \nError: \n" + ex.Message);
            }

            // this ticket should belong to current user
            var output = cmd.TextOutput;

            if (cmd.TaggedOutput[0]["User"] != _connection.UserName)
            {
                DisconnectImpl();
                throw new P4Exception(ErrorSeverity.E_FAILED, error_msg_start + " \nError: \nP4USER variable don't correspond to logged in user.");
            }

            _state = ConnectionState.Success;
        }
Beispiel #8
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);
        }
Beispiel #9
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);
            }
        }
Beispiel #10
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);
            }
        }
        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);
            }
        }
Beispiel #13
0
 private void ReportCommandStart(P4Command cmd, DateTime time)
 {
     WriteLine(string.Format("Thread {2} starting command: {0:X8}, at {1}",
                             cmd1.CommandId, time.ToLongTimeString(), Thread.CurrentThread.ManagedThreadId));
 }
Beispiel #14
0
 public P4CommandResultWrapper(P4Command p4Command, P4CommandResult p4Result) { m_p4Command = p4Command;  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;
            }
        }
Beispiel #16
0
        // return false if user canceled login
        private bool CheckLogin(Connection connection)
        {
            bool result = true;
            bool requireLogin = false;
            P4Command cmd = null;
            try
            {
                if (connection.Server.State == ServerState.Online)
                {
                    cmd = new P4Command(connection, "login", true, "-s");
                    cmd.Run(null);
                }
                else
                {
                    requireLogin = true;
                }
            }
            catch (P4Exception ex)
            {
                if (ex.ErrorLevel >= ErrorSeverity.E_FAILED)
                    //"Perforce password (P4PASSWD) invalid or unset.\n"}    int
                    requireLogin = true;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }

            LoginDialog loginDialog = null;

            while (requireLogin)
            {
                if (loginDialog == null)
                {
                    loginDialog = new LoginDialog();
                    string message = string.Format("For user {0} with workspace {1} on server {2}.".Localize(),
                        connection.UserName, connection.Client.Name, connection.Server.Address.Uri);

                    loginDialog.SetConnectionLabel(message);
                    if ((MainForm != null) && (MainForm.Icon != null))
                        loginDialog.Icon = MainForm.Icon;
                }

                DialogResult dr = loginDialog.ShowDialog(MainForm);
                if (dr == DialogResult.OK)
                {
                    try
                    {
                        if (connection.Server.State != ServerState.Online)
                        {
                            ConnectionOptions["Password"] = loginDialog.Password;
                            connection.Connect(ConnectionOptions);
                            requireLogin = connection.Server.State != ServerState.Online;
                        }
                        else
                        {
                            var credential = connection.Login(loginDialog.Password);
                            requireLogin = credential == null;
                        }
                    }
                    catch (P4Exception e)
                    {
                        ShowErrorMessage(e.Message);
                        if (ThrowExceptions)
                            throw;
                    }
                }
                else
                {
                    result = false;
                    break;
                }
            }
            return result;
        }
Beispiel #17
0
 private void ReportCommandStop(P4Command cmd, DateTime time)
 {
     WriteLine(string.Format("Thread {3} Finished command: {0:X8}, at {1}, run time {2} Milliseconds",
                             cmd1.CommandId, time.ToLongTimeString(), (DateTime.Now - time).TotalMilliseconds, Thread.CurrentThread.ManagedThreadId));
 }
Beispiel #18
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);
            }
        }
        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);
            }
        }
Beispiel #20
0
 public P4CommandResultWrapper(P4Command p4Command, P4CommandResult p4Result)
 {
     m_p4Command = p4Command;  m_p4Result = p4Result;
 }