22using System ;
33using System . Collections . Generic ;
44using System . Data ;
5+ using System . Diagnostics ;
56using System . Text ;
67using System . Threading . Tasks ;
78
@@ -28,28 +29,39 @@ public abstract class TestRunner<T>
2829 /// <param name="connectAs">Connect as</param>
2930 public void Connect ( string username , string password , string database , string connectAs = null )
3031 {
31- string connectionString ;
32- if ( string . IsNullOrEmpty ( connectAs ) )
32+ try
3333 {
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+ }
4043
41- foreach ( var command in runningCommands )
42- {
43- command . Cancel ( ) ;
44- }
44+ foreach ( var command in runningCommands )
45+ {
46+ command . Cancel ( ) ;
47+ }
4548
46- produceConnection = new OracleConnection ( connectionString ) ;
47- produceConnection . Open ( ) ;
49+ produceConnection = new OracleConnection ( connectionString ) ;
50+ produceConnection . Open ( ) ;
4851
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+ }
5163 }
52-
64+
5365 /// <summary>
5466 /// Closes both connections
5567 /// </summary>
@@ -62,11 +74,17 @@ public void Close()
6274
6375 if ( produceConnection != null )
6476 {
65- try {
66- produceConnection . Close ( ) ;
77+ try
78+ {
79+ produceConnection . Close ( ) ;
6780 }
68- catch
81+ catch ( Exception e )
6982 {
83+ using ( EventLog eventLog = new EventLog ( "Application" ) )
84+ {
85+ eventLog . Source = "Application" ;
86+ eventLog . WriteEntry ( $ "{ e . Message } \r \n { e . StackTrace } ", EventLogEntryType . Error ) ;
87+ }
7088 }
7189 }
7290 if ( consumeConnection != null )
@@ -75,8 +93,13 @@ public void Close()
7593 {
7694 consumeConnection . Close ( ) ;
7795 }
78- catch
96+ catch ( Exception e )
7997 {
98+ using ( EventLog eventLog = new EventLog ( "Application" ) )
99+ {
100+ eventLog . Source = "Application" ;
101+ eventLog . WriteEntry ( $ "{ e . Message } \r \n { e . StackTrace } ", EventLogEntryType . Error ) ;
102+ }
80103 }
81104 }
82105 }
@@ -87,20 +110,31 @@ public void Close()
87110 /// <returns>Version as string</returns>
88111 public string GetVersion ( )
89112 {
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 ) ;
92117
93- var reader = cmd . ExecuteReader ( ) ;
94- reader . Read ( ) ;
118+ var reader = cmd . ExecuteReader ( ) ;
119+ reader . Read ( ) ;
95120
96- var version = reader . GetString ( 0 ) ;
121+ var version = reader . GetString ( 0 ) ;
97122
98- reader . Close ( ) ;
123+ reader . Close ( ) ;
99124
100- runningCommands . Remove ( cmd ) ;
101- cmd . Dispose ( ) ;
125+ runningCommands . Remove ( cmd ) ;
126+ cmd . Dispose ( ) ;
102127
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+ }
104138 }
105139
106140 /// <summary>
@@ -141,38 +175,49 @@ public string GetVersion()
141175
142176 protected string GetCoverageReport ( string id )
143177 {
144- var sb = new StringBuilder ( ) ;
178+ try
179+ {
180+ var sb = new StringBuilder ( ) ;
145181
146- var proc = @"DECLARE
182+ var proc = @"DECLARE
147183 l_reporter ut_coverage_html_reporter := ut_coverage_html_reporter();
148184 BEGIN
149185 l_reporter.set_reporter_id(:id);
150186 :lines_cursor := l_reporter.get_lines_cursor();
151187 END;" ;
152188
153- var cmd = new OracleCommand ( proc , consumeConnection ) ;
154- runningCommands . Add ( cmd ) ;
189+ var cmd = new OracleCommand ( proc , consumeConnection ) ;
190+ runningCommands . Add ( cmd ) ;
155191
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 ) ;
158194
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 ;
161197
162- var reader = cmd . ExecuteReader ( ) ;
198+ var reader = cmd . ExecuteReader ( ) ;
163199
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+ }
169205
170- reader . Close ( ) ;
206+ reader . Close ( ) ;
171207
172- runningCommands . Remove ( cmd ) ;
173- cmd . Dispose ( ) ;
208+ runningCommands . Remove ( cmd ) ;
209+ cmd . Dispose ( ) ;
174210
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+ }
176221 }
177222
178223 protected string ConvertToUtVarchar2List ( List < string > elements )
0 commit comments