OciSessionHandle.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. OciCredentialType credentialType;
  30. #endregion // Fields
  31. #region Constructors
  32. public OciSessionHandle (OciHandle parent, IntPtr handle)
  33. : base (OciHandleType.Session, parent, handle)
  34. {
  35. }
  36. #endregion // Constructors
  37. #region Properties
  38. public OciServiceHandle Service {
  39. get { return serviceHandle; }
  40. set { serviceHandle = value; }
  41. }
  42. internal string Username {
  43. get { return username; }
  44. set { username = value; }
  45. }
  46. internal string Password {
  47. get { return String.Empty; }
  48. set { password = value; }
  49. }
  50. #endregion // Properties
  51. #region Methods
  52. public bool BeginSession (OciCredentialType credentialType, OciSessionMode mode, OciErrorHandle error)
  53. {
  54. errorHandle = error;
  55. int status = 0;
  56. if (credentialType == OciCredentialType.RDBMS) {
  57. status = OciCalls.OCIAttrSetString (this,
  58. OciHandleType.Session,
  59. username,
  60. (uint) username.Length,
  61. OciAttributeType.Username,
  62. errorHandle);
  63. if (status != 0)
  64. return false;
  65. status = OciCalls.OCIAttrSetString (this,
  66. OciHandleType.Session,
  67. password,
  68. (uint) password.Length,
  69. OciAttributeType.Password,
  70. errorHandle);
  71. if (status != 0)
  72. return false;
  73. }
  74. status = OciCalls.OCISessionBegin (Service,
  75. errorHandle,
  76. Handle,
  77. credentialType,
  78. mode);
  79. if (status != 0)
  80. return false;
  81. begun = true;
  82. return true;
  83. }
  84. public void EndSession (OciErrorHandle error)
  85. {
  86. if (!begun)
  87. return;
  88. OciCalls.OCISessionEnd (Service, error, this, 0);
  89. begun = false;
  90. }
  91. protected override void Dispose (bool disposing)
  92. {
  93. if (!disposed) {
  94. try {
  95. //EndSession (errorHandle);
  96. disposed = false;
  97. } finally {
  98. base.Dispose (disposing);
  99. }
  100. }
  101. }
  102. #endregion // Methods
  103. }
  104. }