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.

88 lines
3.2 KiB

2 years ago
  1. using System;
  2. namespace SqlSugar
  3. {
  4. internal class DependencyManagement
  5. {
  6. private static bool IsTryJsonNet = false;
  7. private static bool IsTryMySqlData = false;
  8. private static bool IsTrySqlite = false;
  9. private static bool IsTryOracle = false;
  10. public static void TryJsonNet()
  11. {
  12. if (!IsTryJsonNet)
  13. {
  14. try
  15. {
  16. new SerializeService().SerializeObject(new { });
  17. IsTryJsonNet = true;
  18. }
  19. catch
  20. {
  21. var message = ErrorMessage.GetThrowMessage(
  22. " SqlSugar Some functions are used in newtonsoft ,Nuget references Newtonsoft.Json 9.0.0.1 + .",
  23. " SqlSugar 部分功能用到Newtonsoft.Json.dll,需要在Nuget上安装 Newtonsoft.Json 9.0.0.1及以上版本。如果有版本兼容问题请先删除原有引用(注意:所有项目类库),全部重新从NUGET下载,如果还不明白,请查看详细教程 http://www.codeisbug.com/Doc/8/1154");
  24. throw new Exception(message);
  25. }
  26. }
  27. }
  28. public static void TryMySqlData()
  29. {
  30. if (!IsTryMySqlData)
  31. {
  32. try
  33. {
  34. var db = new MySqlProvider();
  35. var conn = db.GetAdapter();
  36. IsTryMySqlData = true;
  37. }
  38. catch
  39. {
  40. var message = ErrorMessage.GetThrowMessage(
  41. "You need to refer to MySql.Data.dll",
  42. "需要引用MySql.Data.dll,请在Nuget安装最新稳定版本,如果有版本兼容问题请先删除原有引用");
  43. throw new Exception(message);
  44. }
  45. }
  46. }
  47. internal static void TryOracle()
  48. {
  49. if (!IsTryOracle)
  50. {
  51. try
  52. {
  53. var db = new OracleProvider();
  54. var conn = db.GetAdapter();
  55. IsTryOracle = true;
  56. }
  57. catch
  58. {
  59. var message = ErrorMessage.GetThrowMessage(
  60. "You need to refer to Oracle.ManagedDataAccess.dll",
  61. "需要引用ManagedDataAccess.dll,请在Nuget安装最新稳定版本,如果有版本兼容问题请先删除原有引用");
  62. throw new Exception(message);
  63. }
  64. }
  65. }
  66. public static void TrySqlite()
  67. {
  68. if (!IsTrySqlite)
  69. {
  70. try
  71. {
  72. var db = new SqliteProvider();
  73. var conn = db.GetAdapter();
  74. IsTrySqlite = true;
  75. }
  76. catch (Exception ex)
  77. {
  78. var message = ErrorMessage.GetThrowMessage(
  79. "You need to refer to System.Data.SQLite.dll." + ex.Message,
  80. "你需要引用System.Data.SQLite.dll,如果有版本兼容问题请先删除原有引用");
  81. throw new Exception(message);
  82. }
  83. }
  84. }
  85. }
  86. }