2
2
using System ;
3
3
using System . Collections . Generic ;
4
4
using System . Data ;
5
+ using System . Diagnostics ;
5
6
using System . Text ;
6
7
using System . Threading . Tasks ;
7
8
@@ -28,28 +29,39 @@ public abstract class TestRunner<T>
28
29
/// <param name="connectAs">Connect as</param>
29
30
public void Connect ( string username , string password , string database , string connectAs = null )
30
31
{
31
- string connectionString ;
32
- if ( string . IsNullOrEmpty ( connectAs ) )
32
+ try
33
33
{
34
- connectionString = $ "User Id={ username } ;Password={ password } ;Data Source={ database } ";
35
- }
36
- else
37
- {
38
- connectionString = $ "User Id={ username } ;DBA Privilege={ connectAs } ;Password={ password } ;Data Source={ database } ";
39
- }
34
+ string connectionString ;
35
+ if ( string . IsNullOrEmpty ( connectAs ) )
36
+ {
37
+ connectionString = $ "User Id={ username } ;Password={ password } ;Data Source={ database } ";
38
+ }
39
+ else
40
+ {
41
+ connectionString = $ "User Id={ username } ;DBA Privilege={ connectAs } ;Password={ password } ;Data Source={ database } ";
42
+ }
40
43
41
- foreach ( var command in runningCommands )
42
- {
43
- command . Cancel ( ) ;
44
- }
44
+ foreach ( var command in runningCommands )
45
+ {
46
+ command . Cancel ( ) ;
47
+ }
45
48
46
- produceConnection = new OracleConnection ( connectionString ) ;
47
- produceConnection . Open ( ) ;
49
+ produceConnection = new OracleConnection ( connectionString ) ;
50
+ produceConnection . Open ( ) ;
48
51
49
- consumeConnection = new OracleConnection ( connectionString ) ;
50
- consumeConnection . Open ( ) ;
52
+ consumeConnection = new OracleConnection ( connectionString ) ;
53
+ consumeConnection . Open ( ) ;
54
+ }
55
+ catch ( Exception e )
56
+ {
57
+ using ( EventLog eventLog = new EventLog ( "Application" ) )
58
+ {
59
+ eventLog . Source = "Application" ;
60
+ eventLog . WriteEntry ( $ "{ e . Message } \r \n { e . StackTrace } ", EventLogEntryType . Error ) ;
61
+ }
62
+ }
51
63
}
52
-
64
+
53
65
/// <summary>
54
66
/// Closes both connections
55
67
/// </summary>
@@ -62,11 +74,17 @@ public void Close()
62
74
63
75
if ( produceConnection != null )
64
76
{
65
- try {
66
- produceConnection . Close ( ) ;
77
+ try
78
+ {
79
+ produceConnection . Close ( ) ;
67
80
}
68
- catch
81
+ catch ( Exception e )
69
82
{
83
+ using ( EventLog eventLog = new EventLog ( "Application" ) )
84
+ {
85
+ eventLog . Source = "Application" ;
86
+ eventLog . WriteEntry ( $ "{ e . Message } \r \n { e . StackTrace } ", EventLogEntryType . Error ) ;
87
+ }
70
88
}
71
89
}
72
90
if ( consumeConnection != null )
@@ -75,8 +93,13 @@ public void Close()
75
93
{
76
94
consumeConnection . Close ( ) ;
77
95
}
78
- catch
96
+ catch ( Exception e )
79
97
{
98
+ using ( EventLog eventLog = new EventLog ( "Application" ) )
99
+ {
100
+ eventLog . Source = "Application" ;
101
+ eventLog . WriteEntry ( $ "{ e . Message } \r \n { e . StackTrace } ", EventLogEntryType . Error ) ;
102
+ }
80
103
}
81
104
}
82
105
}
@@ -87,20 +110,31 @@ public void Close()
87
110
/// <returns>Version as string</returns>
88
111
public string GetVersion ( )
89
112
{
90
- var cmd = new OracleCommand ( "select ut.version() from dual" , produceConnection ) ;
91
- runningCommands . Add ( cmd ) ;
113
+ try
114
+ {
115
+ var cmd = new OracleCommand ( "select ut.version() from dual" , produceConnection ) ;
116
+ runningCommands . Add ( cmd ) ;
92
117
93
- var reader = cmd . ExecuteReader ( ) ;
94
- reader . Read ( ) ;
118
+ var reader = cmd . ExecuteReader ( ) ;
119
+ reader . Read ( ) ;
95
120
96
- var version = reader . GetString ( 0 ) ;
121
+ var version = reader . GetString ( 0 ) ;
97
122
98
- reader . Close ( ) ;
123
+ reader . Close ( ) ;
99
124
100
- runningCommands . Remove ( cmd ) ;
101
- cmd . Dispose ( ) ;
125
+ runningCommands . Remove ( cmd ) ;
126
+ cmd . Dispose ( ) ;
102
127
103
- return version ;
128
+ return version ;
129
+ }
130
+ catch ( Exception e )
131
+ {
132
+ using ( EventLog eventLog = new EventLog ( "Application" ) )
133
+ {
134
+ eventLog . Source = "Application" ;
135
+ eventLog . WriteEntry ( $ "{ e . Message } \r \n { e . StackTrace } ", EventLogEntryType . Error ) ;
136
+ }
137
+ }
104
138
}
105
139
106
140
/// <summary>
@@ -141,38 +175,49 @@ public string GetVersion()
141
175
142
176
protected string GetCoverageReport ( string id )
143
177
{
144
- var sb = new StringBuilder ( ) ;
178
+ try
179
+ {
180
+ var sb = new StringBuilder ( ) ;
145
181
146
- var proc = @"DECLARE
182
+ var proc = @"DECLARE
147
183
l_reporter ut_coverage_html_reporter := ut_coverage_html_reporter();
148
184
BEGIN
149
185
l_reporter.set_reporter_id(:id);
150
186
:lines_cursor := l_reporter.get_lines_cursor();
151
187
END;" ;
152
188
153
- var cmd = new OracleCommand ( proc , consumeConnection ) ;
154
- runningCommands . Add ( cmd ) ;
189
+ var cmd = new OracleCommand ( proc , consumeConnection ) ;
190
+ runningCommands . Add ( cmd ) ;
155
191
156
- cmd . Parameters . Add ( "id" , OracleDbType . Varchar2 , ParameterDirection . Input ) . Value = id ;
157
- cmd . Parameters . Add ( "lines_cursor" , OracleDbType . RefCursor , ParameterDirection . Output ) ;
192
+ cmd . Parameters . Add ( "id" , OracleDbType . Varchar2 , ParameterDirection . Input ) . Value = id ;
193
+ cmd . Parameters . Add ( "lines_cursor" , OracleDbType . RefCursor , ParameterDirection . Output ) ;
158
194
159
- // https://stackoverflow.com/questions/2226769/bad-performance-with-oracledatareader
160
- cmd . InitialLOBFetchSize = - 1 ;
195
+ // https://stackoverflow.com/questions/2226769/bad-performance-with-oracledatareader
196
+ cmd . InitialLOBFetchSize = - 1 ;
161
197
162
- var reader = cmd . ExecuteReader ( ) ;
198
+ var reader = cmd . ExecuteReader ( ) ;
163
199
164
- while ( reader . Read ( ) )
165
- {
166
- var line = reader . GetString ( 0 ) ;
167
- sb . Append ( line ) ;
168
- }
200
+ while ( reader . Read ( ) )
201
+ {
202
+ var line = reader . GetString ( 0 ) ;
203
+ sb . Append ( line ) ;
204
+ }
169
205
170
- reader . Close ( ) ;
206
+ reader . Close ( ) ;
171
207
172
- runningCommands . Remove ( cmd ) ;
173
- cmd . Dispose ( ) ;
208
+ runningCommands . Remove ( cmd ) ;
209
+ cmd . Dispose ( ) ;
174
210
175
- return sb . ToString ( ) ;
211
+ return sb . ToString ( ) ;
212
+ }
213
+ catch ( Exception e )
214
+ {
215
+ using ( EventLog eventLog = new EventLog ( "Application" ) )
216
+ {
217
+ eventLog . Source = "Application" ;
218
+ eventLog . WriteEntry ( $ "{ e . Message } \r \n { e . StackTrace } ", EventLogEntryType . Error ) ;
219
+ }
220
+ }
176
221
}
177
222
178
223
protected string ConvertToUtVarchar2List ( List < string > elements )
0 commit comments