Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        public ErrorBox(Exception error, string errorDetails)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            _error = error;
            InitializeComponent();
            ErrorDetails.Visibility = Visibility.Collapsed;
            ErrorDetails.Text       = error.GetErrorText(null);
            if (!string.IsNullOrWhiteSpace(errorDetails))
            {
                ErrorDetails.Text += Environment.NewLine + Environment.NewLine + "-- Details -- " + Environment.NewLine + Environment.NewLine + errorDetails;
            }
            ErrorDetails.Text += Environment.NewLine + Environment.NewLine + "-- Diagnostics -- " + Environment.NewLine + Environment.NewLine + GetDebugInformation();
            Image.Source       = WpfExtensions.GetStockIcon(WindowsUtilities.StockIconId.ERROR, WindowsUtilities.SHGSI.SHGSI_LARGEICON);
            Error.Text         = CodeFluentRuntimeException.GetInterestingExceptionMessage(error);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public virtual string Produce(bool addFile)
        {
            Hashtable dic = new Hashtable();

            dic.Add("Project", CodeDomProducer.Project);
            dic.Add("Producer", CodeDomProducer);
            dic.Add("TemplateProducer", this);
            string productionTargetPath = CodeDomProducer.GetProductionTargetPath(ProductionNode, FinalizeTargetPath(), IsWebType, false);
            string tempPath             = (CodeDomProducer.TargetProductionOptions & TargetProductionOptions.CreateTempFile) == TargetProductionOptions.None ? null : productionTargetPath + ".tmp";

            dic.Add("TargetPath", productionTargetPath);
            dic.Add("TempTargetPath", tempPath);
            if (!RaiseProducing(dic))
            {
                return(null);
            }

            try
            {
                if (tempPath == null)
                {
                    BaseProducer.CreateFileDirectory(productionTargetPath, CodeDomProducer);
                    BaseProducer.PathUnprotect(productionTargetPath, CodeDomProducer);
                }
                else
                {
                    BaseProducer.CreateFileDirectory(tempPath, CodeDomProducer);
                }

                bool append = false;
                if (File.Exists(productionTargetPath) && CodeDomProducer.IsGeneratedFile(productionTargetPath))
                {
                    if (tempPath != null)
                    {
                        IOUtilities.PathOverwrite(productionTargetPath, tempPath, true);
                    }
                    append = true;
                }
                string target = tempPath ?? productionTargetPath;
                try
                {
                    var unit = CreateCodeCompileUnit();
                    if (unit == null)
                    {
                        return(null);
                    }

                    IOUtilities.WrapSharingViolations(() =>
                    {
                        using (StreamWriter streamWriter = new StreamWriter(target, append, CodeDomProducer.OutputEncoding))
                        {
                            IndentedTextWriter indentedTextWriter = ((CodeDomProducer.ProductionFlags & ProductionFlags.RemoveDates) != ProductionFlags.RemoveDates ? new IndentedTextWriter(streamWriter) : new NoDiffIndentedTextWriter(streamWriter));
                            CodeDomProducer.CodeDomProvider.GenerateCodeFromCompileUnit(unit, indentedTextWriter, CodeDomProducer.CodeGeneratorOptions);
                        }
                    });
                }
                catch (Exception ex)
                {
                    CodeFluentRuntimeException violationException = IOUtilities.GetSharingViolationException(target, ex);
                    if (violationException != null)
                    {
                        throw violationException;
                    }

                    throw;
                }

                if (File.Exists(tempPath ?? productionTargetPath))
                {
                    CodeDomProducer.RaiseProduction(this, ProductionEventArgs.CreateFileWriteEvent(productionTargetPath, GetType().FullName));
                    if (tempPath != null)
                    {
                        BaseProducer.FileOverwrite(tempPath, productionTargetPath, CodeDomProducer, false);
                    }

                    CodeDomProducer.AddToGeneratedFiles(productionTargetPath);
                }
            }
            finally
            {
                if (tempPath != null && File.Exists(tempPath))
                {
                    File.Delete(tempPath);
                }
            }

            RaiseProduced();
            if (addFile)
            {
                CodeDomProducer.AddFileName(productionTargetPath);
            }

            return(productionTargetPath);
        }