forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorManager.cs
More file actions
99 lines (91 loc) · 3.43 KB
/
Copy pathErrorManager.cs
File metadata and controls
99 lines (91 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic;
using PluginCore.Localization;
using PluginCore.Controls;
using PluginCore.Helpers;
using System.Text;
namespace PluginCore.Managers
{
public class ErrorManager
{
/// <summary>
/// Enables/disables the log file output
/// </summary>
public static Boolean OutputIsEnabled = true;
/// <summary>
/// Shows a visible info message to the user
/// </summary>
public static void ShowInfo(String info)
{
if ((PluginBase.MainForm as Form).InvokeRequired)
{
AddToLog("Unsafe ShowInfo: " + info, null);
return;
}
String title = TextHelper.GetString("FlashDevelop.Title.InfoDialog");
MessageBox.Show(PluginBase.MainForm, info, " " + title, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/// <summary>
/// Shows a visible warning message to the user
/// </summary>
public static void ShowWarning(String info, Exception exception)
{
if ((PluginBase.MainForm as Form).InvokeRequired)
{
AddToLog("Unsafe ShowWarning: " + info, exception);
return;
}
String title = TextHelper.GetString("FlashDevelop.Title.WarningDialog");
MessageBox.Show(PluginBase.MainForm, info, " " + title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
if (OutputIsEnabled && exception != null) AddToLog(info, exception);
}
/// <summary>
/// Shows a simple error dialog to the user
/// </summary>
public static void ShowError(String info, Exception exception)
{
if ((PluginBase.MainForm as Form).InvokeRequired)
{
AddToLog("Unsafe ShowError: " + info, exception);
return;
}
String title = TextHelper.GetString("FlashDevelop.Title.ErrorDialog");
MessageBox.Show(PluginBase.MainForm, info, " " + title, MessageBoxButtons.OK, MessageBoxIcon.Error);
if (OutputIsEnabled) AddToLog(info, exception);
}
/// <summary>
/// Shows a visible error message to the user
/// </summary>
public static void ShowError(Exception exception)
{
if ((PluginBase.MainForm as Form).InvokeRequired)
{
AddToLog("Unsafe ShowError", exception);
return;
}
PluginBase.MainForm.ShowErrorDialog(new ErrorManager(), exception);
if (OutputIsEnabled) AddToLog(null, exception);
}
/// <summary>
/// Adds the message and exception to the error log silently
/// </summary>
public static void AddToLog(String message, Exception exception)
{
String result = String.Empty;
result += DateTime.Now.ToString() + "\r\n\r\n";
if (message != null) result += message.ToString() + "\r\n\r\n";
if (exception != null) result += exception.ToString() + "\r\n\r\n";
try
{
String fileName = Path.Combine(PathHelper.BaseDir, "Exceptions.log");
using (StreamWriter sw = new StreamWriter(fileName, true))
{
sw.Write(result);
}
}
catch {}
}
}
}