10
10
11
11
[ assembly: log4net . Config . XmlConfigurator ( Watch = true ) ]
12
12
13
- // <summary>
14
- // This namespaces if for generic application classes
15
- // </summary>
16
13
namespace Markup . Scripts
17
14
{
18
- /// <summary>
19
- /// Used to handle exceptions
20
- /// </summary>
21
15
public class ErrorHandler
22
16
{
23
17
private static readonly ILog log = LogManager . GetLogger ( typeof ( ErrorHandler ) ) ;
24
18
25
- /// <summary>
26
- /// Applies a new path for the log file by FileAppender name
27
- /// </summary>
28
19
public static void SetLogPath ( )
29
20
{
30
21
XmlConfigurator . Configure ( ) ;
@@ -44,9 +35,6 @@ public static void SetLogPath()
44
35
}
45
36
}
46
37
47
- /// <summary>
48
- /// Create a log record to track which methods are being used.
49
- /// </summary>
50
38
public static void CreateLogRecord ( )
51
39
{
52
40
try
@@ -73,27 +61,14 @@ public static void CreateLogRecord()
73
61
}
74
62
}
75
63
76
- /// <summary>
77
- /// Used to produce an error message and create a log record
78
- /// <example>
79
- /// <code lang="C#">
80
- /// ErrorHandler.DisplayMessage(ex);
81
- /// </code>
82
- /// </example>
83
- /// </summary>
84
- /// <param name="ex">Represents errors that occur during application execution.</param>
85
- /// <param name="isSilent">Used to show a message to the user and log an error record or just log a record.</param>
86
- /// <remarks></remarks>
87
64
public static void DisplayMessage ( Exception ex , Boolean isSilent = false )
88
65
{
89
- // gather context
90
66
var sf = new System . Diagnostics . StackFrame ( 1 ) ;
91
67
var caller = sf . GetMethod ( ) ;
92
- var errorDescription = ex . ToString ( ) . Replace ( "\r \n " , " " ) ; // the carriage returns were messing up my log file
68
+ var errorDescription = ex . ToString ( ) . Replace ( "\r \n " , " " ) ;
93
69
var currentProcedure = caller . Name . Trim ( ) ;
94
70
var currentFileName = AssemblyInfo . GetCurrentFileName ( ) ;
95
71
96
- // handle log record
97
72
var logMessage = string . Concat ( new Dictionary < string , string >
98
73
{
99
74
[ "PROCEDURE" ] = currentProcedure ,
@@ -104,26 +79,18 @@ public static void DisplayMessage(Exception ex, Boolean isSilent = false)
104
79
} . Select ( x => $ "[{ x . Key } ]=|{ x . Value } |") ) ;
105
80
log . Error ( logMessage ) ;
106
81
107
- // format message
108
82
var userMessage = new StringBuilder ( )
109
83
. AppendLine ( "Contact your system administrator. A record has been created in the log file." )
110
84
. AppendLine ( "Procedure: " + currentProcedure )
111
85
. AppendLine ( "Description: " + errorDescription )
112
86
. ToString ( ) ;
113
87
114
- // handle message
115
88
if ( isSilent == false )
116
89
{
117
90
MessageBox . Show ( userMessage , "Unexpected Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
118
91
}
119
92
}
120
93
121
- /// <summary>
122
- /// Check to see if there is an active document
123
- /// </summary>
124
- /// <param name="showMsg">To show a message </param>
125
- /// <returns>A method that returns true or false if there is an active document </returns>
126
- /// <remarks></remarks>
127
94
public static bool IsActiveDocument ( bool showMsg = false )
128
95
{
129
96
try
@@ -148,12 +115,6 @@ public static bool IsActiveDocument(bool showMsg = false)
148
115
}
149
116
}
150
117
151
- /// <summary>
152
- /// Check to see if there is an active selection
153
- /// </summary>
154
- /// <param name="showMsg">To show a message </param>
155
- /// <returns>A method that returns true or false if there is an active selection </returns>
156
- /// <remarks></remarks>
157
118
public static bool IsActiveSelection ( bool showMsg = false )
158
119
{
159
120
Excel . Range checkRange = null ;
@@ -185,13 +146,6 @@ public static bool IsActiveSelection(bool showMsg = false)
185
146
}
186
147
}
187
148
188
- /// <summary>
189
- /// This method check whether Excel is in Cell Editing mode or not
190
- /// There are few ways to check this (eg. check to see if a standard menu item is disabled etc.)
191
- /// I know in cell editing mode app.DisplayAlerts throws an Exception, so here I'm relying on that behaviour
192
- /// </summary>
193
- /// <param name="showMsg">To show a message </param>
194
- /// <returns>true if Excel is in cell editing mode</returns>
195
149
private static bool IsInCellEditingMode ( bool showMsg = false )
196
150
{
197
151
bool flag = false ;
@@ -210,12 +164,6 @@ private static bool IsInCellEditingMode(bool showMsg = false)
210
164
return flag ;
211
165
}
212
166
213
- /// <summary>
214
- /// Can an object be inserted
215
- /// </summary>
216
- /// <param name="showMsg">To show a message </param>
217
- /// <returns>A method that returns true or false if an object can be enabled </returns>
218
- /// <remarks></remarks>
219
167
public static bool IsEnabled ( bool showMsg = false )
220
168
{
221
169
try
0 commit comments