You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 rivejä
1.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Quanjiang.DigitalScholl.PushNotifications
  8. {
  9. internal static class ConfigManager
  10. {
  11. private static readonly bool Error;
  12. private static readonly Configuration AppConfig;
  13. static ConfigManager()
  14. {
  15. var dllPath =$"{AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory}\\Quanjiang.DigitalScholl.PushNotifications.dll";
  16. try
  17. {
  18. AppConfig = ConfigurationManager.OpenExeConfiguration(dllPath);
  19. }
  20. catch (ConfigurationErrorsException)
  21. {
  22. Error = true;
  23. }
  24. }
  25. public static KeyValueConfigurationCollection AppSettings
  26. {
  27. get
  28. {
  29. if (Error) return null;
  30. return AppConfig.AppSettings.Settings;
  31. }
  32. }
  33. public static ConnectionStringSettingsCollection ConnectionStrings
  34. {
  35. get
  36. {
  37. if (Error) return null;
  38. return AppConfig.ConnectionStrings.ConnectionStrings;
  39. }
  40. }
  41. public static T GetSection<T>(string name) where T : ConfigurationSection
  42. {
  43. if (Error) return null;
  44. return AppConfig.GetSection(name) as T;
  45. }
  46. }
  47. }