Ejemplo n.º 1
0
        //------------------------------------------------------------
        // CSResources.FormatErrorMessage (2)
        //
        /// <summary>
        /// <para>Get the format string by id, create an error message with args and locations</para>
        /// </summary>
        /// <param name="excp"></param>
        /// <param name="errorNo"></param>
        /// <param name="strID"></param>
        /// <param name="errorKind"></param>
        /// <param name="fileName"></param>
        /// <param name="line"></param>
        /// <param name="col"></param>
        /// <param name="lineEnd"></param>
        /// <param name="colEnd"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        static internal string FormatErrorMessage(
            out Exception excp,
            ERRORKIND errorKind,
            string prefix,
            int errorNo,
            ResNo resNo,
            string fileName,
            int line,
            int col,
            int lineEnd,
            int colEnd,
            params Object[] args)
        {
            string message = null;

            if (!ErrorUtil.FormatErrorMessage(out message, out excp, resNo, args) &&
                String.IsNullOrEmpty(message))
            {
                // If failed to format, concatenate args to create a message.
                if (args.Length > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < args.Length; ++i)
                    {
                        string str = args[i].ToString();
                        if (!String.IsNullOrEmpty(str))
                        {
                            if (sb.Length > 0)
                            {
                                sb.Append(", ");
                            }
                            sb.Append(str);
                        }
                    }
                    if (sb.Length > 0)
                    {
                        message = sb.ToString();
                    }
                }
                if (String.IsNullOrEmpty(message))
                {
                    message = "Unknown error.";
                }
            }

            return(FormatStringUtil.FormatErrorMessageCore(
                       fileName,
                       line,
                       col,
                       lineEnd,
                       colEnd,
                       errorKind,
                       prefix,
                       errorNo,
                       message));
        }
Ejemplo n.º 2
0
        //------------------------------------------------------------
        // CController.ReportError (1)
        //
        /// <summary></summary>
        /// <param name="kind"></param>
        /// <param name="message"></param>
        //------------------------------------------------------------
        internal void ReportError(ERRORKIND kind, string message)
        {
            CountReportedError(kind);

            string buffer = FormatStringUtil.FormatErrorMessageCore(
                null, -1, -1, -1, -1,
                kind,
                null, -1,
                message);

            WriteLine(buffer);
        }
Ejemplo n.º 3
0
        //------------------------------------------------------------
        // ConsoleOutput.FormatString
        //
        /// <summary></summary>
        /// <param name="fmt"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        protected string FormatString(string fmt, params Object[] args)
        {
            string    buffer;
            Exception excp = null;

            if (FormatStringUtil.FormatString(out buffer, out excp, fmt, args))
            {
                return(buffer);
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0}: ",
                            (excp != null ? excp.Message : "Failed to Format"));
            foreach (Object obj in args)
            {
                sb.AppendFormat(", {0}", obj);
            }
            return(sb.ToString());
        }
Ejemplo n.º 4
0
        //------------------------------------------------------------
        // CController.ShowMessage (3)
        //
        /// <summary></summary>
        /// <param name="msg"></param>
        //------------------------------------------------------------
        internal void ShowMessage(ResNo resNo, params Object[] args)
        {
            string    fmt   = null;
            int       count = 0;
            Exception excp  = null;

            if (CResources.GetString(resNo, out fmt, out count, out excp))
            {
                FormatStringUtil.FillupArguments(ref args, count);
                WriteLine(fmt, args);
            }
            else
            {
                if (excp != null)
                {
                    WriteLine(excp.Message);
                }
                else
                {
                    WriteLine("Unknow error in ShowMessage");
                }
            }
        }
Ejemplo n.º 5
0
        //------------------------------------------------------------
        // ErrorUtil.FormatErrorMessage (1)
        //
        /// <summary>
        /// <para>Get the format string by id, create an error message with args</para>
        /// </summary>
        /// <param name="formatted"></param>
        /// <param name="excp"></param>
        /// <param name="strID"></param>
        /// <param name="args"></param>
        /// <returns>Return false if failed to make an error message.</returns>
        //------------------------------------------------------------
        static internal bool FormatErrorMessage(
            out string formatted,
            out Exception excp,
            ResNo resNo,
            params Object[] args)
        {
            formatted = null;
            int    argCount = 0;
            string format   = null;

            excp = null;

            if (CResources.GetString(resNo, out format, out argCount, out excp))
            {
                return(FormatStringUtil.FormatString(
                           out formatted,
                           out excp,
                           format,
                           argCount,
                           args));
            }
            return(false);
        }