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.

273 lines
8.2 KiB

  1. using System;
  2. using System.Web.UI;
  3. using UDDI;
  4. using UDDI.API;
  5. using UDDI.API.Business;
  6. using UDDI.API.Service;
  7. using UDDI.API.Binding;
  8. using UDDI.API.ServiceType;
  9. using UDDI.Diagnostics;
  10. namespace UDDI.Web
  11. {
  12. public class ExplorerControl : UserControl
  13. {
  14. protected EntityBase entity;
  15. protected int elementIndex = -1;
  16. protected string key = "";
  17. protected bool frames = false;
  18. protected TreeView tree;
  19. public void Initialize( EntityBase entity )
  20. {
  21. this.entity = entity;
  22. }
  23. public void Initialize( EntityBase entity, int elementIndex )
  24. {
  25. this.entity = entity;
  26. this.elementIndex = elementIndex;
  27. }
  28. protected override void OnInit( EventArgs e )
  29. {
  30. key = Request[ "key" ];
  31. frames = ( "true" == Request[ "frames" ] );
  32. }
  33. protected override void OnPreRender( EventArgs e )
  34. {
  35. if( null == entity )
  36. return;
  37. string root = ( "/" == Request.ApplicationPath ) ? "" : Request.ApplicationPath;
  38. int contactIndex = 0;
  39. int instanceIndex = 0;
  40. EntityBase rootEntity = null;
  41. if( entity is BusinessEntity )
  42. {
  43. rootEntity = entity;
  44. if( -1 != elementIndex )
  45. key = ((BusinessEntity)entity).BusinessKey + ":" + elementIndex;
  46. else
  47. key = ((BusinessEntity)entity).BusinessKey;
  48. }
  49. else if( entity is TModel )
  50. {
  51. rootEntity = entity;
  52. key = ((TModel)entity).TModelKey;
  53. }
  54. else if( entity is BusinessService )
  55. {
  56. BusinessEntity business = new BusinessEntity();
  57. BusinessService service = (BusinessService)entity;
  58. key = service.ServiceKey;
  59. business.BusinessKey = service.BusinessKey;
  60. business.Get();
  61. rootEntity = business;
  62. }
  63. else if( entity is BindingTemplate )
  64. {
  65. BusinessEntity business = new BusinessEntity();
  66. BusinessService service = new BusinessService();
  67. BindingTemplate binding = (BindingTemplate)entity;
  68. if( -1 != elementIndex )
  69. key = binding.BindingKey + ":" + elementIndex;
  70. else
  71. key = binding.BindingKey;
  72. service.ServiceKey = binding.ServiceKey;
  73. service.Get();
  74. business.BusinessKey = service.BusinessKey;
  75. business.Get();
  76. rootEntity = business;
  77. }
  78. //
  79. // Setup explorer information section.
  80. //
  81. if( rootEntity is BusinessEntity )
  82. {
  83. BusinessEntity business = rootEntity as BusinessEntity;
  84. //
  85. // Build explorer tree.
  86. //
  87. TreeNode businessNode = tree.Nodes.Add(
  88. business.Names[ 0 ].Value,
  89. business.BusinessKey,
  90. "../images/business.gif" );
  91. businessNode.OnClick = "Entity_OnSelect( [[node]], '../details/businessdetail.aspx?key=" + business.BusinessKey + Iff( frames, "&frames=true", "" ) + "' )";
  92. businessNode.Tooltip = Localization.GetString( "TOOLTIP_SEARCH_PROVIDER" );
  93. if( key == business.BusinessKey )
  94. businessNode.Select();
  95. contactIndex = 0;
  96. foreach( Contact contact in business.Contacts )
  97. {
  98. TreeNode contactNode = businessNode.Nodes.Add(
  99. contact.PersonName,
  100. business.BusinessKey + ":" + contactIndex,
  101. "../images/contact.gif" );
  102. contactNode.OnClick = "Entity_OnSelect( [[node]], '../details/contactdetail.aspx?key=" + business.BusinessKey + "&index=" + contactIndex + Iff( frames, "&frames=true", "" ) + "' )";
  103. contactNode.Tooltip = Localization.GetString( "TOOLTIP_SEARCH_CONTACT" );
  104. if( key == business.BusinessKey + ":" + contactIndex )
  105. contactNode.Select();
  106. contactIndex ++;
  107. }
  108. //sort the services
  109. business.BusinessServices.Sort();
  110. foreach( BusinessService service in business.BusinessServices )
  111. {
  112. if( service.BusinessKey.ToLower() != business.BusinessKey.ToLower() )
  113. {
  114. //
  115. // Added logic to catch errors on this.
  116. // if the refrenced service doesn't exist,
  117. // then we can't get the name, thus we get
  118. // an error.
  119. //
  120. TreeNode nodeService;
  121. //
  122. // if there are names, then the service projections still exists,
  123. // use the first name in teh collection.
  124. // otherwise leave name as the broken projection string.
  125. //
  126. if( service.Names.Count>0 )
  127. {
  128. nodeService = businessNode.Nodes.Add(
  129. service.Names[ 0 ].Value,
  130. service.ServiceKey,
  131. "../images/service_projection.gif" );
  132. nodeService.OnClick = "Entity_OnSelect( [[node]], '../details/servicedetail.aspx?key=" + service.ServiceKey + Iff( frames, "&frames=true", "" ) + "&projectionKey="+business.BusinessKey+"' )";
  133. nodeService.Tooltip = Localization.GetString( "TOOLTIP_SEARCH_SERVICEPROJECTION" );
  134. }
  135. else
  136. {
  137. nodeService = businessNode.Nodes.Add(
  138. Localization.GetString( "BUTTON_PROJECTIONBROKEN" ),
  139. service.ServiceKey,
  140. "../images/x.gif" );
  141. nodeService.OnClick = "javascript:alert('"+Localization.GetString( "TOOLTIP_PROJECTIONBROKEN" )+"');";
  142. nodeService.Tooltip = Localization.GetString( "TOOLTIP_PROJECTIONBROKEN" );
  143. }
  144. }
  145. else
  146. {
  147. TreeNode serviceNode = businessNode.Nodes.Add(
  148. service.Names[ 0 ].Value,
  149. service.ServiceKey,
  150. "../images/service.gif" );
  151. serviceNode.OnClick = "Entity_OnSelect( [[node]], '../details/servicedetail.aspx?key=" + service.ServiceKey + Iff( frames, "&frames=true", "" ) + "' )";
  152. serviceNode.Tooltip = Localization.GetString( "TOOLTIP_SEARCH_SERVICE" );
  153. if( key == service.ServiceKey )
  154. serviceNode.Select();
  155. int bindingCount = 0;
  156. foreach( BindingTemplate binding in service.BindingTemplates )
  157. {
  158. bindingCount ++;
  159. TreeNode bindingNode = serviceNode.Nodes.Add(
  160. UDDI.Utility.StringEmpty( binding.AccessPoint.Value )
  161. ? Localization.GetString( "HEADING_NONE" )
  162. : binding.AccessPoint.Value,
  163. binding.BindingKey,
  164. "../images/binding.gif" );
  165. bindingNode.OnClick = "Entity_OnSelect( [[node]], '../details/bindingdetail.aspx?key=" + binding.BindingKey + Iff( frames, "&frames=true", "" ) + "' )";
  166. bindingNode.Tooltip = Localization.GetString( "TOOLTIP_SEARCH_BINDING" );
  167. if( key == binding.BindingKey )
  168. bindingNode.Select();
  169. instanceIndex = 0;
  170. foreach( TModelInstanceInfo instance in binding.TModelInstanceInfos )
  171. {
  172. TreeNode instanceNode = bindingNode.Nodes.Add(
  173. UDDI.Utility.StringEmpty( instance.TModelKey )
  174. ? Localization.GetString( "HEADING_NONE" )
  175. : Lookup.TModelName( instance.TModelKey ),
  176. binding.BindingKey + ":" + instanceIndex,
  177. "../images/instance.gif" );
  178. instanceNode.OnClick = "Entity_OnSelect( [[node]], '../details/instanceinfodetail.aspx?key=" + binding.BindingKey + "&index=" + instanceIndex + Iff( frames, "&frames=true", "" ) + "' )";
  179. instanceNode.Tooltip = Localization.GetString( "TOOLTIP_SEARCH_INSTANCE_INFO" );
  180. if( key == binding.BindingKey + ":" + instanceIndex )
  181. instanceNode.Select();
  182. instanceIndex ++;
  183. }
  184. }
  185. }
  186. }
  187. }
  188. else if( rootEntity is TModel )
  189. {
  190. TModel tModel = rootEntity as TModel;
  191. //
  192. // Build explorer tree.
  193. //
  194. TreeNode nodeTModel = tree.Nodes.Add(
  195. tModel.Name,
  196. tModel.TModelKey,
  197. "../images/tmodel.gif" );
  198. nodeTModel.OnClick = "Entity_OnSelect( [[node]], '../details/modeldetail.aspx?key=" + Conversions.GuidStringFromKey( tModel.TModelKey ) + Iff( frames, "&frames=true", "" ) + "' )";
  199. nodeTModel.Tooltip = Localization.GetString( "TOOLTIP_SEARCH_TMODEL" );
  200. nodeTModel.Select();
  201. }
  202. else
  203. {
  204. Debug.Assert( false, "Unknown root entity '" + rootEntity.ToString() + "'." );
  205. }
  206. if( null != tree.SelectedNode )
  207. {
  208. tree.SelectedNode.EnsureVisible();
  209. tree.SelectedNode.Expand();
  210. }
  211. }
  212. //
  213. // TODO: IIF function may not be required, consider using C# tenery operator
  214. //
  215. protected string Iff( bool expr, string trueResult, string falseResult )
  216. {
  217. if( expr )
  218. return trueResult;
  219. else
  220. return falseResult;
  221. }
  222. }
  223. }