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.

276 lines
10 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.Globalization;
  8. using System.Collections.Specialized;
  9. using UDDI.Web;
  10. using UDDI.API;
  11. using UDDI.API.Service;
  12. using UDDI.API.Business;
  13. namespace UDDI.VisualStudio
  14. {
  15. /// <summary>
  16. /// This class represents the default page that is displayed in the Add Web Reference
  17. /// Dialog in Visual Studio .NET. This page will display the inital search options to
  18. /// the user.
  19. /// </summary>
  20. public class AddWebReferencePage : Page
  21. {
  22. //
  23. // These controls are bound to elements on our .aspx page. We do not need to instantiate
  24. // these objects, ASP.NET will assign values to them for us.
  25. //
  26. protected UddiButton aspnet_searchByService;
  27. protected UddiButton aspnet_searchByProvider;
  28. protected UddiButton aspnet_searchFromBrowse;
  29. protected UddiButton aspnet_cancelBrowse;
  30. protected UddiTextBox aspnet_serviceName;
  31. protected UddiTextBox aspnet_providerName;
  32. protected Label aspnet_serviceErrorMessage;
  33. protected Label aspnet_providerErrorMessage;
  34. protected Label aspnet_noCategoriesMessage;
  35. protected HelpLinkControl aspnet_helpLink;
  36. protected HtmlGenericControl html_browseSearchButtons;
  37. protected HtmlGenericControl html_searchButtons;
  38. protected CategoryBrowserControl uddi_categoryBrowser;
  39. /// <summary>
  40. /// Event handler for the aspnet_searchByService button click.
  41. /// </summary>
  42. /// <param name="sender">Passed by ASP.NET, we don't use it.</param>
  43. /// <param name="args">Passed by ASP.NET, we don't use it.</param>
  44. public void SearchByService_Click( object sender, EventArgs args )
  45. {
  46. //
  47. // We are searching by service name. Make sure we have a name first.
  48. //
  49. string searchName = aspnet_serviceName.Text;
  50. if( null == searchName || searchName.Equals( string.Empty ) || searchName.Length == 0 )
  51. {
  52. ShowErrorMessage( SearchType.SearchByService );
  53. }
  54. else
  55. {
  56. string url = string.Format( "search.aspx?{0}={1}&{2}={3}", StateParamNames.SearchType,
  57. (int)SearchType.SearchByService,
  58. StateParamNames.SearchParams,
  59. Server.UrlEncode( searchName ) );
  60. Response.Redirect( url );
  61. }
  62. }
  63. /// <summary>
  64. /// Event handler for the aspnet_searchByProvider button click.
  65. /// </summary>
  66. /// <param name="sender">Passed by ASP.NET, we don't use it.</param>
  67. /// <param name="args">Passed by ASP.NET, we don't use it.</param>
  68. public void SearchByProvider_Click( object sender, EventArgs args )
  69. {
  70. //
  71. // We are searching by business name. Make sure we have a name first.
  72. //
  73. string searchName = aspnet_providerName.Text;
  74. if( null == searchName || searchName.Equals( string.Empty ) || searchName.Length == 0 )
  75. {
  76. ShowErrorMessage( SearchType.SearchByProvider );
  77. }
  78. else
  79. {
  80. string url = string.Format( "search.aspx?{0}={1}&{2}={3}", StateParamNames.SearchType,
  81. (int)SearchType.SearchByProvider,
  82. StateParamNames.SearchParams,
  83. Server.UrlEncode( searchName ) );
  84. Response.Redirect( url );
  85. }
  86. }
  87. private void SearchFromBrowse_Click( object sender, EventArgs args )
  88. {
  89. string searchID = ( string ) ViewState[ StateParamNames.SearchID ];
  90. string url = string.Format( "search.aspx?{0}={1}&{2}={3}&{4}={5}", StateParamNames.SearchType,
  91. (int)SearchType.SearchFromBrowse,
  92. Server.UrlEncode( StateParamNames.TModelKey ),
  93. Server.UrlEncode( uddi_categoryBrowser.TModelKey ),
  94. StateParamNames.KeyValue,
  95. Server.UrlEncode( uddi_categoryBrowser.KeyValue ) );
  96. Response.Redirect( url );
  97. }
  98. /// <summary>
  99. /// Displays an error message to the user.
  100. /// </summary>
  101. /// <param name="searchType">The type of search determines what message to show.</param>
  102. private void ShowErrorMessage( SearchType searchType )
  103. {
  104. switch( searchType )
  105. {
  106. case SearchType.SearchByService:
  107. {
  108. aspnet_serviceErrorMessage.Text = Localization.GetString( "AWR_SEARCH_SERVICE_ERROR" );
  109. aspnet_serviceErrorMessage.Visible = true;
  110. break;
  111. }
  112. case SearchType.SearchByProvider:
  113. {
  114. aspnet_providerErrorMessage.Text = Localization.GetString( "AWR_SEARCH_PROVIDER_ERROR" );
  115. aspnet_providerErrorMessage.Visible = true;
  116. break;
  117. }
  118. }
  119. }
  120. protected void CancelBrowse_Click( object sender, EventArgs args )
  121. {
  122. string searchID = ViewState[ StateParamNames.SearchID ] as string;
  123. if( null != searchID && searchID.Length > 0 )
  124. {
  125. SessionCache.Discard( searchID );
  126. }
  127. Response.Redirect( "default.aspx" );
  128. }
  129. protected override void OnLoad( EventArgs args )
  130. {
  131. //
  132. // Whenever we load this page, we want to make sure our session state is cleared out and that
  133. // the default search options are visible.
  134. Session.Clear();
  135. //
  136. // Reset the state of our search and browse buttons
  137. //
  138. html_searchButtons.Visible = true;
  139. html_browseSearchButtons.Visible = false;
  140. //
  141. // Set our help link based on the current culture.
  142. //
  143. // -- this control is not localizable, replacing with localizable version
  144. //aspnet_helpLink.NavigateUrl = string.Format(@"javascript:OnNavigate('{0}/addwebreference/{1}/help.htm')", Request.ApplicationPath, CultureInfo.CurrentCulture.TwoLetterISOLanguageName );
  145. aspnet_helpLink.NavigateUrl = string.Format(@"javascript:OnNavigate('{0}/addwebreference/{1}/help.htm')", Request.ApplicationPath, Localization.GetCulture().LCID );
  146. // We don't use the CacheObject, but the CategoryBrowser control won't work unless this object
  147. // is properly instantiated.
  148. //
  149. CacheObject cacheObject;
  150. if( !this.IsPostBack )
  151. {
  152. string searchID = Guid.NewGuid().ToString();
  153. ViewState[ StateParamNames.SearchID ] = searchID;
  154. cacheObject = new CacheObject();
  155. cacheObject.FindBusiness = new FindBusiness();
  156. cacheObject.FindBusiness.CategoryBag = new KeyedReferenceCollection();
  157. cacheObject.FindBusiness.IdentifierBag = new KeyedReferenceCollection();
  158. cacheObject.FindBusiness.TModelBag = new StringCollection();
  159. cacheObject.FindService = new FindService();
  160. cacheObject.FindService.CategoryBag = new KeyedReferenceCollection();
  161. cacheObject.FindService.TModelBag = new StringCollection();
  162. cacheObject.FindTModel = new UDDI.API.ServiceType.FindTModel();
  163. cacheObject.FindTModel.CategoryBag = new KeyedReferenceCollection();
  164. cacheObject.FindTModel.IdentifierBag = new KeyedReferenceCollection();
  165. SessionCache.Save( searchID, cacheObject );
  166. }
  167. else
  168. {
  169. //
  170. // Get our search ID
  171. //
  172. string searchID = ( string ) ViewState[ StateParamNames.SearchID ];
  173. cacheObject = SessionCache.Get( searchID );
  174. //
  175. // We want to peek in the ASP.NET event pipeline to see if the CategoryBrowser has been invoked. If it
  176. // has, then we want to hide the rest of the search page. The reason is that the CategoryBrowser control
  177. // can't be redirected to another page, so we want to give the appearance that its on a dedicated page.
  178. //
  179. if( null != Request[ "__EVENTTARGET" ] && Request[ "__EVENTTARGET" ].Length > 0 )
  180. {
  181. html_searchButtons.Visible = false;
  182. html_browseSearchButtons.Visible = true;
  183. }
  184. }
  185. //
  186. // A null cacheObject at this point is a fatal error because we can't initialize our CategoryBrowser
  187. // without it.
  188. //
  189. if( null == cacheObject )
  190. {
  191. Response.Redirect( "error.aspx" );
  192. }
  193. uddi_categoryBrowser.Initialize( new KeyedReferenceCollection(), cacheObject );
  194. uddi_categoryBrowser.ShowNoCategoriesMessage = false;
  195. }
  196. /// <summary>
  197. /// This is our last chance to manipulate the page. All we want to do is see if our category browser is going to
  198. /// show any taxonomies. If it isn't, we'll output a message instead of an empty control.
  199. /// </summary>
  200. /// <param name="args"></param>
  201. protected override void OnPreRender( EventArgs args )
  202. {
  203. //
  204. // If we are not in a postback, and there are no taxonomies being shown,
  205. // display a message
  206. //
  207. if( 0 == uddi_categoryBrowser.TaxonomyCount && !IsPostBack )
  208. {
  209. aspnet_noCategoriesMessage.Text = Localization.GetString( "AWR_NO_CATEGORIES" );
  210. aspnet_noCategoriesMessage.Visible = true;
  211. uddi_categoryBrowser.Visible = false;
  212. }
  213. //
  214. // Only enable our search button if we are looking at a categorization scheme that is
  215. // valid for categorization.
  216. //
  217. string taxonomyID = uddi_categoryBrowser.TaxonomyID;
  218. string tModelKey = uddi_categoryBrowser.TModelKey;
  219. string keyValue = uddi_categoryBrowser.KeyValue;
  220. if( null != taxonomyID && taxonomyID.Length > 0 &&
  221. null != keyValue && keyValue.Length > 0 &&
  222. Taxonomy.IsValidForClassification( Convert.ToInt32( taxonomyID ), keyValue ) )
  223. {
  224. aspnet_searchFromBrowse.Enabled = true;
  225. }
  226. else
  227. {
  228. aspnet_searchFromBrowse.Enabled = false;
  229. }
  230. base.OnPreRender( args );
  231. }
  232. /// <summary>
  233. /// Override OnInit to set up our event handlers
  234. /// </summary>
  235. /// <param name="args">Passed by ASP.NET, we dont' use it.</param>
  236. protected override void OnInit( EventArgs args )
  237. {
  238. //
  239. // Hook up our event handlers
  240. //
  241. aspnet_searchByService.Click += new EventHandler( SearchByService_Click );
  242. aspnet_searchByProvider.Click += new EventHandler( SearchByProvider_Click );
  243. aspnet_searchFromBrowse.Click += new EventHandler( SearchFromBrowse_Click );
  244. aspnet_cancelBrowse.Click += new EventHandler( CancelBrowse_Click );
  245. }
  246. }
  247. }