/// <summary>
        /// Writes a summary report into ITextRender
        /// </summary>
        /// <param name="ex">The ex.</param>
        /// <param name="sb">The sb.</param>
        /// <param name="summaryTitle">The summary title.</param>
        /// <returns></returns>
        public static String reportSummary(this Exception ex, ITextRender sb = null, String summaryTitle = "")
        {
            if (sb == null)
            {
                sb = new builderForMarkdown();
            }
            if (String.IsNullOrEmpty(summaryTitle))
            {
                summaryTitle = "Exception" + ex.GetType().Name;
            }

            //sb.open(htmlTagName.div, htmlClassForReport.noteContainer, htmlIdForReport.innerException);

            sb.AppendPair(summaryTitle + " message: ", ex.Message, true, "");

            sb.Append(summaryTitle + " stack: ", appendType.heading_3, true);
            //, htmlTagName.p, , "", false);

            ex.StackTrace.cleanStackTrace(sb);

            callerInfo ci = new callerInfo();

            sb.AppendLine(ex.Source);

            sb.AppendLine(ex.StackTrace);

            // sb.close();

            return(sb.ToString());
        }
        /// <summary>
        /// Google search about the exception
        /// </summary>
        /// <param name="ex">The ex.</param>
        /// <param name="ci">The ci.</param>
        public static void googleException(this Exception ex, callerInfo ci)
        {
            if (ex == null)
            {
                return;
            }
            String urlFormat = @"https://www.google.com/?q={0}&safe=off";
            String search    = ci.methodBase.DeclaringType.Name + "." + ci.methodName + "() " +
                               ex.GetType().FullName + " " + ex.Message;

            search = Uri.EscapeDataString(search);
            externalTool.chrome.run(String.Format(urlFormat, search));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the caller information report.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public static String getCallerInfoReport(this callerInfo output)
        {
            builderForMarkdown sb = new builderForMarkdown();

            sb.Append("Caller info report:", appendType.heading_3, true);

            sb.nextTabLevel();
            // sb.AppendLine("Caller method: " + labelFormat);

            sb.AppendPair("Call in code: ", output.sufix);


            sb.AppendPair("Method name: ", output.className);

            sb.AppendPair("Source file: ", output.Filepath);

            sb.Append("Source call line: ", appendType.bold, true);

            sb.Append(output.sourceCodeLine, appendType.source, true);

            sb.Append("Source call line segment: ", appendType.regular, true);
            sb.Append(output.sourceCodeInvokePart, appendType.source, true);

            sb.Append("Caller method local variables:", appendType.heading_4);
            sb.nextTabLevel();

            output.localVariables.ForEach(
                x => sb.Append(
                    String.Format("{0}:{1} {2}", x.LocalIndex, x.LocalType.Name, x.toStringSafe()), appendType.quotation)
                );
            sb.prevTabLevel();

            sb.AppendPair("Caller source line properties:", output.sourceCodeParameterCalls.toCsvInLine());

            sb.prevTabLevel();

            sb.prevTabLevel();

            return(sb.ToString());
        }
        /// <summary>
        /// Appends the exception.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="ex">The ex.</param>
        /// <param name="exceptionLevel">The exception level.</param>
        public void AppendException(String title, Exception ex, Int32 exceptionLevel = 0)
        {
            lock (AppendExceptionLock)
            {
                throw new aceGeneralException("Exception: " + ex.Message, ex, this, title);

                open("Exception", title);

                if (ex == null)
                {
                    AppendLine("Exception: [null]");
                    return;
                }

                ex.describe(this, "");
                callerInfo   ci     = null;
                StackFrame[] frames = null;

                if (ex is aceGeneralException)
                {
                    aceGeneralException axe = (aceGeneralException)ex;
                    ci = axe.callInfo;
                }
                else
                {
                    StackTrace st = new StackTrace(ex, true);
                    StackFrame sf = st.GetFrame(0);
                    if (sf == null)
                    {
                        aceGeneralException axe = new aceGeneralException("WrapperException for " + ex.GetType().Name, ex, this, title);
                        ci = axe.callInfo;
                    }
                    else
                    {
                        ci = callerInfo.getCallerInfo(sf, true);
                    }

                    frames = st.GetFrames();
                }

                if (exceptionLevel == 0)
                {
                    AppendTable(ci.AppendDataFields());
                }

                AppendTable(ci.AppendDataFieldsOfMethod());

                open("parents", "Parent StackFrames");

                List <String> sfi_strings = new List <string>();
                Int32         c           = 0;
                if (frames != null)
                {
                    foreach (StackFrame sfi in frames)
                    {
                        if (c != 0)
                        {
                            open("frame", "StackFrame(" + c.ToString() + ")");

                            callerInfo sfi_ci = callerInfo.getCallerInfo(sfi, true);

                            AppendTable(sfi_ci.AppendDataFieldsOfMethod());
                            close();
                        }
                        c++;

                        //sfi.GetFileLineNumb
                    }
                }
                close();

                if (ex.InnerException != null)
                {
                    AppendException("InnerException [level:" + exceptionLevel + "]", ex.InnerException, exceptionLevel + 1);
                }

                close();
            }
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sf"></param>
        /// <param name="getCode">Kompleksnija operacija - daje vise informacija</param>
        /// <returns></returns>
        public static callerInfo getCallerInfo(StackFrame sf, Boolean getCode = true)
        {
            callerInfo output = new callerInfo();

            if (sf == null)
            {
                Exception ex = new aceGeneralException("Exception had no *StackFrame* --- don-t use explicit throwing after the Exception was caught");
                throw ex;
            }
            else
            {
            }

            MethodBase mb = sf.GetMethod();


            //MethodBodyReader.GetInstructions(output.methodBase);

            output.methodBase = mb;
            output.methodBody = mb.GetMethodBody();
            output.parameters = mb.GetParameters();

            output.methodInfo = output.methodBase as MethodInfo;


            output.callerType     = mb.DeclaringType;
            output.callerTypeInfo = output.callerType;

            output.methodName = output.callerType.FullName + "." + mb.Name + "()";

            if (output.callerTypeInfo == null)
            {
                output.className = "callerTypeInfo is null";
            }
            else
            {
                output.className = output.callerType.FullName; // + "." + mb.Name + "()";
            }
            output.line     = sf.GetFileLineNumber();
            output.column   = sf.GetFileColumnNumber();
            output.Filepath = sf.GetFileName();


            if (output.methodBody != null)
            {
                output.localVariables = output.methodBody.LocalVariables.ToList();
            }


            if (getCode)
            {
                if (output.callerType != null)
                {
                    output.methodInfo = output.callerType.GetMethod(mb.Name, new[] { output.callerType }); //  output.callerTypeInfo.findMethod(mb); //.Name, output.parameters);

                    if (!String.IsNullOrEmpty(output.Filepath))
                    {
                        output.sourceCodeFile = output.Filepath.openFileToList(false, Encoding.UTF8);// open.openFile(output.filepath);
                        output.sourceCodeLine = output.sourceCodeFile[output.line - 1];

                        output.sourceCodeInvokePart = output.sourceCodeLine.Substring(output.column);
                        String ln = methodParameters.Match(output.sourceCodeInvokePart).Value;
                        output.sourceCodeInvokeParamsPart = ln;
                        var propCalls = methodParametersEach.Matches(ln);
                        output.sourceCodeParameterCalls = new List <String>();

                        foreach (Match m in propCalls)
                        {
                            output.sourceCodeParameterCalls.Add(m.Value.Trim("()".ToCharArray()));
                        }
                        //if (output.sourceCodeParameterCalls.Any()) output.sourceCodeParameterCalls.RemoveAt(0);
                    }
                    else
                    {
                        output.sourceCodeLine = " { unknown file location }";
                    }
                }
            }

            if (output.callerType != null)
            {
                output.label = String.Format(labelFormat, output.callerType.FullName, output.methodName,
                                             output.sourceCodeInvokeParamsPart);
            }
            else
            {
                output.label = "Output caller type info is null";
            }
            output.sufix = String.Format(sufixFormat, output.Filepath, output.line, output.column);

            return(output);
        }