电子药箱通讯服务端
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.

ConnectionSessionScope.cs 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace RDH.Data
  7. {
  8. public class ConnectionSessionScope : IDisposable
  9. {
  10. public bool HasOpen { get; set; }
  11. public ConnectionSessionScope()
  12. {
  13. if (ConnectionFactory.Current.GetSessionConnection().State != System.Data.ConnectionState.Open)
  14. {
  15. try
  16. {
  17. ConnectionFactory.Current.GetSessionConnection().Open();
  18. HasOpen = true;
  19. }
  20. catch (Exception ex)
  21. {
  22. HasOpen = false;
  23. throw ex;
  24. }
  25. }
  26. }
  27. public ConnectionSessionScope(String connString)
  28. {
  29. if (ConnectionFactory.Current.GetSessionConnection(connString).State != System.Data.ConnectionState.Open)
  30. {
  31. try
  32. {
  33. ConnectionFactory.Current.GetSessionConnection(connString).Open();
  34. HasOpen = true;
  35. }
  36. catch (Exception ex)
  37. {
  38. HasOpen = false;
  39. }
  40. }
  41. }
  42. public void Dispose()
  43. {
  44. ConnectionFactory.Current.CloseSessionConnection();
  45. }
  46. }
  47. }