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.

533 lines
17 KiB

  1. using System;
  2. using System.Web;
  3. using System.Web.UI;
  4. using System.Web.UI.HtmlControls;
  5. using System.Web.UI.WebControls;
  6. using System.Data;
  7. using System.Collections;
  8. using System.Collections.Specialized;
  9. using UDDI.API;
  10. using UDDI.API.ServiceType;
  11. using UDDI.API.Binding;
  12. using UDDI.API.Service;
  13. using UDDI.API.Business;
  14. namespace UDDI.VisualStudio
  15. {
  16. //
  17. // Simple internal class to hold information about a Service.
  18. //
  19. internal class ServiceResultInfo
  20. {
  21. public string serviceName;
  22. public string serviceKey;
  23. }
  24. //
  25. // Simple internal class to hold information about a Business.
  26. //
  27. internal class BusinessResultInfo
  28. {
  29. public string businessName;
  30. public ArrayList serviceResultInfos;
  31. public BusinessResultInfo()
  32. {
  33. serviceResultInfos = new ArrayList();
  34. }
  35. }
  36. /// <summary>
  37. /// ResultsList is a ASP.NET control that will display the results of our search.
  38. /// TODO this class does a lot of work, consider moving some of the rendering out into a separate classs
  39. /// </summary>
  40. public class ResultsList : UserControl
  41. {
  42. //
  43. // This function is defined in search.aspx.
  44. //
  45. private static string EXPAND_JSCRIPT = "toggle(this, '{0}');";
  46. private static string PLUS_SRC = "../images/plus.gif";
  47. private ArrayList results;
  48. private int currentPage;
  49. /// <summary>
  50. /// Use this function to populate a ResultsList instance with raw values from the database.
  51. /// The results from the database must be returned in the following order:
  52. ///
  53. /// businessName
  54. /// businessKey
  55. /// serviceName
  56. /// serviceKey
  57. ///
  58. /// ParseResults will use indexes to read these values from the SqlDataReaderAccessor so this
  59. /// order must be maintained from the database.
  60. /// </summary>
  61. /// <param name="values">Reader returned from the database.</param>
  62. /// <returns></returns>
  63. public int ParseResults( SqlDataReaderAccessor values )
  64. {
  65. results = new ArrayList();
  66. string currentBusinessName = null;
  67. string lastBusinessName = null;
  68. BusinessResultInfo businessInfo = new BusinessResultInfo();
  69. while( values.Read() )
  70. {
  71. currentBusinessName = values.GetString( 0 );
  72. ServiceResultInfo serviceInfo = new ServiceResultInfo();
  73. serviceInfo.serviceName = values.GetString( 2 );
  74. serviceInfo.serviceKey = values.GetString( 3 );
  75. if (null != lastBusinessName && false == lastBusinessName.Equals( currentBusinessName ) )
  76. {
  77. results.Add( businessInfo );
  78. businessInfo = new BusinessResultInfo();
  79. }
  80. businessInfo.businessName = currentBusinessName;
  81. businessInfo.serviceResultInfos.Add( serviceInfo );
  82. lastBusinessName = currentBusinessName;
  83. }
  84. //
  85. // Add our last one.
  86. //
  87. if( businessInfo.serviceResultInfos.Count > 0 )
  88. {
  89. results.Add( businessInfo );
  90. }
  91. return results.Count;
  92. }
  93. /// <summary>
  94. /// Overridden from UserControl. This method will get called when its time to render our control.
  95. /// </summary>
  96. /// <param name="writer">Passed in from ASP.NET, use it to write our HTML</param>
  97. protected override void Render( HtmlTextWriter writer )
  98. {
  99. //
  100. // Figure out our current page and number of results
  101. //
  102. try
  103. {
  104. currentPage = Int32.Parse( Request[ StateParamNames.CurrentPage ] );
  105. }
  106. catch
  107. {
  108. currentPage = 1;
  109. }
  110. RenderResults( writer );
  111. }
  112. /// <summary>
  113. /// This method actually does the work of rendering our results.
  114. /// </summary>
  115. /// <param name="writer">Passed from Render()</param>
  116. private void RenderResults( HtmlTextWriter writer )
  117. {
  118. //
  119. // TODO should this be in the PagingControl?
  120. //
  121. //
  122. // Determine the start and end indexes of the results that we'll display. These values are based
  123. // on the current page that we are displaying.
  124. //
  125. int startIndex;
  126. int endIndex;
  127. GetStartIndex( out startIndex, out endIndex );
  128. if( endIndex > results.Count )
  129. {
  130. endIndex = results.Count;
  131. }
  132. if( startIndex < endIndex )
  133. {
  134. //
  135. // Render everything in table.
  136. //
  137. writer.AddAttribute( HtmlTextWriterAttribute.Width, "95%" );
  138. writer.RenderBeginTag( HtmlTextWriterTag.Table );
  139. //
  140. // Render the range of results.
  141. //
  142. RenderRange( writer, startIndex, endIndex );
  143. //
  144. // Render our paging information
  145. //
  146. RenderPaging( writer );
  147. writer.RenderEndTag(); // TABLE
  148. }
  149. }
  150. private void RenderPaging( HtmlTextWriter writer )
  151. {
  152. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  153. writer.AddAttribute( HtmlTextWriterAttribute.Class, "pagesCell" );
  154. writer.AddAttribute( HtmlTextWriterAttribute.Colspan, "3");
  155. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  156. PagingRenderer paging = new PagingRenderer( results.Count, currentPage , Request.Path);
  157. paging.Render( writer );
  158. writer.RenderEndTag(); // Td
  159. writer.RenderEndTag(); // Tr
  160. }
  161. /// <summary>
  162. /// Renders a range of businesses.
  163. /// </summary>
  164. /// <param name="writer">Writer to use to write our HTML.</param>
  165. /// <param name="startIndex">The beginning of our range of businesses to render.</param>
  166. /// <param name="endIndex">The end of our range of businesses to render.</param>
  167. private void RenderRange( HtmlTextWriter writer, int startIndex, int endIndex )
  168. {
  169. while( startIndex < endIndex )
  170. {
  171. BusinessResultInfo businessResultInfo = ( BusinessResultInfo )results[startIndex];
  172. //
  173. // Render the business name.
  174. //
  175. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  176. writer.AddAttribute( HtmlTextWriterAttribute.Colspan, "3" );
  177. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  178. writer.RenderBeginTag( HtmlTextWriterTag.B );
  179. writer.Write( Server.HtmlEncode( businessResultInfo.businessName ) );
  180. writer.RenderEndTag();
  181. writer.RenderEndTag();
  182. writer.RenderEndTag();
  183. foreach( ServiceResultInfo serviceResultInfo in businessResultInfo.serviceResultInfos )
  184. {
  185. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  186. //
  187. // Write a placeholder cell so we can indent each service info under its
  188. // business name.
  189. //
  190. writer.AddAttribute( HtmlTextWriterAttribute.Class, "space_cell" );
  191. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  192. writer.Write( "&nbsp;" );
  193. writer.RenderEndTag();
  194. //
  195. // Render the service.
  196. //
  197. RenderServiceInfo( serviceResultInfo, writer );
  198. writer.RenderEndTag();
  199. }
  200. startIndex++;
  201. }
  202. }
  203. /// <summary>
  204. /// This method renders an individual service.
  205. /// </summary>
  206. /// <param name="serviceInfo">The service to render.</param>
  207. /// <param name="writer">Writer to use to write our HTML.</param>
  208. private void RenderServiceInfo( ServiceResultInfo serviceInfo, HtmlTextWriter writer )
  209. {
  210. //
  211. // Render a plus/minus tag. We will use the service key of this service to name
  212. // our hidden details panel.
  213. //
  214. writer.AddAttribute( HtmlTextWriterAttribute.Class, "expand_cell" );
  215. writer.AddAttribute( HtmlTextWriterAttribute.Align, "center" );
  216. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  217. RenderExpandTag( writer, serviceInfo.serviceKey );
  218. writer.RenderEndTag();
  219. //
  220. // Render the name of the service. Use the first name that is registered with the service.
  221. //
  222. writer.AddAttribute( HtmlTextWriterAttribute.Width, "100%" );
  223. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  224. writer.Write( Server.HtmlEncode( serviceInfo.serviceName ) );
  225. writer.RenderEndTag();
  226. writer.RenderEndTag();
  227. //
  228. // Render a details panel for the service that is initially hidden.
  229. //
  230. writer.AddAttribute( HtmlTextWriterAttribute.Id, serviceInfo.serviceKey );
  231. writer.AddAttribute( HtmlTextWriterAttribute.Style, "display:none" );
  232. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  233. //
  234. // Skip 2 cells
  235. //
  236. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  237. writer.RenderEndTag();
  238. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  239. writer.RenderEndTag();
  240. writer.AddAttribute( HtmlTextWriterAttribute.Id, serviceInfo.serviceKey + "_detailsPanel" );
  241. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  242. RenderServiceDetail( serviceInfo.serviceKey, writer );
  243. writer.RenderEndTag();
  244. }
  245. /// <summary>
  246. /// Renders the +/- sign used to show or hide the details of a service.
  247. /// </summary>
  248. /// <param name="writer">Writer to use to write our HTML.</param>
  249. /// <param name="serviceKey">The service key is used to uniquely identify this HTML component. We need to do this for the script
  250. /// that is located in search.aspx.
  251. /// </param>
  252. private void RenderExpandTag( HtmlTextWriter writer, string serviceKey)
  253. {
  254. string jscript = EXPAND_JSCRIPT.Replace( "{0}", serviceKey );
  255. writer.AddAttribute( HtmlTextWriterAttribute.Style, "cursor:hand" );
  256. writer.AddAttribute( HtmlTextWriterAttribute.Src, ResultsList.PLUS_SRC );
  257. writer.AddAttribute( HtmlTextWriterAttribute.Onclick, jscript );
  258. writer.RenderBeginTag( HtmlTextWriterTag.Img );
  259. writer.RenderEndTag();
  260. }
  261. private void RenderServiceDetail( string serviceKey, HtmlTextWriter writer )
  262. {
  263. //
  264. // Get details for this service
  265. //
  266. StringCollection serviceKeys = new StringCollection();
  267. serviceKeys.Add( serviceKey );
  268. ServiceDetail serviceDetail = new ServiceDetail();
  269. serviceDetail.Get( serviceKeys );
  270. //
  271. // We will only get the first one
  272. //
  273. BusinessService businessService = serviceDetail.BusinessServices[ 0 ];
  274. writer.AddAttribute( HtmlTextWriterAttribute.Width, "100%" );
  275. writer.AddAttribute( HtmlTextWriterAttribute.Class, "serviceDetailOuterTable" );
  276. writer.RenderBeginTag( HtmlTextWriterTag.Table );
  277. //
  278. // Render the business descriptions if there is one
  279. //
  280. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  281. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  282. writer.RenderBeginTag( HtmlTextWriterTag.B );
  283. writer.Write( Localization.GetString( "AWR_SERVICE_DESCRIPTION" ) );
  284. writer.RenderEndTag(); // B
  285. writer.RenderEndTag(); // Td
  286. writer.RenderEndTag(); // Tr
  287. foreach( Description description in businessService.Descriptions )
  288. {
  289. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  290. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  291. writer.Write( Server.HtmlEncode( description.Value ) );
  292. writer.RenderEndTag(); // Td
  293. writer.RenderEndTag(); // Tr
  294. }
  295. //
  296. // Render each binding in the service that has a WSDL file associated with it
  297. //
  298. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  299. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  300. writer.RenderBeginTag( HtmlTextWriterTag.B );
  301. writer.Write( Localization.GetString( "AWR_BINDINGS" ) );
  302. writer.RenderEndTag(); // B
  303. writer.RenderEndTag(); // Td
  304. writer.RenderEndTag(); // Tr
  305. foreach( BindingTemplate bindingTemplate in businessService.BindingTemplates )
  306. {
  307. //
  308. // Render each binding in a row
  309. //
  310. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  311. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  312. writer.AddAttribute( HtmlTextWriterAttribute.Width, "100%" );
  313. writer.AddAttribute( HtmlTextWriterAttribute.Class, "accessPointTable" );
  314. writer.RenderBeginTag( HtmlTextWriterTag.Table );
  315. //
  316. // Render the access point
  317. //
  318. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  319. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  320. writer.RenderBeginTag( HtmlTextWriterTag.B );
  321. writer.Write( Localization.GetString( "AWR_ACCESS_POINT" ) );
  322. writer.RenderEndTag(); // B
  323. writer.RenderEndTag(); // Td
  324. writer.RenderEndTag(); // Tr
  325. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  326. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  327. writer.Write( Server.HtmlEncode( bindingTemplate.AccessPoint.Value ) );
  328. writer.RenderEndTag(); // Td
  329. writer.RenderEndTag(); // Tr
  330. //
  331. // Render the descriptions.
  332. //
  333. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  334. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  335. writer.RenderBeginTag( HtmlTextWriterTag.B );
  336. writer.Write( Localization.GetString( "AWR_DESCRIPTION" ) );
  337. writer.RenderEndTag(); // B
  338. writer.RenderEndTag(); // Td
  339. writer.RenderEndTag(); // Tr
  340. foreach( Description description in bindingTemplate.Descriptions )
  341. {
  342. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  343. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  344. writer.Write( Server.HtmlEncode( description.Value ) );
  345. writer.RenderEndTag(); // Td
  346. writer.RenderEndTag(); // Tr
  347. //
  348. // Render an empty row between descriptions
  349. //
  350. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  351. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  352. writer.RenderEndTag(); // Tr
  353. writer.RenderEndTag(); // Td
  354. }
  355. //
  356. // Render the WSDL files. We are assuming that any overview doc urls are urls to WSDL files
  357. //
  358. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  359. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  360. writer.RenderBeginTag( HtmlTextWriterTag.B );
  361. writer.Write( Localization.GetString( "AWR_ID" ) );
  362. writer.RenderEndTag(); // B
  363. writer.RenderEndTag(); // Td
  364. writer.RenderEndTag(); // Tr
  365. int wsdlCount = 0;
  366. foreach( TModelInstanceInfo instanceInfo in bindingTemplate.TModelInstanceInfos )
  367. {
  368. //
  369. // Get the tModel related to this instance.
  370. //
  371. TModel tModel = new TModel( instanceInfo.TModelKey );
  372. //
  373. // We don't want any exceptions ruining the rest of our display
  374. //
  375. try
  376. {
  377. //
  378. // Get details for this tModel.
  379. //
  380. tModel.Get();
  381. bool isWsdlSpec = false;
  382. foreach( KeyedReference keyedReference in tModel.CategoryBag )
  383. {
  384. if( true == keyedReference.KeyValue.Equals( UDDI.Constants.UDDITypeTaxonomyWSDLSpecKeyValue ) &&
  385. true == keyedReference.TModelKey.ToLower().Equals( UDDI.Constants.UDDITypeTaxonomyTModelKey ) )
  386. {
  387. isWsdlSpec = true;
  388. break;
  389. }
  390. }
  391. //
  392. // If this tModel has an overview doc, then consider that document as the link to the
  393. // WSDL file.
  394. //
  395. if( true == isWsdlSpec &&
  396. null != tModel.OverviewDoc.OverviewURL &&
  397. tModel.OverviewDoc.OverviewURL.Length > 0 )
  398. {
  399. //
  400. // Render the WSDL link
  401. //
  402. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  403. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  404. //
  405. // Render the arrow image.
  406. //
  407. writer.AddAttribute( HtmlTextWriterAttribute.Src, "../images/orange_arrow_right.gif" );
  408. writer.RenderBeginTag( HtmlTextWriterTag.Img );
  409. writer.Write("&nbsp;");
  410. writer.RenderEndTag(); // Img
  411. //
  412. // Make the overview URL a hyper link
  413. //
  414. writer.AddAttribute( HtmlTextWriterAttribute.Href, tModel.OverviewDoc.OverviewURL );
  415. writer.RenderBeginTag( HtmlTextWriterTag.A );
  416. writer.Write( tModel.OverviewDoc.OverviewURL );
  417. writer.RenderEndTag(); // A
  418. //
  419. // Render the first description if there is one
  420. //
  421. if( tModel.OverviewDoc.Descriptions.Count > 0 )
  422. {
  423. writer.Write( "&nbsp;-&nbsp;" );
  424. writer.Write( tModel.OverviewDoc.Descriptions[0].Value );
  425. }
  426. wsdlCount++;
  427. writer.RenderEndTag(); // Td
  428. writer.RenderEndTag(); // Tr
  429. }
  430. }
  431. catch
  432. {
  433. //
  434. // Intentionally empty.
  435. //
  436. }
  437. }
  438. //
  439. // If there were no WSDL files registered, render a message saying so.
  440. //
  441. if( 0 == wsdlCount )
  442. {
  443. writer.RenderBeginTag( HtmlTextWriterTag.Tr );
  444. writer.RenderBeginTag( HtmlTextWriterTag.Td );
  445. writer.Write( Localization.GetString( "AWR_NO_WSDLS" ) );
  446. writer.RenderEndTag(); // Td
  447. writer.RenderEndTag(); // Tr
  448. }
  449. writer.RenderEndTag(); // TABLE
  450. writer.RenderEndTag(); // Td
  451. writer.RenderEndTag(); // Tr
  452. }
  453. writer.RenderEndTag(); // TABLE
  454. }
  455. /// <summary>
  456. /// Returns the start index of the result we are supposed to show, taking into account paging.
  457. /// </summary>
  458. /// <param name="startIndex">The start index.</param>
  459. /// <param name="rawEndIndex">The 'raw' end index; that is not taking into account whether this value exceeds the number of pages we have.</param>
  460. private void GetStartIndex( out int startIndex, out int rawEndIndex )
  461. {
  462. startIndex = ( currentPage - 1) * Constants.NumResultsPerPage;
  463. rawEndIndex = startIndex + Constants.NumResultsPerPage;
  464. }
  465. }
  466. }