System.Data.SQLite
Check-in [5f0d62ce57]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Move the XML configuration file reading code into its own private method.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5f0d62ce57e7bb495867fff9bb20d805d4fdc42b
User & Date: mistachkin 2016-07-02 00:30:39
Context
2016-07-02
03:10
Remove superfluous comment. check-in: 7273ee5d1f user: mistachkin tags: trunk
00:30
Move the XML configuration file reading code into its own private method. check-in: 5f0d62ce57 user: mistachkin tags: trunk
00:06
Improve comments. check-in: 4b9b00163e user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/UnsafeNativeMethods.cs.

   761    761             fileName = MaybeCombinePath(directory, XmlConfigFileName);
   762    762   
   763    763             if (File.Exists(fileName))
   764    764                 return fileName;
   765    765   
   766    766             return null;
   767    767         }
          768  +
          769  +      /////////////////////////////////////////////////////////////////////////
          770  +
          771  +      /// <summary>
          772  +      /// Queries and returns the value of the specified setting, using the
          773  +      /// specified XML configuration file.
          774  +      /// </summary>
          775  +      /// <param name="fileName">
          776  +      /// The name of the XML configuration file to read.
          777  +      /// </param>
          778  +      /// <param name="name">
          779  +      /// The name of the setting.
          780  +      /// </param>
          781  +      /// <param name="default">
          782  +      /// The value to be returned if the setting has not been set explicitly
          783  +      /// or cannot be determined.
          784  +      /// </param>
          785  +      /// <param name="expand">
          786  +      /// Non-zero to expand any environment variable references contained in
          787  +      /// the setting value to be returned.  This has no effect on the .NET
          788  +      /// Compact Framework.
          789  +      /// </param>
          790  +      /// <returns>
          791  +      /// The value of the setting -OR- the default value specified by
          792  +      /// <paramref name="default" /> if it has not been set explicitly or
          793  +      /// cannot be determined.  By default, all references to existing
          794  +      /// environment variables will be expanded to their corresponding values
          795  +      /// within the value to be returned unless either the "No_Expand" or
          796  +      /// "No_Expand_<paramref name="name" />" environment variable is set [to
          797  +      /// anything].
          798  +      /// </returns>
          799  +      private static string GetSettingValueViaXmlConfigFile(
          800  +          string fileName, /* in */
          801  +          string name,     /* in */
          802  +          string @default, /* in */
          803  +          bool expand      /* in */
          804  +          )
          805  +      {
          806  +          try
          807  +          {
          808  +              if ((fileName == null) || (name == null))
          809  +                  return @default;
          810  +
          811  +              XmlDocument document = new XmlDocument();
          812  +
          813  +              document.Load(fileName); /* throw */
          814  +
          815  +              XmlElement element = document.SelectSingleNode(
          816  +                  HelperMethods.StringFormat(CultureInfo.InvariantCulture,
          817  +                  "/configuration/appSettings/add[@key='{0}']", name)) as
          818  +                  XmlElement; /* throw */
          819  +
          820  +              if (element != null)
          821  +              {
          822  +                  string value = null;
          823  +
          824  +                  if (element.HasAttribute("value"))
          825  +                      value = element.GetAttribute("value");
          826  +
          827  +#if !PLATFORM_COMPACTFRAMEWORK
          828  +                  if (expand && !String.IsNullOrEmpty(value))
          829  +                      value = Environment.ExpandEnvironmentVariables(value);
          830  +#endif
          831  +
          832  +                  if (value != null)
          833  +                      return value;
          834  +              }
          835  +          }
          836  +#if !NET_COMPACT_20 && TRACE_SHARED
          837  +          catch (Exception e)
          838  +#else
          839  +          catch (Exception)
          840  +#endif
          841  +          {
          842  +#if !NET_COMPACT_20 && TRACE_SHARED
          843  +              try
          844  +              {
          845  +                  Trace.WriteLine(HelperMethods.StringFormat(
          846  +                      CultureInfo.CurrentCulture, "Native library " +
          847  +                      "pre-loader failed to get setting \"{0}\" value " +
          848  +                      "from XML configuration file \"{1}\": {2}", name,
          849  +                      fileName, e)); /* throw */
          850  +              }
          851  +              catch
          852  +              {
          853  +                  // do nothing.
          854  +              }
          855  +#endif
          856  +          }
          857  +
          858  +          return @default;
          859  +      }
   768    860   
   769    861         /////////////////////////////////////////////////////////////////////////
   770    862         /// <summary>
   771    863         /// Queries and returns the value of the specified setting, using the XML
   772    864         /// configuration file and/or the environment variables for the current
   773    865         /// process and/or the current system, when available.
   774    866         /// </summary>
