| 1 | using System;
|
|---|
| 2 | using System.Text;
|
|---|
| 3 | using System.Threading;
|
|---|
| 4 | using System.Windows.Forms;
|
|---|
| 5 | using Baza_Reklam.Classes;
|
|---|
| 6 |
|
|---|
| 7 | namespace Baza_Reklam
|
|---|
| 8 | {
|
|---|
| 9 | static class Program
|
|---|
| 10 | {
|
|---|
| 11 | /// <summary>
|
|---|
| 12 | /// The main entry point for the application.
|
|---|
| 13 | /// </summary>
|
|---|
| 14 | [STAThread]
|
|---|
| 15 | static void Main()
|
|---|
| 16 | {
|
|---|
| 17 | #if !DEBUG
|
|---|
| 18 | CustomExceptionHandler exceptionHandler = new CustomExceptionHandler();
|
|---|
| 19 | Application.ThreadException += exceptionHandler.OnThreadException;
|
|---|
| 20 | #endif
|
|---|
| 21 |
|
|---|
| 22 | Application.EnableVisualStyles();
|
|---|
| 23 | Application.SetCompatibleTextRenderingDefault(false);
|
|---|
| 24 |
|
|---|
| 25 | Logowanie logowanie = new Logowanie();
|
|---|
| 26 |
|
|---|
| 27 | if (logowanie.ShowDialog() == DialogResult.OK)
|
|---|
| 28 | {
|
|---|
| 29 | Application.Run(new MDIBazaReklam());
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | // Creates a class to handle the exception event.
|
|---|
| 35 | internal class CustomExceptionHandler
|
|---|
| 36 | {
|
|---|
| 37 |
|
|---|
| 38 | // Handles the exception event.
|
|---|
| 39 | public void OnThreadException(object sender, ThreadExceptionEventArgs t)
|
|---|
| 40 | {
|
|---|
| 41 | try
|
|---|
| 42 | {
|
|---|
| 43 | ShowThreadExceptionDialog(t.Exception);
|
|---|
| 44 | }
|
|---|
| 45 | catch
|
|---|
| 46 | {
|
|---|
| 47 | try
|
|---|
| 48 | {
|
|---|
| 49 | MessageBox.Show("Fatal Error - aplikacja zostanie zamknięta", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
|
|---|
| 50 | }
|
|---|
| 51 | finally
|
|---|
| 52 | {
|
|---|
| 53 | Application.Exit();
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | // Creates the error message and displays it.
|
|---|
| 59 | private static void ShowThreadExceptionDialog(Exception exception)
|
|---|
| 60 | {
|
|---|
| 61 | string userName = User.Instance().Login;
|
|---|
| 62 | if (string.IsNullOrEmpty(userName)) userName = "[not_found]";
|
|---|
| 63 |
|
|---|
| 64 | Logger.LogException(exception, userName, DateTime.Now);
|
|---|
| 65 | StringBuilder sb = new StringBuilder();
|
|---|
| 66 | sb.AppendLine("Wystąpił nieoczekiwany wyjątek.");
|
|---|
| 67 | sb.AppendLine(string.Empty);
|
|---|
| 68 | sb.AppendLine("Informacje dotyczące tego błędu zostały automatycznie przekazane programiście.");
|
|---|
| 69 | sb.AppendLine(string.Empty);
|
|---|
| 70 | sb.AppendLine("Data i czas: " + DateTime.Now);
|
|---|
| 71 | sb.AppendLine("Użytkownik: " + userName);
|
|---|
| 72 | MessageBox.Show(sb.ToString(), "Błąd w aplikacji Baza Reklam", MessageBoxButtons.OK, MessageBoxIcon.Stop);
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 | } |
|---|