Exemple #1
0
        /// <summary>
        /// Create a list of new P4Exceptions
        /// </summary>
        /// <param name="cmd">command which was run</param>
        /// <param name="args">arguments to the command</param>
        /// <param name="errors">The list of errors which caused the exception</param>
        /// <param name="nDetails">The info output of the command which caused the exception</param>
        internal P4Exception(string cmd, string[] args, P4ClientErrorList errors, P4ClientInfoMessageList nDetails)
        {
            if (errors.Count < 1)
            {
                return;
            }
            cmdLine = cmd;
            if (args != null)
            {
                for (int idx = 0; idx < args.Length; idx++)
                {
                    if (string.IsNullOrEmpty(args[idx]) == false)
                    {
                        cmdLine += " " + args[idx];
                    }
                }
            }
            errorLevel = errors[0].SeverityLevel;
            errorCode  = errors[0].ErrorCode;
            message    = errors[0].ErrorMessage;
            P4Exception currentException = this;

            for (int idx = 1; idx < errors.Count; idx++)
            {
                currentException.nextError = new P4Exception(errors[idx]);
                currentException           = currentException.nextError;
            }
            details = nDetails;
        }
Exemple #2
0
 /// <summary>
 /// Throw if any error in the list exceeds minLevel
 /// </summary>
 /// <param name="errors">List of client errors causing the exception</param>
 /// <param name="details">P4ClientInfoMessageList details</param>
 internal static void Throw(P4ClientErrorList errors, P4ClientInfoMessageList details)
 {
     foreach (P4ClientError current in errors)
     {
         if (current.SeverityLevel >= minLevel)
         {
             throw new P4Exception(errors, details);
         }
     }
 }
Exemple #3
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;
        }
Exemple #4
0
        /// <summary>
        /// Create a list of new P4Exceptions
        /// </summary>
        /// <param name="errors">The list of errors which caused the exception</param>
        /// <param name="nDetails">The info output of the command which caused the exception</param>
        internal P4Exception(P4ClientErrorList errors, P4ClientInfoMessageList nDetails)
        {
            if (errors.Count < 1)
            {
                return;
            }
            errorLevel = errors[0].SeverityLevel;
            errorCode  = errors[0].ErrorCode;
            message    = errors[0].ErrorMessage;
            P4Exception currentException = this;

            for (int idx = 1; idx < errors.Count; idx++)
            {
                currentException.nextError = new P4Exception(errors[idx]);
                currentException           = currentException.nextError;
            }
            details = nDetails;
        }
        /// <summary>
        /// Create a P4CommandResult by running a command
        /// </summary>
        /// <param name="cmd">Command to run</param>
        /// <param name="flags">Flags for the command</param>
        public P4CommandResult(P4Command cmd, StringList flags)
        {
            try
            {
                _cmd = cmd.Cmd;
                if ((flags != null) || (cmd.Args != null))
                {
                    int argc = ((flags != null) ? flags.Count : 0) + ((cmd.Args != null) ? cmd.Args.Count : 0);
                    if (argc > 0)
                    {
                        _args = new string[argc];
                        argc  = 0;
                        if (flags != null)
                        {
                            for (int idx = 0; idx < flags.Count; idx++)
                            {
                                _args[argc++] = flags[idx];
                            }
                        }
                        if (cmd.Args != null)
                        {
                            for (int idx = 0; idx < cmd.Args.Count; idx++)
                            {
                                _args[argc++] = cmd.Args[idx];
                            }
                        }
                    }
                }
                success = cmd.RunInt(flags);
            }
            finally
            {
                TimeStamp = DateTime.Now;

                infoOutput   = cmd.InfoOutput;
                errorList    = cmd.ErrorOutput;
                textOutput   = cmd.TextOutput;
                taggedOutput = cmd.TaggedOutput;
                binaryOutput = cmd.BinaryOutput;

                cmd.pServer.LastResults = this;
            }
        }
Exemple #6
0
        /// <summary>
        /// Run the command supplying additional arguments
        /// </summary>
        /// <param name="flags">Additional arguments inserted in front of the current arguments</param>
        /// <returns></returns>
        internal bool RunInt(StringList flags)
        {
            lock (this)
            {
                // Capture the the info output
                if (onInfoResultsDelegate != null)
                {
                    pServer.InfoResultsReceived += onInfoResultsDelegate;
                }

                // Handle any Resolve callbacks from the server
                if (CmdResolveHandler != null)
                {
                    pServer.ResolveHandler = CmdResolveHandler;
                }

                // Handle any Resolve callbacks from the server
                if (CmdResolveAHandler != null)
                {
                    pServer.ResolveAHandler = CmdResolveAHandler;
                }

                // Handle any prompts for input from the server
                if (CmdPromptHandler != null)
                {
                    pServer.PromptHandler = CmdPromptHandler;
                }

                // clear any saved results
                infoOutput = new P4ClientInfoMessageList();

                Exception lastError = null;

                bool success = false;
                try
                {
                    StringList paramList = flags + args;

                    pServer.EchoCommand(cmd, paramList);

                    while (true)
                    {
                        //retries--;
                        try
                        {
                            success = pServer.RunCommand(cmd,
                                                         CommandId,
                                                         tagged,
                                                         paramList,
                                                         paramList == null ? 0 : paramList.Count);
                            break;
                        }
                        catch (P4Exception ex)
                        {
                            if (ex is P4CommandCanceledException)
                            {
                                throw;
                            }
                            if (ex is P4CommandTimeOutException)
                            {
                                if (Connection != null)
                                {
                                    Connection.Disconnect();
                                }
                                throw;
                            }
                            if (lastError != null)
                            {
                                if (Connection != null)
                                {
                                    Connection.Disconnect();
                                }
                                // been here before, so don't try again
                                string      msg  = string.Format("The connection to the Perforce server at {0} has been lost", pServer.Port);
                                P4Exception p4ex = new P4LostConnectionException(ErrorSeverity.E_FATAL, msg);
                                throw;
                            }
                            lastError = ex;

                            if ((ex.Message.Contains("socket: WSA")) ||
                                P4ClientError.IsTCPError(ex.ErrorCode) || P4ClientError.IsSSLError(ex.ErrorCode))
                            {
                                try
                                {
                                    pServer.Reconnect();
                                }
                                catch
                                {
                                    if (Connection != null)
                                    {
                                        Connection.Disconnect();
                                    }
                                    string      msg  = string.Format("The connection to the Perforce server at {0} has been lost", pServer.Port);
                                    P4Exception p4ex = new P4LostConnectionException(ErrorSeverity.E_FATAL, msg);
                                    throw;
                                }
                            }
                            else
                            {
                                throw;
                            }
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    if (success)
                    {
                        // info output is gathered by OnInfoOut()
                    }
                    else
                    {
                        // info output is gathered by OnInfoOut()
                    }
                }
                catch (Exception ex)
                {
                    LogFile.LogException("P4Command", ex);
                    throw;
                }
                finally
                {
                    // Cancel the redirected the output, this will reset the callbacks if this command does not have callbacks set
                    pServer.InfoResultsReceived -= onInfoResultsDelegate;
                    pServer.PromptHandler        = null;
                    pServer.ResolveHandler       = null;
                    pServer.ResolveAHandler      = null;
                }

                return(success);
            }
        }