Merge pull request #1500 from criteo-forks/criteo
[mono.git] / mcs / class / System.Web / System.Web.Security / SqliteRoleProvider.cs
1 //
2 // $Id: PgRoleProvider.cs 12 2007-10-17 17:22:43Z dna $
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright © 2006, 2007 Nauck IT KG           http://www.nauck-it.de
24 //
25 // Author:
26 //      Daniel Nauck            <d.nauck(at)nauck-it.de>
27 //
28 // Adapted to Sqlite by Marek Habersack <mhabersack@novell.com>
29 //
30
31 using System;
32 using System.Data;
33 using System.Data.Common;
34 using System.Collections.Generic;
35 using System.Collections.Specialized;
36 using System.Diagnostics;
37 using System.Text;
38 using System.Configuration;
39 using System.Configuration.Provider;
40 using System.Web.Hosting;
41 using System.Web.Security;
42
43 using Mono.Data.Sqlite;
44
45 namespace System.Web.Security
46 {
47         internal class SqliteRoleProvider : RoleProvider
48         {
49                 const string m_RolesTableName = "Roles";
50                 const string m_UserInRolesTableName = "UsersInRoles";
51                 string m_ConnectionString = string.Empty;
52
53                 DbParameter AddParameter (DbCommand command, string parameterName)
54                 {
55                         return AddParameter (command, parameterName, null);
56                 }
57                 
58                 DbParameter AddParameter (DbCommand command, string parameterName, object parameterValue)
59                 {
60                         return AddParameter (command, parameterName, ParameterDirection.Input, parameterValue);
61                 }
62
63                 DbParameter AddParameter (DbCommand command, string parameterName, ParameterDirection direction, object parameterValue)
64                 {
65                         DbParameter dbp = command.CreateParameter ();
66                         dbp.ParameterName = parameterName;
67                         dbp.Value = parameterValue;
68                         dbp.Direction = direction;
69                         command.Parameters.Add (dbp);
70                         return dbp;
71                 }
72                 
73                 /// <summary>
74                 /// System.Configuration.Provider.ProviderBase.Initialize Method
75                 /// </summary>
76                 public override void Initialize(string name, NameValueCollection config)
77                 {
78                         // Initialize values from web.config.
79                         if (config == null)
80                                 throw new ArgumentNullException("Config", Properties.Resources.ErrArgumentNull);
81
82                         if (string.IsNullOrEmpty(name))
83                                 name = Properties.Resources.RoleProviderDefaultName;
84
85                         if (string.IsNullOrEmpty(config["description"]))
86                         {
87                                 config.Remove("description");
88                                 config.Add("description", Properties.Resources.RoleProviderDefaultDescription);
89                         }
90
91                         // Initialize the abstract base class.
92                         base.Initialize(name, config);
93
94                         m_ApplicationName = GetConfigValue(config["applicationName"], HostingEnvironment.ApplicationVirtualPath);
95
96                         // Get connection string.
97                         string connStrName = config["connectionStringName"];
98
99                         if (string.IsNullOrEmpty(connStrName))
100                         {
101                                 throw new ArgumentOutOfRangeException("ConnectionStringName", Properties.Resources.ErrArgumentNullOrEmpty);
102                         }
103                         else
104                         {
105                                 ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[connStrName];
106
107                                 if (ConnectionStringSettings == null || string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
108                                 {
109                                         throw new ProviderException(Properties.Resources.ErrConnectionStringNullOrEmpty);
110                                 }
111
112                                 m_ConnectionString = ConnectionStringSettings.ConnectionString;
113                         }
114                 }
115
116                 /// <summary>
117                 /// System.Web.Security.RoleProvider properties.
118                 /// </summary>
119                 #region System.Web.Security.RoleProvider properties
120                 string m_ApplicationName = string.Empty;
121
122                 public override string ApplicationName
123                 {
124                         get { return m_ApplicationName; }
125                         set { m_ApplicationName = value; }
126                 }
127                 #endregion
128
129                 /// <summary>
130                 /// System.Web.Security.RoleProvider methods.
131                 /// </summary>
132                 #region System.Web.Security.RoleProvider methods
133
134                 /// <summary>
135                 /// RoleProvider.AddUsersToRoles
136                 /// </summary>
137                 public override void AddUsersToRoles(string[] userNames, string[] roleNames)
138                 {
139                         foreach (string rolename in roleNames)
140                         {
141                                 if (!RoleExists(rolename))
142                                 {
143                                         throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, rolename));
144                                 }
145                         }
146
147                         foreach (string username in userNames)
148                         {
149                                 foreach (string rolename in roleNames)
150                                 {
151                                         if (IsUserInRole(username, rolename))
152                                         {
153                                                 throw new ProviderException(string.Format(Properties.Resources.ErrUserAlreadyInRole, username, rolename));
154                                         }
155                                 }
156                         }
157
158                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
159                         {
160                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
161                                 {
162                                         dbCommand.CommandText = string.Format("INSERT INTO \"{0}\" (\"Username\", \"Rolename\", \"ApplicationName\") Values (@Username, @Rolename, @ApplicationName)", m_UserInRolesTableName);
163
164                                         AddParameter (dbCommand, "@Username");
165                                         AddParameter (dbCommand, "@Rolename");
166                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
167
168                                         SqliteTransaction dbTrans = null;
169
170                                         try
171                                         {
172                                                 dbConn.Open();
173                                                 dbCommand.Prepare();
174
175                                                 using (dbTrans = dbConn.BeginTransaction())
176                                                 {
177                                                         foreach (string username in userNames)
178                                                         {
179                                                                 foreach (string rolename in roleNames)
180                                                                 {
181                                                                         dbCommand.Parameters["@Username"].Value = username;
182                                                                         dbCommand.Parameters["@Rolename"].Value = rolename;
183                                                                         dbCommand.ExecuteNonQuery();
184                                                                 }
185                                                         }
186                                                         // Attempt to commit the transaction
187                                                         dbTrans.Commit();
188                                                 }
189                                         }
190                                         catch (SqliteException e)
191                                         {
192                                                 Trace.WriteLine(e.ToString());
193
194                                                 try
195                                                 {
196                                                         // Attempt to roll back the transaction
197                                                         Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
198                                                         dbTrans.Rollback();
199                                                 }
200                                                 catch (SqliteException re)
201                                                 {
202                                                         // Rollback failed
203                                                         Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
204                                                         Trace.WriteLine(re.ToString());
205                                                 }
206
207                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
208                                         }
209                                         finally
210                                         {
211                                                 if (dbConn != null)
212                                                         dbConn.Close();
213                                         }
214                                 }
215                         }
216                 }
217
218                 /// <summary>
219                 /// RoleProvider.CreateRole
220                 /// </summary>
221                 public override void CreateRole(string roleName)
222                 {
223                         if (RoleExists(roleName))
224                         {
225                                 throw new ProviderException(string.Format(Properties.Resources.ErrRoleAlreadyExist, roleName));
226                         }
227
228                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
229                         {
230                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
231                                 {
232                                         dbCommand.CommandText = string.Format("INSERT INTO \"{0}\" (\"Rolename\", \"ApplicationName\") Values (@Rolename, @ApplicationName)", m_RolesTableName);
233
234                                         AddParameter (dbCommand, "@Rolename", roleName);
235                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
236
237                                         try
238                                         {
239                                                 dbConn.Open();
240                                                 dbCommand.Prepare();
241
242                                                 dbCommand.ExecuteNonQuery();
243                                         }
244                                         catch (SqliteException e)
245                                         {
246                                                 Trace.WriteLine(e.ToString());
247                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
248                                         }
249                                         finally
250                                         {
251                                                 if (dbConn != null)
252                                                         dbConn.Close();
253                                         }
254                                 }
255                         }
256                 }
257
258                 /// <summary>
259                 /// RoleProvider.DeleteRole
260                 /// </summary>
261                 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
262                 {
263                         if (!RoleExists(roleName))
264                         {
265                                 throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, roleName));
266                         }
267
268                         if (throwOnPopulatedRole && GetUsersInRole(roleName).Length > 0)
269                         {
270                                 throw new ProviderException(Properties.Resources.ErrCantDeletePopulatedRole);
271                         }
272
273                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
274                         {
275                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
276                                 {
277                                         dbCommand.CommandText = string.Format("DELETE FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_RolesTableName);
278
279                                         AddParameter (dbCommand, "@Rolename", roleName);
280                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
281
282                                         SqliteTransaction dbTrans = null;
283
284                                         try
285                                         {
286                                                 dbConn.Open();
287                                                 dbCommand.Prepare();
288
289                                                 using (dbTrans = dbConn.BeginTransaction())
290                                                 {
291                                                         dbCommand.ExecuteNonQuery();
292
293                                                         // Attempt to commit the transaction
294                                                         dbTrans.Commit();
295                                                 }
296                                         }
297                                         catch (SqliteException e)
298                                         {
299                                                 Trace.WriteLine(e.ToString());
300
301                                                 try
302                                                 {
303                                                         // Attempt to roll back the transaction
304                                                         Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
305                                                         dbTrans.Rollback();
306                                                 }
307                                                 catch (SqliteException re)
308                                                 {
309                                                         // Rollback failed
310                                                         Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
311                                                         Trace.WriteLine(re.ToString());
312                                                 }
313
314                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
315                                         }
316                                         finally
317                                         {
318                                                 if (dbConn != null)
319                                                         dbConn.Close();
320                                         }
321                                 }
322                         }
323
324                         return true;
325                 }
326
327                 /// <summary>
328                 /// RoleProvider.FindUsersInRole
329                 /// </summary>
330                 public override string[] FindUsersInRole(string roleName, string usernameToMatch)
331                 {
332                         List<string> userList = new List<string>();
333
334                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
335                         {
336                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
337                                 {
338                                         dbCommand.CommandText = string.Format("SELECT \"Username\" FROM \"{0}\" WHERE \"Username\" LIKE @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName ORDER BY \"Username\" ASC", m_UserInRolesTableName);
339
340                                         AddParameter (dbCommand, "@Username", usernameToMatch);
341                                         AddParameter (dbCommand, "@Rolename", roleName);
342                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
343
344                                         try
345                                         {
346                                                 dbConn.Open();
347                                                 dbCommand.Prepare();
348
349                                                 using (SqliteDataReader reader = dbCommand.ExecuteReader())
350                                                 {
351                                                         if (reader.HasRows)
352                                                         {
353                                                                 while (reader.Read())
354                                                                 {
355                                                                         userList.Add(reader.GetString(0));
356                                                                 }
357                                                         }
358                                                 }
359                                         }
360                                         catch (SqliteException e)
361                                         {
362                                                 Trace.WriteLine(e.ToString());
363                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
364                                         }
365                                         finally
366                                         {
367                                                 if (dbConn != null)
368                                                         dbConn.Close();
369                                         }
370                                 }
371                         }
372
373                         return userList.ToArray();
374                 }
375
376                 /// <summary>
377                 /// RoleProvider.GetAllRoles
378                 /// </summary>
379                 public override string[] GetAllRoles()
380                 {
381                         List<string> rolesList = new List<string>();
382
383                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
384                         {
385                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
386                                 {
387                                         dbCommand.CommandText = string.Format("SELECT \"Rolename\" FROM \"{0}\" WHERE \"ApplicationName\" = @ApplicationName ORDER BY \"Rolename\" ASC", m_RolesTableName);
388
389                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
390
391                                         try
392                                         {
393                                                 dbConn.Open();
394                                                 dbCommand.Prepare();
395
396                                                 using (SqliteDataReader reader = dbCommand.ExecuteReader())
397                                                 {
398                                                         while (reader.Read())
399                                                         {
400                                                                 rolesList.Add(reader.GetString(0));
401                                                         }
402                                                 }                                               
403                                         }
404                                         catch (SqliteException e)
405                                         {
406                                                 Trace.WriteLine(e.ToString());
407                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
408                                         }
409                                         finally
410                                         {
411                                                 if (dbConn != null)
412                                                         dbConn.Close();
413                                         }
414                                 }
415                         }
416
417                         return rolesList.ToArray();
418                 }
419
420                 /// <summary>
421                 /// RoleProvider.GetRolesForUser
422                 /// </summary>
423                 public override string[] GetRolesForUser(string username)
424                 {
425                         List<string> rolesList = new List<string>();
426
427                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
428                         {
429                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
430                                 {
431                                         dbCommand.CommandText = string.Format("SELECT \"Rolename\" FROM \"{0}\" WHERE \"Username\" = @Username AND \"ApplicationName\" = @ApplicationName ORDER BY \"Rolename\" ASC", m_UserInRolesTableName);
432
433                                         AddParameter (dbCommand, "@Username", username);
434                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
435
436                                         try
437                                         {
438                                                 dbConn.Open();
439                                                 dbCommand.Prepare();
440
441                                                 using (SqliteDataReader reader = dbCommand.ExecuteReader())
442                                                 {
443                                                         if (reader.HasRows)
444                                                         {
445                                                                 while (reader.Read())
446                                                                 {
447                                                                         rolesList.Add(reader.GetString(0));
448                                                                 }
449                                                         }
450                                                 }
451                                         }
452                                         catch (SqliteException e)
453                                         {
454                                                 Trace.WriteLine(e.ToString());
455                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
456                                         }
457                                         finally
458                                         {
459                                                 if (dbConn != null)
460                                                         dbConn.Close();
461                                         }
462                                 }
463                         }
464
465                         return rolesList.ToArray();
466                 }
467
468                 /// <summary>
469                 /// RoleProvider.GetUsersInRole
470                 /// </summary>
471                 public override string[] GetUsersInRole(string roleName)
472                 {
473                         List<string> userList = new List<string>();
474
475                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
476                         {
477                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
478                                 {
479                                         dbCommand.CommandText = string.Format("SELECT \"Username\" FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName ORDER BY \"Username\" ASC", m_UserInRolesTableName);
480
481                                         AddParameter (dbCommand, "@Rolename", roleName);
482                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
483
484                                         try
485                                         {
486                                                 dbConn.Open();
487                                                 dbCommand.Prepare();
488
489                                                 using (SqliteDataReader reader = dbCommand.ExecuteReader())
490                                                 {
491                                                         if (reader.HasRows)
492                                                         {
493                                                                 while (reader.Read())
494                                                                 {
495                                                                         userList.Add(reader.GetString(0));
496                                                                 }
497                                                         }
498                                                 }
499                                         }
500                                         catch (SqliteException e)
501                                         {
502                                                 Trace.WriteLine(e.ToString());
503                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
504                                         }
505                                         finally
506                                         {
507                                                 if (dbConn != null)
508                                                         dbConn.Close();
509                                         }
510                                 }
511                         }
512
513                         return userList.ToArray();
514                 }
515
516                 /// <summary>
517                 /// RoleProvider.IsUserInRole
518                 /// </summary>
519                 public override bool IsUserInRole(string userName, string roleName)
520                 {
521                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
522                         {
523                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
524                                 {
525                                         dbCommand.CommandText = string.Format("SELECT COUNT(*) FROM \"{0}\" WHERE \"Username\" = @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_UserInRolesTableName);
526
527                                         AddParameter (dbCommand, "@Username", userName);
528                                         AddParameter (dbCommand, "@Rolename", roleName);
529                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
530
531                                         try
532                                         {
533                                                 dbConn.Open();
534                                                 dbCommand.Prepare();
535
536                                                 int numRecs = 0;
537                                                 Int32.TryParse(dbCommand.ExecuteScalar().ToString(), out numRecs);
538
539                                                 if (numRecs > 0)
540                                                         return true;
541                                         }
542                                         catch (SqliteException e)
543                                         {
544                                                 Trace.WriteLine(e.ToString());
545                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
546                                         }
547                                         finally
548                                         {
549                                                 if (dbConn != null)
550                                                         dbConn.Close();
551                                         }
552                                 }
553                         }
554
555                         return false;
556                 }
557
558                 /// <summary>
559                 /// RoleProvider.RemoveUsersFromRoles
560                 /// </summary>
561                 public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
562                 {
563                         foreach (string rolename in roleNames)
564                         {
565                                 if (!RoleExists(rolename))
566                                 {
567                                         throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, rolename));
568                                 }
569                         }
570
571                         foreach (string username in userNames)
572                         {
573                                 foreach (string rolename in roleNames)
574                                 {
575                                         if (!IsUserInRole(username, rolename))
576                                         {
577                                                 throw new ProviderException(string.Format(Properties.Resources.ErrUserIsNotInRole, username, rolename));
578                                         }
579                                 }
580                         }
581
582                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
583                         {
584                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
585                                 {
586                                         dbCommand.CommandText = string.Format("DELETE FROM \"{0}\" WHERE \"Username\" = @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_UserInRolesTableName);
587
588                                         AddParameter (dbCommand, "@Username");
589                                         AddParameter (dbCommand, "@Rolename");
590                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
591
592                                         SqliteTransaction dbTrans = null;
593
594                                         try
595                                         {
596                                                 dbConn.Open();
597                                                 dbCommand.Prepare();
598
599                                                 using (dbTrans = dbConn.BeginTransaction())
600                                                 {
601                                                         foreach (string username in userNames)
602                                                         {
603                                                                 foreach (string rolename in roleNames)
604                                                                 {
605                                                                         dbCommand.Parameters["@Username"].Value = username;
606                                                                         dbCommand.Parameters["@Rolename"].Value = rolename;
607                                                                         dbCommand.ExecuteNonQuery();
608                                                                 }
609                                                         }
610                                                         // Attempt to commit the transaction
611                                                         dbTrans.Commit();
612                                                 }
613                                         }
614                                         catch (SqliteException e)
615                                         {
616                                                 Trace.WriteLine(e.ToString());
617
618                                                 try
619                                                 {
620                                                         // Attempt to roll back the transaction
621                                                         Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
622                                                         dbTrans.Rollback();
623                                                 }
624                                                 catch (SqliteException re)
625                                                 {
626                                                         // Rollback failed
627                                                         Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
628                                                         Trace.WriteLine(re.ToString());
629                                                 }
630
631                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
632                                         }
633                                         finally
634                                         {
635                                                 if (dbConn != null)
636                                                         dbConn.Close();
637                                         }
638                                 }
639                         }
640                 }
641
642                 /// <summary>
643                 /// RoleProvider.RoleExists
644                 /// </summary>
645                 public override bool RoleExists(string roleName)
646                 {
647                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
648                         {
649                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
650                                 {
651                                         dbCommand.CommandText = string.Format("SELECT COUNT(*) FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_RolesTableName);
652
653                                         AddParameter (dbCommand, "@Rolename", roleName);
654                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
655
656                                         try
657                                         {
658                                                 dbConn.Open();
659                                                 dbCommand.Prepare();
660
661                                                 int numRecs = 0;
662                                                 Int32.TryParse(dbCommand.ExecuteScalar().ToString(), out numRecs);
663
664                                                 if (numRecs > 0)
665                                                         return true;
666                                         }
667                                         catch (SqliteException e)
668                                         {
669                                                 Trace.WriteLine(e.ToString());
670                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
671                                         }
672                                         finally
673                                         {
674                                                 if (dbConn != null)
675                                                         dbConn.Close();
676                                         }
677                                 }
678                         }
679
680                         return false;
681                 }
682                 #endregion
683
684                 #region private methods
685                 /// <summary>
686                 /// A helper function to retrieve config values from the configuration file.
687                 /// </summary>
688                 /// <param name="configValue"></param>
689                 /// <param name="defaultValue"></param>
690                 /// <returns></returns>
691                 string GetConfigValue(string configValue, string defaultValue)
692                 {
693                         if (string.IsNullOrEmpty(configValue))
694                                 return defaultValue;
695
696                         return configValue;
697                 }
698                 #endregion      
699         }
700 }