Leaked source code of windows server 2003
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.

192 lines
6.1 KiB

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.IO;
  5. using System.Text;
  6. using System.Xml;
  7. using System.Xml.Serialization;
  8. using UDDI.API;
  9. using UDDI.API.Business;
  10. using UDDI.API.Service;
  11. using UDDI.API.ServiceType;
  12. using UDDI;
  13. using UDDI.Diagnostics;
  14. namespace UDDI.Web
  15. {
  16. /// ********************************************************************
  17. /// public class CacheObject
  18. /// --------------------------------------------------------------------
  19. /// <summary>
  20. /// Encapsulates a session cache object.
  21. /// </summary>
  22. /// ********************************************************************
  23. ///
  24. [ XmlRoot( "cacheObject" ) ]
  25. public class CacheObject
  26. {
  27. [XmlElement( "find_business", typeof( FindBusiness ) )]
  28. public UDDI.API.Business.FindBusiness FindBusiness;
  29. [XmlElement( "find_service", typeof( FindService ) )]
  30. public UDDI.API.Service.FindService FindService;
  31. [XmlElement( "find_tModel", typeof( FindTModel ) )]
  32. public UDDI.API.ServiceType.FindTModel FindTModel;
  33. [XmlAttribute( "findType" )]
  34. public string FindType;
  35. [ XmlIgnore ]
  36. public string UserID;
  37. public CacheObject()
  38. {
  39. }
  40. public void Save()
  41. {
  42. SessionCache.Save( UserID, this );
  43. }
  44. }
  45. public class SessionCache
  46. {
  47. /// ****************************************************************
  48. /// public Get
  49. /// ----------------------------------------------------------------
  50. /// <summary>
  51. /// Retrieves a cache object from the session cache.
  52. /// </summary>
  53. /// ----------------------------------------------------------------
  54. /// <param name="userID">
  55. /// The user id.
  56. /// </param>
  57. /// ----------------------------------------------------------------
  58. /// <returns>
  59. /// The cache object.
  60. /// </returns>
  61. /// ****************************************************************
  62. ///
  63. public static CacheObject Get( string userID )
  64. {
  65. Debug.Enter();
  66. //
  67. // Retrieve the cache object from the database.
  68. //
  69. string data = "";
  70. SqlCommand cmd = new SqlCommand( "UI_getSessionCache", ConnectionManager.GetConnection() );
  71. cmd.CommandType = CommandType.StoredProcedure;
  72. cmd.Transaction = ConnectionManager.GetTransaction();
  73. cmd.Parameters.Add( new SqlParameter( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID ) ).Direction = ParameterDirection.Input;
  74. cmd.Parameters.Add( new SqlParameter( "@context", SqlDbType.NVarChar, UDDI.Constants.Lengths.Context ) ).Direction = ParameterDirection.Input;
  75. cmd.Parameters[ "@PUID" ].Value = userID;
  76. cmd.Parameters[ "@context" ].Value = "WebServer";
  77. data = (string)cmd.ExecuteScalar();
  78. //
  79. // Deserialize into a cache object.
  80. //
  81. CacheObject cache = null;
  82. if( !Utility.StringEmpty( data ) )
  83. {
  84. XmlSerializer serializer = new XmlSerializer( typeof( CacheObject ) );
  85. StringReader reader = new StringReader( data );
  86. cache = (CacheObject)serializer.Deserialize( reader );
  87. cache.UserID = userID;
  88. }
  89. Debug.Leave();
  90. return cache;
  91. }
  92. /// ****************************************************************
  93. /// public Save
  94. /// ----------------------------------------------------------------
  95. /// <summary>
  96. /// Stores the cache object in the session cache.
  97. /// </summary>
  98. /// ----------------------------------------------------------------
  99. /// <param name="userID">
  100. /// The user id.
  101. /// </param>
  102. ///
  103. /// <param name="cacheObject">
  104. /// The cache object.
  105. /// </param>
  106. /// ****************************************************************
  107. ///
  108. public static void Save( string userID, CacheObject cache )
  109. {
  110. Debug.Enter();
  111. //
  112. // Serialize the data into a stream.
  113. //
  114. XmlSerializer serializer = new XmlSerializer( typeof( CacheObject ) );
  115. UTF8EncodedStringWriter writer = new UTF8EncodedStringWriter();
  116. serializer.Serialize( writer, cache );
  117. //
  118. // Write the cache object to the database.
  119. //
  120. SqlCommand cmd = new SqlCommand( "UI_setSessionCache", ConnectionManager.GetConnection() );
  121. cmd.CommandType = CommandType.StoredProcedure;
  122. cmd.Transaction = ConnectionManager.GetTransaction();
  123. cmd.Parameters.Add( new SqlParameter( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID ) ).Direction = ParameterDirection.Input;
  124. cmd.Parameters.Add( new SqlParameter( "@cacheValue", SqlDbType.NText ) ).Direction = ParameterDirection.Input;
  125. cmd.Parameters.Add( new SqlParameter( "@context", SqlDbType.NVarChar, UDDI.Constants.Lengths.Context ) ).Direction = ParameterDirection.Input;
  126. cmd.Parameters[ "@PUID" ].Value = userID;
  127. cmd.Parameters[ "@cacheValue" ].Value = writer.ToString();
  128. cmd.Parameters[ "@context" ].Value = "WebServer";
  129. cmd.ExecuteNonQuery();
  130. Debug.Leave();
  131. }
  132. /// ****************************************************************
  133. /// public Discard
  134. /// ----------------------------------------------------------------
  135. /// <summary>
  136. /// Removes a cache object from the session cache.
  137. /// </summary>
  138. /// ----------------------------------------------------------------
  139. /// <param name="userID">
  140. /// The user id.
  141. /// </param>
  142. /// ****************************************************************
  143. ///
  144. public static void Discard( string userID )
  145. {
  146. Debug.Enter();
  147. SqlCommand cmd = new SqlCommand( "UI_removeSessionCache", ConnectionManager.GetConnection() );
  148. cmd.CommandType = CommandType.StoredProcedure;
  149. cmd.Transaction = ConnectionManager.GetTransaction();
  150. cmd.Parameters.Add( new SqlParameter( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID ) ).Direction = ParameterDirection.Input;
  151. cmd.Parameters.Add( new SqlParameter( "@context", SqlDbType.NVarChar, UDDI.Constants.Lengths.Context ) ).Direction = ParameterDirection.Input;
  152. cmd.Parameters[ "@PUID" ].Value = userID;
  153. cmd.Parameters[ "@context" ].Value = "WebServer";
  154. cmd.ExecuteNonQuery();
  155. Debug.Leave();
  156. }
  157. }
  158. }