Esempio n. 1
0
 /// <summary>
 /// Create and throw an exception if it exceeds the MinThrowLevel
 /// </summary>
 /// <param name="cmd">command which was run</param>
 /// <param name="args">arguments to the command</param>
 /// <param name="error">Client error causing the exception</param>
 public static void Throw(string cmd, string[] args, P4ClientError error)
 {
     if (error.SeverityLevel >= minLevel)
     {
         throw new P4Exception(cmd, args, error);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Create and throw an exception if it exceeds the MinThrowLevel
 /// </summary>
 /// <param name="error">Client error causing the exception</param>
 public static void Throw(P4ClientError error)
 {
     if (error.SeverityLevel >= minLevel)
     {
         throw new P4Exception(error);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Create a new P4Exception
 /// </summary>
 /// <param name="error">Client error causing the exception</param>
 public P4Exception(P4ClientError error)
 {
     errorCode  = error.ErrorCode;
     errorLevel = error.SeverityLevel;
     message    = error.ErrorMessage;
     nextError  = null;
 }
Esempio n. 4
0
        /// <summary>
        /// Create a new P4Exception
        /// </summary>
        /// <param name="cmd">command which was run</param>
        /// <param name="args">arguments passed to the command</param>
        /// <param name="error">Client error causing the exception</param>
        public P4Exception(string cmd, string[] args, P4ClientError error)
        {
            errorCode  = error.ErrorCode;
            errorLevel = error.SeverityLevel;
            message    = error.ErrorMessage;
            nextError  = null;

            cmdLine = cmd;
            if (args != null)
            {
                for (int idx = 0; idx < args.Length; idx++)
                {
                    if (string.IsNullOrEmpty(args[idx]) == false)
                    {
                        cmdLine += " " + args[idx];
                    }
                }
            }
        }
Esempio n. 5
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);
            }
        }