................................................................................
   811    903             if (name == null)
   812    904                 return @default;
   813    905   
   814    906             /////////////////////////////////////////////////////////////////////
   815    907   
   816    908             #region Debug Build Only
   817    909   #if DEBUG
          910  +          //
          911  +          // NOTE: We are about to read a setting value from the environment
          912  +          //       or possibly from the XML configuration file; create or
          913  +          //       increment the appropriate statistic now.
          914  +          //
   818    915             DebugData.IncrementSettingReadCount(name, false);
   819    916   #endif
   820    917             #endregion
   821    918   
   822    919             /////////////////////////////////////////////////////////////////////
   823    920   
   824         -          string value = null;
          921  +          bool expand = true; /* SHARED: Environment -AND- XML config file. */
          922  +
          923  +          /////////////////////////////////////////////////////////////////////
   825    924   
   826    925   #if !PLATFORM_COMPACTFRAMEWORK
   827         -          bool expand = true;
          926  +          string value = null;
   828    927   
   829    928             if (Environment.GetEnvironmentVariable("No_Expand") != null)
   830    929             {
   831    930                 expand = false;
   832    931             }
   833    932             else if (Environment.GetEnvironmentVariable(
   834    933                     HelperMethods.StringFormat(CultureInfo.InvariantCulture,
................................................................................
   857    956             }
   858    957   #endif
   859    958   
   860    959             /////////////////////////////////////////////////////////////////////
   861    960   
   862    961             #region Debug Build Only
   863    962   #if DEBUG
          963  +          //
          964  +          // NOTE: We are about to read a setting value from the XML
          965  +          //       configuration file; create or increment the appropriate
          966  +          //       statistic now.
          967  +          //
   864    968             DebugData.IncrementSettingReadCount(name, true);
   865    969   #endif
   866    970             #endregion
   867    971   
   868    972             /////////////////////////////////////////////////////////////////////
   869    973   
   870         -          try
   871         -          {
   872         -              string fileName = GetXmlConfigFileName();
   873         -
   874         -              if (fileName == null)
   875         -                  return @default;
   876         -
   877         -              XmlDocument document = new XmlDocument();
   878         -
   879         -              document.Load(fileName);
   880         -
   881         -              XmlElement element = document.SelectSingleNode(
   882         -                  HelperMethods.StringFormat(CultureInfo.InvariantCulture,
   883         -                  "/configuration/appSettings/add[@key='{0}']", name)) as
   884         -                  XmlElement;
   885         -
   886         -              if (element != null)
   887         -              {
   888         -                  if (element.HasAttribute("value"))
   889         -                      value = element.GetAttribute("value");
   890         -
   891         -#if !PLATFORM_COMPACTFRAMEWORK
   892         -                  if (expand && !String.IsNullOrEmpty(value))
   893         -                      value = Environment.ExpandEnvironmentVariables(value);
   894         -#endif
   895         -
   896         -                  if (value != null)
   897         -                      return value;
   898         -              }
   899         -          }
   900         -#if !NET_COMPACT_20 && TRACE_SHARED
   901         -          catch (Exception e)
   902         -#else
   903         -          catch (Exception)
   904         -#endif
   905         -          {
   906         -#if !NET_COMPACT_20 && TRACE_SHARED
   907         -              try
   908         -              {
   909         -                  Trace.WriteLine(HelperMethods.StringFormat(
   910         -                      CultureInfo.CurrentCulture,
   911         -                      "Native library pre-loader failed to get setting " +
   912         -                      "\"{0}\" value: {1}", name, e)); /* throw */
   913         -              }
   914         -              catch
   915         -              {
   916         -                  // do nothing.
   917         -              }
   918         -#endif
   919         -          }
   920         -
   921         -          return @default;
          974  +          return GetSettingValueViaXmlConfigFile(
          975  +              GetXmlConfigFileName(), name, @default, expand);
   922    976         }
   923    977   
   924    978         /////////////////////////////////////////////////////////////////////////
   925    979   
   926    980   #if !PLATFORM_COMPACTFRAMEWORK
   927    981         private static string ListToString(IList<string> list)
   928    982         {