/// <summary> /// Loads the bug. /// </summary> /// <param name="fileName">Name of the file.</param> void LoadBug(string fileName) { BugFile.Text = fileName; BugDocument xml = new BugDocument(); xml.Load(fileName); CurrentContext = ReBugContext.Create(xml); ContextExplorer.SelectedObject = new PropertyGridInspector(CurrentContext); ReBug.Enabled = true; }
/// <summary> /// Handles the Error event of the Application control. /// </summary> /// <param name="sender">The source of the event.</param> static void Application_Error(object sender) { if (IsReBug) {//Error handling is disabled. return; } HttpContext context = ((HttpApplication) sender).Context; if (context == null || context.Error == null) { return; } BugDocument bug = new BugDocument(); XmlNode root = bug.AppendChild(bug.CreateElement("bugx")); bug.CreationDate = DateTime.Now; bug.ErrorFromBot = BrowserHelper.IsKnownBot(context.Request.UserAgent); BugEventArgs bugEventArgs = new BugEventArgs(); bugEventArgs.Bug = bug; DataToSave dataToSave = BugxConfiguration.DataToSave; string errorId = BuildUniqueIdentifier(context.Error); string bugVirtualPath = "~/bugx/errors/" + context.Error.GetBaseException().GetType().FullName.Replace('.', '/') + "/" + errorId; DirectoryInfo destination = new DirectoryInfo(context.Request.MapPath(bugVirtualPath)); if (!destination.Exists) { destination.Create(); } string fileName = DateTime.Now.ToUniversalTime().ToString("/yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture) + ".bugx"; if (File.Exists(fileName)) { return; } //Minimum data to save. SaveUrl(root, context); SaveRequest(root, context); if ((dataToSave & DataToSave.Session) != 0) { SaveSession(root, context); } if ((dataToSave & DataToSave.Cache) != 0) { SaveCache(root, context); } if ((dataToSave & DataToSave.Context) != 0) { SaveContext(root, context); } if ((dataToSave & DataToSave.Application) != 0) { SaveApplication(root, context); } if ((dataToSave & DataToSave.User) != 0) { SaveUser(root, context); } if ((dataToSave & DataToSave.Exception) != 0) { SaveException(root, context); } OnError(bugEventArgs); try { bug.Save(destination.FullName + fileName); bugEventArgs.BugUri = ExceptionHelper.BuildBugUri(bugVirtualPath + "/" + fileName); bugEventArgs.BugReport = ExceptionHelper.BuildBugReportUri(bugVirtualPath + "/" + fileName); if (MaySendErrorComplete(errorId) && !BugxConfiguration.ShouldBeFiltered(errorId)) { OnErrorComplete(bugEventArgs); } }catch(IOException){}//Nothing to do if the same bug arrives twice. }
/// <summary> /// Builds the report. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="context">The context.</param> static void BuildReport(string fileName, HttpContext context) { context.Response.ContentType = "text/html"; XslCompiledTransform xsl = new XslCompiledTransform(); using (Stream xslFile = XslFile) using (XmlWriter writer = new XmlTextWriter(context.Response.Output)) { BugDocument bug = new BugDocument(); bug.Load(fileName); xsl.Load(new XmlTextReader(xslFile)); xsl.Transform(bug, XsltExtension.RegisterExtension(), writer); } }
/// <summary> /// Handles the Error event of the Application control. /// </summary> /// <param name="sender">The source of the event.</param> static void Application_Error(object sender) { if (IsReBug) {//Error handling is disabled. return; } HttpContext context = ((HttpApplication)sender).Context; if (context == null || context.Error == null) { return; } BugDocument bug = new BugDocument(); XmlNode root = bug.AppendChild(bug.CreateElement("bugx")); bug.CreationDate = DateTime.Now; bug.ErrorFromBot = BrowserHelper.IsKnownBot(context.Request.UserAgent); BugEventArgs bugEventArgs = new BugEventArgs(); bugEventArgs.Bug = bug; DataToSave dataToSave = BugxConfiguration.DataToSave; string errorId = BuildUniqueIdentifier(context.Error); string bugVirtualPath = "~/bugx/errors/" + context.Error.GetBaseException().GetType().FullName.Replace('.', '/') + "/" + errorId; DirectoryInfo destination = new DirectoryInfo(context.Request.MapPath(bugVirtualPath)); if (!destination.Exists) { destination.Create(); } string fileName = DateTime.Now.ToUniversalTime().ToString("/yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture) + ".bugx"; if (File.Exists(fileName)) { return; } //Minimum data to save. SaveUrl(root, context); SaveRequest(root, context); if ((dataToSave & DataToSave.Session) != 0) { SaveSession(root, context); } if ((dataToSave & DataToSave.Cache) != 0) { SaveCache(root, context); } if ((dataToSave & DataToSave.Context) != 0) { SaveContext(root, context); } if ((dataToSave & DataToSave.Application) != 0) { SaveApplication(root, context); } if ((dataToSave & DataToSave.User) != 0) { SaveUser(root, context); } if ((dataToSave & DataToSave.Exception) != 0) { SaveException(root, context); } OnError(bugEventArgs); try { bug.Save(destination.FullName + fileName); bugEventArgs.BugUri = ExceptionHelper.BuildBugUri(bugVirtualPath + "/" + fileName); bugEventArgs.BugReport = ExceptionHelper.BuildBugReportUri(bugVirtualPath + "/" + fileName); if (MaySendErrorComplete(errorId) && !BugxConfiguration.ShouldBeFiltered(errorId)) { OnErrorComplete(bugEventArgs); } }catch (IOException) {}//Nothing to do if the same bug arrives twice. }