コード例 #1
0
        public static void OnError(Page page, bool fullStack, Exception e)
        {
            if ((page == null) || (e == null))
            {
                return;
            }

            Control error = page.Master.FindControl("Error");

            if (error != null)
            {
                error.Visible = true;
            }

            error = page.Master.FindControl("ErrorText");
            if (error != null)
            {
                Literal literal = new Literal();
                if (fullStack || ShowErrorsFullStack)
                {
                    literal.Text = e.ToString() + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    literal.Text = CodeFluentRuntimeException.GetAllMessages(e, "<br />") + Environment.NewLine + Environment.NewLine;
                }
                error.Controls.Add(literal);
            }
        }
コード例 #2
0
ファイル: WpfExtensions.cs プロジェクト: latop2604/developers
        public static string GetErrorText(this Exception exception, JsonUtilitiesOptions options)
        {
            if (exception == null)
            {
                return(null);
            }

            if (options == null)
            {
                options = new JsonUtilitiesOptions();
            }

            string error = CodeFluentRuntimeException.GetAllMessages(exception);
            string extra = null;
            var    we    = exception as WebException;

            if (we != null && we.Response != null)
            {
                Stream stream = we.Response.GetResponseStream();
                if (stream != null && stream.CanRead)
                {
                    using (var reader = new StreamReader(stream))
                    {
                        extra = reader.ReadToEnd();
                        if (we.Response.Headers[HttpResponseHeader.ContentType] == "application/json" && extra != null)
                        {
                            options.ThrowExceptions = false;
                            var    dic = (Dictionary <string, object>)JsonUtilities.Deserialize(extra, null, options);
                            object ex;
                            if (dic.TryGetValue("Exception", out ex))
                            {
                                if (ex != null)
                                {
                                    extra = string.Format("{0}", ex);
                                }
                                else
                                {
                                    // try without deserialization
                                    options.SerializationOptions &= ~JsonSerializationOptions.UseISerializable;
                                    var dic2 = (Dictionary <string, object>)JsonUtilities.Deserialize(extra, null, options);
                                    if (dic2.TryGetValue("Exception", out ex) && ex is IDictionary <string, object> )
                                    {
                                        var dicex = (IDictionary <string, object>)ex;
                                        var sb    = new StringBuilder(Environment.NewLine);
                                        sb.AppendLine("Source: " + dicex.GetValue <string>("Source", null));
                                        sb.AppendLine("Message: " + dicex.GetValue <string>("Message", null));
                                        sb.AppendLine("Class: " + dicex.GetValue <string>("ClassName", null));
                                        sb.AppendLine(dicex.GetValue <string>("StackTraceString", null));
                                        extra = sb.ToString();
                                    }
                                    else
                                    {
                                        if (dic.TryGetValue("FullMessage", out ex))
                                        {
                                            extra = string.Format("{0}", ex);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (extra != null)
            {
                return(error + Environment.NewLine + extra);
            }

            return(error);
        }