OciSessionHandle.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // OciSessionHandle.cs
  3. //
  4. // Part of managed C#/.NET library System.Data.OracleClient.dll
  5. //
  6. // Part of the Mono class libraries at
  7. // mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci
  8. //
  9. // Assembly: System.Data.OracleClient.dll
  10. // Namespace: System.Data.OracleClient.Oci
  11. //
  12. // Author:
  13. // Tim Coleman <[email protected]>
  14. //
  15. // Copyright (C) Tim Coleman, 2003
  16. //
  17. using System;
  18. using System.Runtime.InteropServices;
  19. namespace System.Data.OracleClient.Oci {
  20. internal sealed class OciSessionHandle : OciHandle, IDisposable
  21. {
  22. #region Fields
  23. OciErrorHandle errorHandle;
  24. OciServiceHandle serviceHandle;
  25. bool begun = false;
  26. bool disposed = false;
  27. string username;
  28. string password;
  29. #endregion // Fields
  30. #region Constructors
  31. public OciSessionHandle (OciHandle parent, IntPtr handle)
  32. : base (OciHandleType.Session, parent, handle)
  33. {
  34. }
  35. #endregion // Constructors
  36. #region Properties
  37. public OciServiceHandle Service {
  38. get { return serviceHandle; }
  39. set { serviceHandle = value; }
  40. }
  41. public string Username {
  42. get { return username; }
  43. set { username = value; }
  44. }
  45. public string Password {
  46. get { return password; }
  47. set { password = value; }
  48. }
  49. #endregion // Properties
  50. #region Methods
  51. public bool BeginSession (OciCredentialType credentialType, OciSessionMode mode, OciErrorHandle error)
  52. {
  53. errorHandle = error;
  54. int status = 0;
  55. status = OciCalls.OCIAttrSetString (this,
  56. OciHandleType.Session,
  57. username,
  58. (uint) username.Length,
  59. OciAttributeType.Username,
  60. errorHandle);
  61. if (status != 0)
  62. return false;
  63. status = OciCalls.OCIAttrSetString (this,
  64. OciHandleType.Session,
  65. password,
  66. (uint) password.Length,
  67. OciAttributeType.Password,
  68. errorHandle);
  69. if (status != 0)
  70. return false;
  71. status = OciCalls.OCISessionBegin (Service,
  72. errorHandle,
  73. Handle,
  74. credentialType,
  75. mode);
  76. if (status != 0)
  77. return false;
  78. begun = true;
  79. return true;
  80. }
  81. public void EndSession (OciErrorHandle error)
  82. {
  83. if (!begun)
  84. return;
  85. OciCalls.OCISessionEnd (Service, error, this, 0);
  86. }
  87. protected override void Dispose (bool disposing)
  88. {
  89. if (!disposed) {
  90. try {
  91. EndSession (errorHandle);
  92. disposed = false;
  93. } finally {
  94. base.Dispose (disposing);
  95. }
  96. }
  97. }
  98. #endregion // Methods
  99. }
  100. }