Manos.Mvc.ExceptionRenderer.RenderLocation C# (CSharp) Method

RenderLocation() public static method

public static RenderLocation ( IHttpResponse r, string file, int line ) : void
r IHttpResponse
file string
line int
return void
        public static void RenderLocation(IHttpResponse r, string file, int line)
        {
            if (file == null)
                return;

            // Does the file exist?
            if (System.IO.File.Exists(file))
            {
                try
                {
                    var rdr = new StreamReader(file);

                    var sb = new StringBuilder();
                    r.Write("<pre>");
                    for (int i = 1; ; i++)
                    {
                        if (i > line + 2)
                            break;

                        var text = rdr.ReadLine();
                        if (text == null)
                            break;

                        if (i < line - 2)
                            continue;

                        if (i == line)
                            r.Write("<span style=\"color:red;\">");

                        r.Write("Line {0:0000}: ", i);
                        r.WriteLine(UnsafeString.Escape(text));

                        if (i == line)
                            r.Write("</span>");
                    }

                    r.WriteLine("</pre>");
                }
                catch (Exception)
                {
                    // Ignore
                }
            }

            r.Write("<p><b>Location:</b> {0} <b>Line:</b> {1}</p>\n", UnsafeString.Escape(file), line);
        }