public static void BindErrorMessage(this ICSharpCode.TextEditor.TextEditorControl txt, string sql, Exception ex)
        {
            var sb = new StringBuilder();

            if (!(ex is TaosException))
            {
                sb.AppendLine(ex.Message);
                sb.AppendLine();
                sb.AppendLine("===================================================");
                sb.AppendLine(ex.StackTrace);
            }
            else
            {
                var tex = ex as TaosException;
                sb.AppendLine($"Error code: {tex.ErrorCode}");
                sb.AppendLine($"Error message:{tex.Message}");
                if (tex.Data != null)
                {
                    foreach (string item in tex.Data.Keys)
                    {
                        sb.AppendLine($"{item}:{tex.Data[item]}");
                    }
                }
                sb.AppendLine("===================================================");
                sb.AppendLine(tex.StackTrace);
            }

            txt.Highlighting = null;
            txt.Clear();
            txt.Text = sb.ToString();
        }
Exemple #2
0
        public static void BindErrorMessage(this ICSharpCode.TextEditor.TextEditorControl txt, string sql, Exception ex)
        {
            var sb = new StringBuilder();

            if (!(ex is LiteException))
            {
                sb.AppendLine(ex.Message);
                sb.AppendLine();
                sb.AppendLine("===================================================");
                sb.AppendLine(ex.StackTrace);
            }
            else if (ex is LiteException lex)
            {
                sb.AppendLine(ex.Message);

                if (lex.ErrorCode == LiteException.UNEXPECTED_TOKEN && sql != null)
                {
                    var p      = (int)lex.Position;
                    var start  = (int)Math.Max(p - 30, 1) - 1;
                    var end    = Math.Min(p + 15, sql.Length);
                    var length = end - start;

                    var str = sql.Substring(start, length).Replace('\n', ' ').Replace('\r', ' ');
                    var t   = length - (end - p);

                    sb.AppendLine();
                    sb.AppendLine(str);
                    sb.AppendLine("".PadLeft(t, '-') + "^");
                }
            }

            txt.Highlighting = null;
            txt.Clear();
            txt.Text = sb.ToString();
        }
Exemple #3
0
        public static void BindParameter(this ICSharpCode.TextEditor.TextEditorControl txt, TaskData data)
        {
            txt.SuspendLayout();
            txt.Clear();
            txt.SetHighlighting("JSON");

            var sb = new StringBuilder();

            using (var writer = new StringWriter(sb))
            {
                var w = new JsonWriter(writer)
                {
                    Pretty = true,
                    Indent = 2
                };

                w.Serialize(data.Parameters ?? BsonValue.Null);
            }

            txt.Text = sb.ToString();
            txt.ResumeLayout();
        }