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.

1059 lines
28 KiB

  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using System.Collections.Specialized;
  5. using System.ComponentModel;
  6. using System.Data.SqlClient;
  7. using System.Xml.Serialization;
  8. using UDDI;
  9. using UDDI.Diagnostics;
  10. using UDDI.Replication;
  11. using UDDI.API.ServiceType;
  12. namespace UDDI.API.Binding
  13. {
  14. /// ****************************************************************
  15. /// class BindingTemplate
  16. /// ----------------------------------------------------------------
  17. /// <summary>
  18. /// </summary>
  19. /// ****************************************************************
  20. ///
  21. [XmlRootAttribute( "bindingTemplate", Namespace=UDDI.API.Constants.Namespace )]
  22. public class BindingTemplate : EntityBase
  23. {
  24. //
  25. // Attribute: bindingKey
  26. //
  27. [XmlAttribute("bindingKey")]
  28. public string BindingKey = "";
  29. //
  30. // Attribute: serviceKey
  31. //
  32. [XmlAttribute("serviceKey")]
  33. public string ServiceKey = "";
  34. //
  35. // Element: description
  36. //
  37. private DescriptionCollection descriptions;
  38. [XmlElement("description")]
  39. public DescriptionCollection Descriptions
  40. {
  41. get
  42. {
  43. if( null == descriptions )
  44. descriptions = new DescriptionCollection();
  45. return descriptions;
  46. }
  47. set { descriptions = value; }
  48. }
  49. //
  50. // Element: accessPoint
  51. //
  52. private AccessPoint accessPoint;
  53. [XmlElement("accessPoint")]
  54. public AccessPoint AccessPointSerialize
  55. {
  56. get
  57. {
  58. if( null != accessPoint && accessPoint.ShouldSerialize )
  59. return accessPoint;
  60. return null;
  61. }
  62. set { accessPoint = value; }
  63. }
  64. [XmlIgnore]
  65. public AccessPoint AccessPoint
  66. {
  67. get
  68. {
  69. if( null == accessPoint )
  70. accessPoint = new AccessPoint();
  71. return accessPoint;
  72. }
  73. }
  74. //
  75. // Element: hostingRedirector
  76. //
  77. private HostingRedirector hostingRedirector;
  78. [XmlElement("hostingRedirector")]
  79. public HostingRedirector HostingRedirectorSerialize
  80. {
  81. get
  82. {
  83. if( null != hostingRedirector && hostingRedirector.ShouldSerialize )
  84. return hostingRedirector;
  85. return null;
  86. }
  87. set
  88. {
  89. hostingRedirector = value;
  90. }
  91. }
  92. [XmlIgnore]
  93. public HostingRedirector HostingRedirector
  94. {
  95. get
  96. {
  97. if( null == hostingRedirector )
  98. hostingRedirector = new HostingRedirector();
  99. return hostingRedirector;
  100. }
  101. }
  102. //
  103. // Element: tModelInstanceDetails
  104. //
  105. private TModelInstanceInfoCollection tModelInstanceInfos;
  106. [ XmlArray( "tModelInstanceDetails" ), XmlArrayItem( "tModelInstanceInfo" ) ]
  107. public TModelInstanceInfoCollection TModelInstanceInfos
  108. {
  109. get
  110. {
  111. if( null == tModelInstanceInfos )
  112. tModelInstanceInfos = new TModelInstanceInfoCollection();
  113. return tModelInstanceInfos;
  114. }
  115. set { tModelInstanceInfos = value; }
  116. }
  117. [XmlIgnore]
  118. public override UDDI.EntityType EntityType
  119. {
  120. get { return EntityType.BindingTemplate; }
  121. }
  122. [XmlIgnore]
  123. public override string EntityKey
  124. {
  125. get { return BindingKey; }
  126. }
  127. /// ****************************************************************
  128. /// public BindingTemplate [constructor]
  129. /// ----------------------------------------------------------------
  130. /// <summary>
  131. /// </summary>
  132. /// ****************************************************************
  133. ///
  134. public BindingTemplate()
  135. {
  136. }
  137. /// ****************************************************************
  138. /// public BindingTemplate [constructor]
  139. /// ----------------------------------------------------------------
  140. /// <summary>
  141. /// </summary>
  142. /// ----------------------------------------------------------------
  143. /// <param name="bindingKey">
  144. /// </param>
  145. /// ****************************************************************
  146. ///
  147. public BindingTemplate( string bindingKey )
  148. {
  149. BindingKey = bindingKey;
  150. }
  151. /// ****************************************************************
  152. /// public Delete
  153. /// ----------------------------------------------------------------
  154. /// <summary>
  155. /// Removes the specified bindingTemplate from the database.
  156. /// </summary>
  157. /// ----------------------------------------------------------------
  158. /// <returns>
  159. /// </returns>
  160. /// ----------------------------------------------------------------
  161. /// <remarks>
  162. /// The bindingKey must be set prior to execution of this call.
  163. /// </remarks>
  164. /// ****************************************************************
  165. ///
  166. public override void Delete()
  167. {
  168. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_bindingTemplate_delete" );
  169. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  170. sp.Parameters.Add( "@bindingKey", SqlDbType.UniqueIdentifier );
  171. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  172. sp.Parameters.SetString( "@PUID", Context.User.ID );
  173. sp.Parameters.SetGuidFromString( "@bindingKey", BindingKey );
  174. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  175. sp.ExecuteNonQuery();
  176. //
  177. // Save the change log entry.
  178. //
  179. if( Context.LogChangeRecords )
  180. {
  181. ChangeRecord changeRecord = new ChangeRecord();
  182. changeRecord.Payload = new ChangeRecordDelete( EntityType.BindingTemplate, BindingKey );
  183. changeRecord.Log();
  184. }
  185. }
  186. /// ****************************************************************
  187. /// public Get
  188. /// ----------------------------------------------------------------
  189. /// <summary>
  190. /// Retrieves the bindingTemplate details from the database.
  191. /// </summary>
  192. /// ----------------------------------------------------------------
  193. /// <returns>
  194. /// </returns>
  195. /// ----------------------------------------------------------------
  196. /// <remarks>
  197. /// The bindingKey must be set prior to execution of this call.
  198. /// </remarks>
  199. /// ****************************************************************
  200. ///
  201. public override void Get()
  202. {
  203. Debug.Enter();
  204. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_bindingTemplate_get_batch" );
  205. sp.Parameters.Add( "@bindingKey", SqlDbType.UniqueIdentifier );
  206. sp.Parameters.Add( "@serviceKey", SqlDbType.UniqueIdentifier, ParameterDirection.Output );
  207. sp.Parameters.Add( "@URLTypeID", SqlDbType.TinyInt, ParameterDirection.Output );
  208. sp.Parameters.Add( "@accessPoint", SqlDbType.NVarChar, UDDI.Constants.Lengths.AccessPoint, ParameterDirection.Output );
  209. sp.Parameters.Add( "@hostingRedirector", SqlDbType.UniqueIdentifier, ParameterDirection.Output );
  210. sp.Parameters.SetGuidFromString( "@bindingKey", BindingKey );
  211. SqlDataReaderAccessor reader = null;
  212. ArrayList instanceIds = new ArrayList();
  213. try
  214. {
  215. //
  216. // net_bindingTemplate_get will return the objects contained in a business in the following order:
  217. //
  218. // - descriptions
  219. // - tmodel instance infos
  220. reader = sp.ExecuteReader();
  221. //
  222. // Read the descriptions
  223. //
  224. Descriptions.Read( reader );
  225. //
  226. // Read the tmodel instance infos
  227. //
  228. if( true == reader.NextResult() )
  229. {
  230. instanceIds = TModelInstanceInfos.Read( reader );
  231. }
  232. }
  233. finally
  234. {
  235. if( null != reader )
  236. {
  237. reader.Close();
  238. }
  239. }
  240. //
  241. // These calls will make separate sproc calls, so we have to close our reader first.
  242. //
  243. TModelInstanceInfos.Populate( instanceIds );
  244. //
  245. // Get output parameters
  246. //
  247. ServiceKey = sp.Parameters.GetGuidString( "@serviceKey" );
  248. AccessPoint.URLType = (URLType)sp.Parameters.GetInt( "@URLTypeID" );
  249. AccessPoint.Value = sp.Parameters.GetString( "@accessPoint" );
  250. HostingRedirector.BindingKey = sp.Parameters.GetGuidString( "@hostingRedirector" );
  251. #if never
  252. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_bindingTemplate_get" );
  253. sp.Parameters.Add( "@bindingKey", SqlDbType.UniqueIdentifier );
  254. sp.Parameters.Add( "@serviceKey", SqlDbType.UniqueIdentifier, ParameterDirection.Output );
  255. sp.Parameters.Add( "@URLTypeID", SqlDbType.TinyInt, ParameterDirection.Output );
  256. sp.Parameters.Add( "@accessPoint", SqlDbType.NVarChar, UDDI.Constants.Lengths.AccessPoint, ParameterDirection.Output );
  257. sp.Parameters.Add( "@hostingRedirector", SqlDbType.UniqueIdentifier, ParameterDirection.Output );
  258. sp.Parameters.SetGuidFromString( "@bindingKey", BindingKey );
  259. sp.ExecuteNonQuery();
  260. ServiceKey = sp.Parameters.GetGuidString( "@serviceKey" );
  261. AccessPoint.URLType = (URLType)sp.Parameters.GetInt( "@URLTypeID" );
  262. AccessPoint.Value = sp.Parameters.GetString( "@accessPoint" );
  263. HostingRedirector.BindingKey = sp.Parameters.GetGuidString( "@hostingRedirector" );
  264. //
  265. // Get all contained objects.
  266. //
  267. Descriptions.Get( BindingKey, EntityType.BindingTemplate );
  268. TModelInstanceInfos.Get( BindingKey );
  269. #endif
  270. QueryLog.Write( QueryType.Get, EntityType.BindingTemplate );
  271. }
  272. /// ****************************************************************
  273. /// public InnerSave
  274. /// ----------------------------------------------------------------
  275. /// <summary>
  276. /// Stores the bindingTemplate details into the database.
  277. /// </summary>
  278. /// ****************************************************************
  279. ///
  280. internal void InnerSave( string serviceKey )
  281. {
  282. if( 0 == ServiceKey.Length )
  283. ServiceKey = serviceKey;
  284. else
  285. Debug.Verify( 0 == String.Compare( ServiceKey, serviceKey, true ), "UDDI_ERROR_INVALIDKEYPASSED_BINDINGPROJECTION", ErrorType.E_invalidKeyPassed );
  286. if( Utility.StringEmpty( BindingKey ) )
  287. {
  288. //
  289. // This is an insert so, generate a bindingkey
  290. //
  291. BindingKey = Guid.NewGuid().ToString();
  292. }
  293. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_bindingTemplate_save" );
  294. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  295. sp.Parameters.Add( "@bindingKey", SqlDbType.UniqueIdentifier );
  296. sp.Parameters.Add( "@serviceKey", SqlDbType.UniqueIdentifier );
  297. sp.Parameters.Add( "@generic", SqlDbType.VarChar, UDDI.Constants.Lengths.generic );
  298. sp.Parameters.Add( "@URLTypeID", SqlDbType.TinyInt );
  299. sp.Parameters.Add( "@accessPoint", SqlDbType.NVarChar, UDDI.Constants.Lengths.AccessPoint );
  300. sp.Parameters.Add( "@hostingRedirector", SqlDbType.UniqueIdentifier );
  301. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  302. sp.Parameters.Add( "@lastChange", SqlDbType.BigInt );
  303. sp.Parameters.SetString( "@PUID", Context.User.ID );
  304. sp.Parameters.SetGuidFromString( "@bindingKey", BindingKey );
  305. sp.Parameters.SetGuidFromString( "@serviceKey", ServiceKey );
  306. sp.Parameters.SetString( "@generic", Constants.Version );
  307. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  308. if( null != AccessPoint )
  309. {
  310. sp.Parameters.SetShort( "@URLTypeID", (short)AccessPoint.URLType );
  311. sp.Parameters.SetString( "@accessPoint", AccessPoint.Value );
  312. }
  313. if( null != HostingRedirector )
  314. sp.Parameters.SetGuidFromString( "@hostingRedirector", HostingRedirector.BindingKey );
  315. sp.Parameters.SetLong( "@lastChange", DateTime.UtcNow.Ticks );
  316. sp.ExecuteNonQuery();
  317. //
  318. // Save all contained objects.
  319. //
  320. Descriptions.Save( BindingKey, EntityType.BindingTemplate );
  321. TModelInstanceInfos.Save( BindingKey );
  322. }
  323. /// ****************************************************************
  324. /// internal Validate
  325. /// ----------------------------------------------------------------
  326. /// <summary>
  327. /// </summary>
  328. /// ****************************************************************
  329. ///
  330. internal void Validate()
  331. {
  332. //
  333. // Check to make sure that either the hosting redirector or the accessPoint were specified
  334. //
  335. if( Utility.StringEmpty( AccessPoint.Value ) && Utility.StringEmpty( HostingRedirector.BindingKey ) )
  336. throw new UDDIException( ErrorType.E_fatalError,"UDDI_ERROR_FATALERROR_BINDING_APVALUEMISSING" );
  337. //
  338. // Check for a circular reference
  339. //
  340. if( 0 == String.Compare( BindingKey, HostingRedirector.BindingKey, true ) )
  341. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_BINDING_HRSELFREFERENCE" );
  342. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_bindingTemplate_validate" );
  343. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  344. sp.Parameters.Add( "@bindingKey", SqlDbType.UniqueIdentifier );
  345. sp.Parameters.Add( "@serviceKey", SqlDbType.UniqueIdentifier );
  346. sp.Parameters.Add( "@hostingRedirector", SqlDbType.UniqueIdentifier );
  347. sp.Parameters.Add( "@flag", SqlDbType.Int );
  348. sp.Parameters.SetString( "@PUID", Context.User.ID );
  349. sp.Parameters.SetGuidFromString( "@bindingKey", BindingKey );
  350. sp.Parameters.SetGuidFromString( "@serviceKey", ServiceKey );
  351. sp.Parameters.SetGuidFromString( "@hostingRedirector", HostingRedirector.BindingKey );
  352. if( Context.User.AllowPreassignedKeys )
  353. sp.Parameters.SetInt( "@flag", 1 );
  354. else
  355. sp.Parameters.SetInt( "@flag", 0 );
  356. sp.ExecuteNonQuery();
  357. //
  358. // Validate field length for AccessPoint.Value
  359. //
  360. Utility.ValidateLength( ref AccessPoint.Value, "accessPoint", UDDI.Constants.Lengths.AccessPoint );
  361. Descriptions.Validate();
  362. TModelInstanceInfos.Validate();
  363. }
  364. /// ****************************************************************
  365. /// public Save
  366. /// ----------------------------------------------------------------
  367. /// <summary>
  368. /// Stores the bindingTemplate details into the database, as a
  369. /// child of the service specified by the key.
  370. /// </summary>
  371. /// ****************************************************************
  372. ///
  373. public override void Save()
  374. {
  375. Validate();
  376. InnerSave( this.ServiceKey );
  377. //
  378. // Save the change log entry.
  379. //
  380. if( Context.LogChangeRecords )
  381. {
  382. ChangeRecord changeRecord = new ChangeRecord();
  383. changeRecord.Payload = new ChangeRecordNewData( this );
  384. changeRecord.Log();
  385. }
  386. }
  387. }
  388. /// ********************************************************************
  389. /// public class BindingTemplateCollection
  390. /// --------------------------------------------------------------------
  391. /// <summary>
  392. /// </summary>
  393. /// ********************************************************************
  394. ///
  395. public class BindingTemplateCollection : CollectionBase
  396. {
  397. /// ****************************************************************
  398. /// public Get
  399. /// ----------------------------------------------------------------
  400. /// <summary>
  401. /// Populates the collection with all binding templates related to
  402. /// the specified service.
  403. /// </summary>
  404. /// ----------------------------------------------------------------
  405. /// <param name="serviceKey">
  406. /// Key of the parent service. A Guid formatted as a string.
  407. /// </param>
  408. /// ----------------------------------------------------------------
  409. /// <returns>
  410. ///
  411. /// </returns>
  412. /// ----------------------------------------------------------------
  413. /// <remarks>
  414. ///
  415. /// </remarks>
  416. /// ****************************************************************
  417. ///
  418. public void Get( string serviceKey )
  419. {
  420. //
  421. // Get all the bindings associated with the specified service
  422. //
  423. SqlStoredProcedureAccessor cmd = new SqlStoredProcedureAccessor( "net_businessService_bindingTemplates_get" );
  424. cmd.Parameters.Add( "@serviceKey", SqlDbType.UniqueIdentifier, ParameterDirection.Input );
  425. cmd.Parameters.SetGuidFromString( "@serviceKey", serviceKey );
  426. SqlDataReaderAccessor reader = cmd.ExecuteReader();
  427. try
  428. {
  429. Read( reader );
  430. #if never
  431. //
  432. // Get the keys of the services for this business ID
  433. //
  434. while( rdr.Read() )
  435. {
  436. Add( rdr.GetGuid(0).ToString() );
  437. }
  438. #endif
  439. }
  440. finally
  441. {
  442. reader.Close();
  443. }
  444. Populate();
  445. #if never
  446. //
  447. // Populate each binding
  448. //
  449. foreach( BindingTemplate bt in this )
  450. {
  451. bt.Get();
  452. }
  453. #endif
  454. }
  455. public void Read( SqlDataReaderAccessor reader )
  456. {
  457. //
  458. // Get the keys of the services for this business ID
  459. //
  460. while( reader.Read() )
  461. {
  462. Add( reader.GetGuidString(0) );
  463. }
  464. }
  465. public void Populate()
  466. {
  467. //
  468. // Populate each binding
  469. //
  470. foreach( BindingTemplate bt in this )
  471. {
  472. bt.Get();
  473. }
  474. }
  475. /// ****************************************************************
  476. /// internal Validate
  477. /// ----------------------------------------------------------------
  478. /// <summary>
  479. /// </summary>
  480. /// ----------------------------------------------------------------
  481. /// <remarks>
  482. /// </remarks>
  483. /// ****************************************************************
  484. ///
  485. internal void Validate()
  486. {
  487. foreach( BindingTemplate bt in this )
  488. {
  489. bt.Validate();
  490. }
  491. }
  492. /// ****************************************************************
  493. /// public Save
  494. /// ----------------------------------------------------------------
  495. /// <summary>
  496. /// Saves the contained binding templates. Relates them to
  497. /// the service specified by the serviceKey argument.
  498. /// </summary>
  499. /// ----------------------------------------------------------------
  500. /// <param name="serviceKey">
  501. /// Key of the parent service. A Guid formatted as a string.
  502. /// </param>
  503. /// ----------------------------------------------------------------
  504. /// <returns>
  505. /// </returns>
  506. /// ----------------------------------------------------------------
  507. /// <remarks>
  508. /// This method simply calls the Save() method on all contained
  509. /// BindingTemplates.
  510. /// </remarks>
  511. /// ****************************************************************
  512. ///
  513. public void Save( string serviceKey )
  514. {
  515. foreach( BindingTemplate bt in this )
  516. {
  517. bt.InnerSave( serviceKey );
  518. }
  519. }
  520. public void Save()
  521. {
  522. foreach( BindingTemplate bt in this )
  523. {
  524. bt.Save();
  525. }
  526. }
  527. public BindingTemplate this[ int index ]
  528. {
  529. get
  530. { return (BindingTemplate)List[index]; }
  531. set
  532. { List[index] = value; }
  533. }
  534. public int Add( BindingTemplate value )
  535. {
  536. return List.Add(value);
  537. }
  538. public int Add( string bindingKey )
  539. {
  540. return List.Add( new BindingTemplate( bindingKey ) );
  541. }
  542. public int Add()
  543. {
  544. return List.Add( new BindingTemplate() );
  545. }
  546. public void Insert(int index, BindingTemplate value)
  547. {
  548. List.Insert(index, value);
  549. }
  550. public int IndexOf(BindingTemplate value)
  551. {
  552. return List.IndexOf(value);
  553. }
  554. public bool Contains(BindingTemplate value)
  555. {
  556. return List.Contains(value);
  557. }
  558. public void Remove(BindingTemplate value)
  559. {
  560. List.Remove(value);
  561. }
  562. public void CopyTo( BindingTemplate[] array )
  563. {
  564. foreach( BindingTemplate binding in array )
  565. Add( binding );
  566. }
  567. public BindingTemplate[] ToArray()
  568. {
  569. return (BindingTemplate[])InnerList.ToArray( typeof( BindingTemplate ) );
  570. }
  571. }
  572. /// ****************************************************************
  573. /// class AccessPoint
  574. /// ----------------------------------------------------------------
  575. /// <summary>
  576. /// An AccessPoint describes the URL where services are available.
  577. /// </summary>
  578. /// ****************************************************************
  579. ///
  580. public class AccessPoint
  581. {
  582. // ----[Attribute: URLType]-----------------------------------------
  583. [XmlAttribute("URLType")]
  584. public URLType URLType;
  585. // ----[Element Text]-----------------------------------------------
  586. [XmlText]
  587. public string Value;
  588. public AccessPoint()
  589. {
  590. URLType = UDDI.API.URLType.Http;
  591. }
  592. public AccessPoint( string accessPointValue )
  593. {
  594. Value = accessPointValue;
  595. }
  596. [XmlIgnore]
  597. public bool ShouldSerialize
  598. {
  599. get
  600. {
  601. if( null != Value )
  602. return true;
  603. return false;
  604. }
  605. }
  606. }
  607. /// ****************************************************************
  608. /// class HostingRedirector
  609. /// ----------------------------------------------------------------
  610. /// <summary>
  611. /// A HostingRedirector describes a service location using another
  612. /// bindingTemplate.
  613. /// </summary>
  614. /// ****************************************************************
  615. ///
  616. public class HostingRedirector
  617. {
  618. // ----[Attribute: bindingKey]--------------------------------------------
  619. [XmlAttribute("bindingKey")]
  620. public string BindingKey;
  621. [XmlIgnore]
  622. public bool ShouldSerialize
  623. {
  624. get
  625. {
  626. if( null != BindingKey )
  627. return true;
  628. return false;
  629. }
  630. }
  631. }
  632. /// ****************************************************************
  633. /// class DeleteBinding
  634. /// ----------------------------------------------------------------
  635. /// <summary>
  636. /// The DeleteBinding class contains data and methods associated
  637. /// with the delete_binding message. It is typically populated
  638. /// via deserialization by the .NET runtime as part of the
  639. /// message processing interface.
  640. ///
  641. /// As part of the publisher API, this message implements
  642. /// IAuthenticateable. This allows the enclosed authInfo to be
  643. /// authorized prior to processing
  644. /// </summary>
  645. /// ****************************************************************
  646. ///
  647. [XmlRootAttribute( "delete_binding", Namespace=UDDI.API.Constants.Namespace )]
  648. public class DeleteBinding : IAuthenticateable, IMessage
  649. {
  650. //
  651. // Attribute: generic
  652. //
  653. private string generic;
  654. [XmlAttribute("generic")]
  655. public string Generic
  656. {
  657. get { return generic; }
  658. set { generic = value; }
  659. }
  660. //
  661. // Element: authInfo
  662. //
  663. private string authInfo;
  664. [XmlElement("authInfo")]
  665. public string AuthInfo
  666. {
  667. get { return authInfo; }
  668. set { authInfo = value; }
  669. }
  670. //
  671. // Element: bindingKey
  672. //
  673. [XmlElement("bindingKey")]
  674. public StringCollection BindingKeys;
  675. public DeleteBinding()
  676. {
  677. Generic = UDDI.API.Constants.Version;
  678. }
  679. public void Delete()
  680. {
  681. foreach( string key in BindingKeys )
  682. {
  683. BindingTemplate bt = new BindingTemplate( key );
  684. bt.Delete();
  685. }
  686. }
  687. }
  688. [XmlRootAttribute("find_binding", Namespace=UDDI.API.Constants.Namespace)]
  689. public class FindBinding : IMessage
  690. {
  691. //
  692. // Attribute: generic
  693. //
  694. private string generic;
  695. [XmlAttribute("generic")]
  696. public string Generic
  697. {
  698. get { return generic; }
  699. set { generic = value; }
  700. }
  701. //
  702. // Attribute: maxRows
  703. //
  704. private int maxRows = -1;
  705. [XmlAttribute( "maxRows" ), DefaultValue( -1 )]
  706. public int MaxRows
  707. {
  708. get { return maxRows; }
  709. set
  710. {
  711. if( value < 0 )
  712. {
  713. throw new UDDIException(
  714. ErrorType.E_fatalError,
  715. "UDDI_ERROR_FATALERROR_FINDBINDING_MAXROWSLESSTHANZERO" );
  716. }
  717. maxRows = value;
  718. }
  719. }
  720. //
  721. // Attribute: serviceKey
  722. //
  723. [XmlAttribute("serviceKey")]
  724. public string ServiceKey;
  725. //
  726. // Element: findQualifiers/findQualifier
  727. //
  728. [XmlArray("findQualifiers"), XmlArrayItem("findQualifier")]
  729. public FindQualifierCollection FindQualifiers;
  730. //
  731. // Element: tModelBag/tModelKey
  732. //
  733. [XmlArray("tModelBag"), XmlArrayItem("tModelKey")]
  734. public StringCollection TModelBag;
  735. public FindBinding()
  736. {
  737. Generic = UDDI.API.Constants.Version;
  738. }
  739. public BindingDetail Find()
  740. {
  741. BindingDetail bindingDetail = new BindingDetail();
  742. QueryLog.Write( QueryType.Find, EntityType.BindingTemplate );
  743. //
  744. // Validate find parameters.
  745. //
  746. Utility.IsValidKey( EntityType.BusinessService, ServiceKey );
  747. //
  748. // Process each find constraint.
  749. //
  750. FindBuilder find = new FindBuilder( EntityType.BindingTemplate, FindQualifiers, ServiceKey );
  751. //
  752. // If no search arguments are specified, return an empty result
  753. // set.
  754. //
  755. if( Utility.CollectionEmpty( TModelBag ) )
  756. return bindingDetail;
  757. try
  758. {
  759. int rows = 1;
  760. //
  761. // Find entities with matching parent key.
  762. //
  763. if( !Utility.StringEmpty( ServiceKey ) )
  764. rows = find.FindByParentKey( ServiceKey );
  765. //
  766. // Find entities with matching TModel bag items.
  767. //
  768. if( !Utility.CollectionEmpty( TModelBag ) )
  769. rows = find.FindByTModelBag( TModelBag );
  770. //
  771. // Process the find result set.
  772. //
  773. if( 0 == rows )
  774. {
  775. //
  776. // Cleanup any temporary tables.
  777. //
  778. find.Abort();
  779. }
  780. else if( 0 == MaxRows )
  781. {
  782. bindingDetail.Truncated = Truncated.True;
  783. return bindingDetail;
  784. }
  785. else
  786. {
  787. //
  788. // Read in the find results.
  789. //
  790. SqlDataReaderAccessor reader;
  791. SqlStoredProcedureAccessor sp;
  792. sp = find.RetrieveResults( MaxRows );
  793. reader = sp.ExecuteReader();
  794. try
  795. {
  796. while( reader.Read() )
  797. bindingDetail.BindingTemplates.Add( reader.GetGuidString( "entityKey" ) );
  798. }
  799. finally
  800. {
  801. reader.Close();
  802. }
  803. if( sp.Parameters.GetBool( "@truncated" ) )
  804. bindingDetail.Truncated = Truncated.True;
  805. else
  806. bindingDetail.Truncated = Truncated.False;
  807. foreach( BindingTemplate bindingTemplate in bindingDetail.BindingTemplates )
  808. bindingTemplate.Get();
  809. }
  810. }
  811. catch( Exception )
  812. {
  813. find.Abort();
  814. throw;
  815. }
  816. return bindingDetail;
  817. }
  818. }
  819. /// ********************************************************************
  820. /// public class GetBindingDetail
  821. /// --------------------------------------------------------------------
  822. /// <summary>
  823. /// </summary>
  824. /// ********************************************************************
  825. ///
  826. [XmlRoot( "get_bindingDetail", Namespace=UDDI.API.Constants.Namespace )]
  827. public class GetBindingDetail : IMessage
  828. {
  829. //
  830. // Attribute: generic
  831. //
  832. private string generic;
  833. [XmlAttribute("generic")]
  834. public string Generic
  835. {
  836. get { return generic; }
  837. set { generic = value; }
  838. }
  839. //
  840. // Element: bindingKey
  841. //
  842. [XmlElement("bindingKey")]
  843. public StringCollection BindingKeys;
  844. public GetBindingDetail()
  845. {
  846. }
  847. }
  848. /// ********************************************************************
  849. /// public class SaveBinding
  850. /// --------------------------------------------------------------------
  851. /// <summary>
  852. /// </summary>
  853. /// ********************************************************************
  854. ///
  855. [XmlRoot( "save_binding", Namespace=UDDI.API.Constants.Namespace )]
  856. public class SaveBinding : IAuthenticateable, IMessage
  857. {
  858. //
  859. // Attribute: generic
  860. //
  861. private string generic;
  862. [XmlAttribute("generic")]
  863. public string Generic
  864. {
  865. get { return generic; }
  866. set { generic = value; }
  867. }
  868. //
  869. // Element: authInfo
  870. //
  871. private string authInfo;
  872. [XmlElement("authInfo")]
  873. public string AuthInfo
  874. {
  875. get { return authInfo; }
  876. set { authInfo = value; }
  877. }
  878. //
  879. // Element: bindingTemplate
  880. //
  881. [XmlElement("bindingTemplate")]
  882. public BindingTemplateCollection BindingTemplates;
  883. /// ****************************************************************
  884. /// public Save
  885. /// ----------------------------------------------------------------
  886. /// <summary>
  887. /// </summary>
  888. /// ****************************************************************
  889. ///
  890. public void Save()
  891. {
  892. BindingTemplates.Save();
  893. }
  894. }
  895. [XmlRoot("bindingDetail", Namespace=UDDI.API.Constants.Namespace)]
  896. public class BindingDetail
  897. {
  898. [XmlAttribute("generic")]
  899. public string Generic = UDDI.API.Constants.Version;
  900. [XmlAttribute("operator")]
  901. public string Operator = Config.GetString( "Operator" );
  902. [XmlAttribute("truncated")]
  903. public Truncated Truncated;
  904. [XmlElement("bindingTemplate")]
  905. public BindingTemplateCollection BindingTemplates = new BindingTemplateCollection();
  906. public void Get( StringCollection bindingKeys )
  907. {
  908. foreach( string key in bindingKeys )
  909. {
  910. int n = BindingTemplates.Add( key );
  911. BindingTemplates[ n ].Get();
  912. }
  913. }
  914. }
  915. }