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.

322 lines
9.2 KiB

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.HtmlControls;
  7. using System.Web.UI.WebControls;
  8. using System.Collections;
  9. using UDDI.Web;
  10. using UDDI.API;
  11. using UDDI.API.Service;
  12. using UDDI.API.Business;
  13. namespace UDDI.VisualStudio
  14. {
  15. //
  16. // Just a simple class to help us keep track of our results.
  17. //
  18. public class ResultsCache
  19. {
  20. public ResultsCache()
  21. {}
  22. public ResultsCache( SearchType searchType, string searchParams )
  23. {
  24. this.searchType = searchType;
  25. this.searchParams = searchParams;
  26. }
  27. public string searchParams;
  28. public SearchType searchType;
  29. public int numResults;
  30. }
  31. public class SearchPage : Page
  32. {
  33. //
  34. // These controls are bound to elements on our .aspx page. We do not need to instantiate
  35. // these objects, ASP.NET will assign values to them for us.
  36. //
  37. protected HtmlGenericControl html_hasResultsLabel;
  38. protected HtmlGenericControl html_noResultsLabel;
  39. protected HtmlGenericControl html_searchResultsMsg;
  40. protected HtmlGenericControl html_browseResultsMsg;
  41. protected HtmlGenericControl html_hasResultsMsg;
  42. protected ResultsList uddi_resultsList;
  43. //
  44. // These values will be displayed in search.aspx using <%= tags
  45. //
  46. protected ResultsCache results;
  47. /// <summary>
  48. /// Override OnLoad to do our initialization.
  49. /// </summary>
  50. /// <param name="args">Passed by ASP.NET, we don't use it.</param>
  51. protected override void OnLoad( EventArgs args )
  52. {
  53. //
  54. // See if we already have a cached search, if we do, we'll use it. We only cache search params,
  55. // result count and the search type, we'll get values from our database all the time.
  56. //
  57. results = Session[ StateParamNames.Results ] as ResultsCache;
  58. //
  59. // If we don't have search results, get them
  60. //
  61. if( null == results )
  62. {
  63. //
  64. // Instantiate our results cache
  65. //
  66. results = new ResultsCache();
  67. //
  68. // Run our query based on the search type and display the results
  69. //
  70. string temp = Request[ StateParamNames.SearchType ];
  71. if( null == temp || temp.Length == 0 )
  72. {
  73. Response.Redirect( "error.aspx" );
  74. }
  75. results.searchType = ( SearchType ) Int32.Parse( temp );
  76. if( results.searchType == SearchType.SearchByService || results.searchType == SearchType.SearchByProvider )
  77. {
  78. results.searchParams = GetSearchParams();
  79. }
  80. }
  81. //
  82. // Search type determines what sproc to run.
  83. //
  84. SqlStoredProcedureAccessor searchCommand = new SqlStoredProcedureAccessor();
  85. switch( results.searchType )
  86. {
  87. case SearchType.SearchByService:
  88. {
  89. searchCommand.ProcedureName = "VS_AWR_services_get";
  90. searchCommand.Parameters.Add( "@serviceName", SqlDbType.NVarChar, 450 );
  91. searchCommand.Parameters.SetString( "@serviceName", results.searchParams );
  92. break;
  93. }
  94. case SearchType.SearchByProvider:
  95. {
  96. searchCommand.ProcedureName = "VS_AWR_businesses_get";
  97. searchCommand.Parameters.Add( "@businessName", SqlDbType.NVarChar, 450 );
  98. searchCommand.Parameters.SetString( "@businessName", results.searchParams );
  99. break;
  100. }
  101. case SearchType.SearchFromBrowse:
  102. {
  103. searchCommand.ProcedureName = "VS_AWR_categorization_get";
  104. searchCommand.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  105. searchCommand.Parameters.Add( "@keyValue", SqlDbType.NVarChar, 255 );
  106. searchCommand.Parameters.SetGuidFromString( "@tModelKey", GetTModelKey() );
  107. searchCommand.Parameters.SetString( "@keyValue", GetKeyValue() );
  108. break;
  109. }
  110. }
  111. //
  112. // Get the results that we are supposed to display.
  113. //
  114. SqlDataReaderAccessor resultsReader = searchCommand.ExecuteReader();
  115. results.numResults = uddi_resultsList.ParseResults( resultsReader );
  116. resultsReader.Close();
  117. //
  118. // Store our results in session state
  119. //
  120. Session[ StateParamNames.Results ] = results;
  121. DisplaySearchMessages( results.numResults );
  122. }
  123. private void DisplaySearchMessages(int numResults )
  124. {
  125. //
  126. // Depending on whether we have results or not, show or hide the panel that will show our results.
  127. //
  128. if( numResults > 0 )
  129. {
  130. if( results.searchType == SearchType.SearchFromBrowse )
  131. {
  132. html_browseResultsMsg.Visible = true;
  133. html_searchResultsMsg.Visible = false;
  134. }
  135. else
  136. {
  137. html_browseResultsMsg.Visible = false;
  138. html_searchResultsMsg.Visible = true;
  139. }
  140. html_hasResultsLabel.Visible = true;
  141. html_noResultsLabel.Visible = false;
  142. }
  143. else
  144. {
  145. html_hasResultsLabel.Visible = false;
  146. html_noResultsLabel.Visible = true;
  147. }
  148. }
  149. private string GetKeyValue()
  150. {
  151. string keyValue = Request[ StateParamNames.KeyValue ];
  152. if( null == keyValue || keyValue.Length == 0 )
  153. {
  154. return "%";
  155. }
  156. return Server.UrlDecode( keyValue );
  157. }
  158. private string GetTModelKey()
  159. {
  160. //
  161. // Get the tModel key to search on
  162. //
  163. string tModelKey = Request[ StateParamNames.TModelKey ];
  164. if( null == tModelKey || tModelKey.Length == 0 )
  165. {
  166. Response.Redirect( "error.aspx" );
  167. }
  168. return Server.UrlDecode( tModelKey );
  169. }
  170. private string GetSearchParams()
  171. {
  172. //
  173. // Make sure we have search params
  174. //
  175. string searchParams = Request[ StateParamNames.SearchParams ];
  176. if( null == searchParams || searchParams.Length == 0 )
  177. {
  178. Response.Redirect( "error.aspx" );
  179. }
  180. return searchParams;
  181. }
  182. }
  183. ///**********************************************************************************
  184. /// <summary>
  185. /// Class to help manage help link localization.
  186. /// </summary>
  187. ///**********************************************************************************
  188. public class HelpLinkControl : UserControl
  189. {
  190. private string helpstring;
  191. /// *****************************************************************************
  192. /// <summary>
  193. /// Text for the Help Message.
  194. ///
  195. /// If a localization key is provided, then a the string will be set to the
  196. /// Localized value.
  197. /// </summary>
  198. /// *****************************************************************************
  199. public string HelpString
  200. {
  201. get{ return helpstring; }
  202. set
  203. {
  204. if( Localization.IsKey( (string)value ) )
  205. helpstring=Localization.GetString( Localization.StripMarkup( (string)value ) );
  206. else
  207. helpstring=value;
  208. }
  209. }
  210. private string helplinktext;
  211. /// *****************************************************************************
  212. /// <summary>
  213. /// Text for the Link inside the help Message.
  214. ///
  215. /// If a localization key is provided, then a the string will be set to the
  216. /// Localized value.
  217. /// </summary>
  218. /// *****************************************************************************
  219. public string HelpLinkText
  220. {
  221. get{ return helplinktext; }
  222. set
  223. {
  224. if( Localization.IsKey( (string)value ) )
  225. helplinktext=Localization.GetString( Localization.StripMarkup( (string)value ) );
  226. else
  227. helplinktext=value;
  228. }
  229. }
  230. private string navigateurl;
  231. /// *****************************************************************************
  232. /// <summary>
  233. /// Url that the HelpLink will navigate too.
  234. /// </summary>
  235. /// *****************************************************************************
  236. public string NavigateUrl
  237. {
  238. get{ return navigateurl; }
  239. set{ navigateurl=value; }
  240. }
  241. private string navigatetarget;
  242. /// *****************************************************************************
  243. /// <summary>
  244. /// Url Target of the Help Link
  245. /// </summary>
  246. /// *****************************************************************************
  247. public string NavigateTarget
  248. {
  249. get{ return navigatetarget; }
  250. set{ navigatetarget=value; }
  251. }
  252. private string cssclass;
  253. public string CssClass
  254. {
  255. get{ return cssclass; }
  256. set{ cssclass=value; }
  257. }
  258. /// <summary>
  259. /// method to write content to the Response Stream
  260. /// </summary>
  261. /// <param name="output">Stream to write output too.</param>
  262. protected override void Render( HtmlTextWriter output )
  263. {
  264. UDDI.Diagnostics.Debug.Verify( null!=HelpLinkText,"UDDI_ERROR_FATALERROR_AWR_NULLHELPLINKTEXT" );
  265. UDDI.Diagnostics.Debug.Verify( null!=HelpString,"UDDI_ERROR_FATALERROR_AWR_NULLHELPSTRING" );
  266. string hyperlink = "";
  267. if( null!=NavigateUrl )
  268. {
  269. //build the hyperlink.
  270. hyperlink="<a href=\"" + NavigateUrl + "\"" +
  271. ((null!=NavigateTarget )?" target=\"" + NavigateTarget + "\" " : "" ) + " >{0}</a>";
  272. hyperlink = string.Format( hyperlink, HelpLinkText );
  273. }
  274. if( null!=CssClass ) //if a stylesheet class was provided add it to the stream to be rendered
  275. output.AddAttribute( HtmlTextWriterAttribute.Class,CssClass ) ;
  276. output.RenderBeginTag( HtmlTextWriterTag.Span );
  277. //format the help string with the hyperlink string.
  278. output.Write( HelpString, ((""!=hyperlink)?hyperlink:HelpLinkText ) );
  279. output.RenderEndTag();
  280. }
  281. }
  282. }