Example #1
0
 private static void Exit(string message, bool interactive, SystemErrorCodes exitCode = SystemErrorCodes.ERROR_SUCCESS)
 {
     Console.WriteLine();
     Console.WriteLine();
     Console.WriteLine(message);
     Console.WriteLine();
     if (interactive)
     {
         Console.WriteLine("Nothing else to do, you can now close the application window");
         Console.ReadLine();
     }
     Environment.Exit((int)exitCode);
 }
        /// <summary>
        ///     Extracts the Configuration attribute from the SystemErrorCodes enum
        /// </summary>
        /// <param name="arg">SystemErrorCodes enum</param>
        /// <returns>Configuration attribute</returns>
        private static Configuration GetAttribute(SystemErrorCodes arg)
        {
            FieldInfo fieldInfo = arg.GetType().GetField(arg.ToString());

            if (fieldInfo == null)
            {
                return(null);
            }
            object attr = fieldInfo.GetCustomAttributes(typeof(Configuration), true).FirstOrDefault();

            if (attr == null)
            {
                return(null);
            }
            return((Configuration)attr);
        }
Example #3
0
        /// <summary>
        /// 连续运行模式,支持打开某程序后,持续向其输入命令,直到结束。
        /// </summary>
        /// <param name="exePath"></param>
        /// <param name="args"></param>
        /// <param name="moreArgs"></param>
        /// <returns></returns>
        public static RunResult RunAsContinueMode(string exePath, string args, string[] moreArgs)
        {
            var result = new RunResult();

            try
            {
                using (var p = GetProcess())
                {
                    p.StartInfo.FileName  = exePath;
                    p.StartInfo.Arguments = args;
                    p.Start();

                    //先输出一个换行,以便将程序的第一行输出显示出来。
                    //如adb.exe,假如不调用此函数的话,第一行等待的shell@android:/ $必须等待下一个命令输入才会显示。
                    p.StandardInput.WriteLine();

                    result.OutputString = ReadStandardOutputLine(p);

                    result.MoreOutputString = new Dictionary <int, string>();
                    for (int i = 0; i < moreArgs.Length; i++)
                    {
                        p.StandardInput.WriteLine(moreArgs[i] + '\r');

                        //必须等待一定时间,让程序运行一会儿,马上读取会读出空的值。
                        Thread.Sleep(WaitTime);

                        result.MoreOutputString.Add(i, ReadStandardOutputLine(p));
                    }

                    p.WaitForExit();
                    result.ExitCode = p.ExitCode;
                    result.Success  = true;
                }
            }
            catch (Win32Exception ex)
            {
                result.Success      = false;
                result.OutputString = string.Format("{0},{1}", ex.NativeErrorCode, SystemErrorCodes.ToString(ex.NativeErrorCode));
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.OutputString = ex.ToString();
            }
            return(result);
        }
Example #4
0
        internal void Raise(string exceptionName)
        {
            if (String.IsNullOrEmpty(exceptionName))
            {
                throw new ArgumentNullException("exceptionName");
            }

            AssertNotFinished();

            try {
                var statement = Statement;
                while (statement != null)
                {
                    if (statement is PlSqlBlockStatement)
                    {
                        var block = (PlSqlBlockStatement)statement;
                        if (block.Handles(exceptionName))
                        {
                            block.FireHandler(this, exceptionName);
                            return;
                        }
                    }

                    statement = statement.Parent;
                }

                if (SystemErrorCodes.IsSystemError(exceptionName))
                {
                    var errorCode = SystemErrorCodes.GetErrorCode(exceptionName);
                    throw new StatementException(errorCode, String.Format("Exception '{0}' explicitly risen from code", exceptionName));
                }

                var declared = Request.Context.FindDeclaredException(exceptionName);
                if (declared == null)
                {
                    throw new InvalidOperationException(String.Format("Exception '{0}' was not declared in the context.", exceptionName));
                }

                throw new StatementException(declared.ErrorCode,
                                             String.Format("Declared exception '{0}' explicitly risen from code", exceptionName));
            } finally {
                Terminate();
            }
        }
Example #5
0
        public static RunResult Run(string exePath, string args)
        {
            var result = new RunResult();

            try
            {
                using (var p = GetProcess())
                {
                    p.StartInfo.FileName  = exePath;
                    p.StartInfo.Arguments = args;
                    p.Start();

                    //获取正常信息
                    if (p.StandardOutput.Peek() > -1)
                    {
                        result.OutputString = p.StandardOutput.ReadToEnd();
                    }

                    //获取错误信息
                    if (p.StandardError.Peek() > -1)
                    {
                        result.OutputString = p.StandardError.ReadToEnd();
                    }

                    p.WaitForExit();
                    result.ExitCode = p.ExitCode;
                    result.Success  = true;
                }
            }
            catch (Win32Exception ex)
            {
                result.Success      = false;
                result.OutputString = string.Format("{0},{1}", ex.NativeErrorCode, SystemErrorCodes.ToString(ex.NativeErrorCode));
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.OutputString = ex.ToString();
            }
            return(result);
        }
 /// <summary>
 ///     Gets source from enum
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static ErrorSource GetSource(this SystemErrorCodes arg)
 {
     return(GetAttribute(arg).Source);
 }
 /// <summary>
 ///     Gets error priority from enum
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static ErrorPriority GetPriority(this SystemErrorCodes arg)
 {
     return(GetAttribute(arg).Priority);
 }
 /// <summary>
 ///     Gets error description from enum
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static string GetDescription(this SystemErrorCodes arg)
 {
     return(GetAttribute(arg).Description);
 }