예제 #1
0
        private string getContext(IContextMaker contextMaker, DiffPosition position,
                                  ContextDepth depth, double fontSizePx, out string stylesheet)
        {
            stylesheet = String.Empty;
            if (contextMaker == null)
            {
                return("<html><body>Cannot access file storage and render diff context</body></html>");
            }

            try
            {
                DiffContext          context   = contextMaker.GetContext(position, depth);
                DiffContextFormatter formatter = new DiffContextFormatter(fontSizePx, 2);
                stylesheet = formatter.GetStylesheet();
                return(formatter.GetBody(context));
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException || ex is ContextMakingException)
                {
                    string errorMessage = "Cannot render HTML context.";
                    ExceptionHandlers.Handle(errorMessage, ex);
                    return(String.Format("<html><body>{0} See logs for details</body></html>", errorMessage));
                }
                throw;
            }
        }
예제 #2
0
        private string getContext(IContextMaker contextMaker, DiffPosition position,
                                  ContextDepth depth, int fontSizePx, int rowsVPaddingPx)
        {
            if (contextMaker == null || _formatter == null)
            {
                return("<html><body>Cannot access git repository and render diff context</body></html>");
            }

            try
            {
                DiffContext context = contextMaker.GetContext(position, depth);
                return(_formatter.FormatAsHTML(context, fontSizePx, rowsVPaddingPx));
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException || ex is GitOperationException || ex is GitObjectException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot render HTML context");
                    string errorMessage = System.Net.WebUtility.HtmlEncode(ex.Message).Replace("\n", "<br>");
                    return(String.Format("<html><body>{0}</body></html>", errorMessage));
                }
                throw;
            }
        }