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.

1533 lines
38 KiB

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Collections;
  5. using System.Collections.Specialized;
  6. using System.ComponentModel;
  7. using System.Xml.Serialization;
  8. using UDDI;
  9. using UDDI.Diagnostics;
  10. using UDDI.API;
  11. using UDDI.Replication;
  12. using UDDI.API.Service;
  13. using UDDI.API.ServiceType;
  14. namespace UDDI.API.Business
  15. {
  16. /// ********************************************************************
  17. /// class BusinessEntity
  18. /// --------------------------------------------------------------------
  19. /// <summary>
  20. /// </summary>
  21. /// ********************************************************************
  22. ///
  23. [XmlRootAttribute( "businessEntity", Namespace=UDDI.API.Constants.Namespace )]
  24. public class BusinessEntity : EntityBase
  25. {
  26. //
  27. // Attribute: businessKey
  28. //
  29. [XmlAttribute("businessKey")]
  30. public string BusinessKey;
  31. //
  32. // Attribute: operator
  33. //
  34. [XmlAttribute("operator")]
  35. public string Operator;
  36. //
  37. // Attribute: authorizedName
  38. //
  39. [XmlAttribute("authorizedName")]
  40. public string AuthorizedName;
  41. //
  42. // Element: discoveryURLs
  43. //
  44. [ XmlIgnore ]
  45. public DiscoveryUrlCollection DiscoveryUrls = new DiscoveryUrlCollection();
  46. [ XmlArray( "discoveryURLs" ), XmlArrayItem( "discoveryURL" ) ]
  47. public DiscoveryUrl[] DiscoveryUrlsSerialize
  48. {
  49. get
  50. {
  51. if( Utility.CollectionEmpty( DiscoveryUrls ) )
  52. return null;
  53. return DiscoveryUrls.ToArray();
  54. }
  55. set
  56. {
  57. DiscoveryUrls.Clear();
  58. DiscoveryUrls.CopyTo( value );
  59. }
  60. }
  61. //
  62. // Element: name
  63. //
  64. private NameCollection names;
  65. [XmlElement("name")]
  66. public NameCollection Names
  67. {
  68. get
  69. {
  70. if( null == names )
  71. names = new NameCollection();
  72. return names;
  73. }
  74. set { names = value; }
  75. }
  76. //
  77. // Element: description
  78. //
  79. private DescriptionCollection descriptions;
  80. [XmlElement("description")]
  81. public DescriptionCollection Descriptions
  82. {
  83. get
  84. {
  85. if( null == descriptions )
  86. descriptions = new DescriptionCollection();
  87. return descriptions;
  88. }
  89. set { descriptions = value; }
  90. }
  91. //
  92. // Element: contacts
  93. //
  94. [ XmlIgnore ]
  95. public ContactCollection Contacts = new ContactCollection();
  96. [ XmlArray( "contacts" ), XmlArrayItem( "contact" ) ]
  97. public Contact[] ContactsSerialize
  98. {
  99. get
  100. {
  101. if( Utility.CollectionEmpty( Contacts ) )
  102. return null;
  103. return Contacts.ToArray();
  104. }
  105. set
  106. {
  107. Contacts.Clear();
  108. Contacts.CopyTo( value );
  109. }
  110. }
  111. //
  112. // Element: businessServices
  113. //
  114. [ XmlIgnore ]
  115. public BusinessServiceCollection BusinessServices = new BusinessServiceCollection();
  116. [ XmlArray( "businessServices" ), XmlArrayItem( "businessService" ) ]
  117. public BusinessService[] BusinessServicesSerialize
  118. {
  119. get
  120. {
  121. if( Utility.CollectionEmpty( BusinessServices ) )
  122. return null;
  123. return BusinessServices.ToArray();
  124. }
  125. set
  126. {
  127. BusinessServices.Clear();
  128. BusinessServices.CopyTo( value );
  129. }
  130. }
  131. //
  132. // Element: identifierBag
  133. //
  134. [ XmlIgnore ]
  135. public KeyedReferenceCollection IdentifierBag = new KeyedReferenceCollection();
  136. [ XmlArray( "identifierBag" ), XmlArrayItem( "keyedReference" ) ]
  137. public KeyedReference[] IdentifierBagSerialize
  138. {
  139. get
  140. {
  141. if( Utility.CollectionEmpty( IdentifierBag ) )
  142. return null;
  143. return IdentifierBag.ToArray();
  144. }
  145. set
  146. {
  147. IdentifierBag.Clear();
  148. IdentifierBag.CopyTo( value );
  149. }
  150. }
  151. //
  152. // Element: categoryBag
  153. //
  154. [ XmlIgnore ]
  155. public KeyedReferenceCollection CategoryBag = new KeyedReferenceCollection();
  156. [ XmlArray( "categoryBag" ), XmlArrayItem( "keyedReference" ) ]
  157. public KeyedReference[] CategoryBagSerialize
  158. {
  159. get
  160. {
  161. if( Utility.CollectionEmpty( CategoryBag ) )
  162. return null;
  163. return CategoryBag.ToArray();
  164. }
  165. set
  166. {
  167. CategoryBag.Clear();
  168. CategoryBag.CopyTo( value );
  169. }
  170. }
  171. [XmlIgnore]
  172. public override UDDI.EntityType EntityType
  173. {
  174. get { return EntityType.BusinessEntity; }
  175. }
  176. [XmlIgnore]
  177. public override string EntityKey
  178. {
  179. get { return BusinessKey; }
  180. }
  181. /// ****************************************************************
  182. /// public BusinessEntity [constructor]
  183. /// ----------------------------------------------------------------
  184. /// <summary>
  185. /// </summary>
  186. /// ****************************************************************
  187. ///
  188. public BusinessEntity()
  189. {
  190. }
  191. /// ****************************************************************
  192. /// public BusinessEntity [constructor]
  193. /// ----------------------------------------------------------------
  194. /// <summary>
  195. /// </summary>
  196. /// ----------------------------------------------------------------
  197. /// <param name="businessKey">
  198. /// </param>
  199. /// ****************************************************************
  200. ///
  201. public BusinessEntity( string businessKey )
  202. {
  203. BusinessKey = businessKey;
  204. }
  205. /// ****************************************************************
  206. /// public Delete
  207. /// ----------------------------------------------------------------
  208. /// <summary>
  209. /// </summary>
  210. /// ****************************************************************
  211. ///
  212. public override void Delete()
  213. {
  214. Debug.Enter();
  215. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_businessEntity_delete" );
  216. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  217. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  218. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  219. sp.Parameters.SetString( "@PUID", Context.User.ID );
  220. sp.Parameters.SetGuidFromString( "@businessKey", BusinessKey );
  221. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  222. sp.ExecuteNonQuery();
  223. //
  224. // Save the change log entry.
  225. //
  226. if( Context.LogChangeRecords )
  227. {
  228. ChangeRecord changeRecord = new ChangeRecord();
  229. changeRecord.Payload = new ChangeRecordDelete( EntityType.BusinessEntity, BusinessKey );
  230. changeRecord.Log();
  231. }
  232. Debug.Leave();
  233. }
  234. /// ****************************************************************
  235. /// internal Validate
  236. /// ----------------------------------------------------------------
  237. /// <summary>
  238. /// </summary>
  239. /// ****************************************************************
  240. ///
  241. internal void Validate()
  242. {
  243. Debug.Enter();
  244. //
  245. // Check to make sure publisher's limit allows save of this
  246. // entity. If this is an update, we won't check since they are
  247. // simply replacing an existing entity. We also won't check if
  248. // the limit is 0, since this indicates unlimited publishing
  249. // rights.
  250. //
  251. int limit = Context.User.BusinessLimit;
  252. int count = Context.User.BusinessCount;
  253. if( Utility.StringEmpty( BusinessKey ) && 0 != limit )
  254. {
  255. //
  256. // Verify that the publisher has not exceeded their limit.
  257. //
  258. if( count >= limit )
  259. {
  260. throw new UDDIException( ErrorType.E_accountLimitExceeded, "UDDI_ERROR_ACCOUNTLIMITEXCEEDED_BUSINESS", limit , count );
  261. }
  262. }
  263. //
  264. // Check to see if this is an update of an existing businessEntity. If
  265. // it is, we'll need to perform further validation in the database.
  266. //
  267. if( !Utility.StringEmpty( BusinessKey ) )
  268. {
  269. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_businessEntity_validate" );
  270. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  271. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  272. sp.Parameters.Add( "@flag", SqlDbType.Int );
  273. sp.Parameters.SetString( "@PUID", Context.User.ID );
  274. sp.Parameters.SetGuidFromString( "@businessKey", BusinessKey );
  275. if( Context.User.AllowPreassignedKeys )
  276. sp.Parameters.SetInt( "@flag", 1 );
  277. else
  278. sp.Parameters.SetInt( "@flag", 0 );
  279. sp.ExecuteNonQuery();
  280. }
  281. //
  282. // Validate the contained elements.
  283. //
  284. DiscoveryUrls.Validate();
  285. Names.Validate();
  286. Descriptions.Validate();
  287. Contacts.Validate();
  288. BusinessServices.Validate( BusinessKey );
  289. IdentifierBag.Validate( BusinessKey, KeyedReferenceType.IdentifierBag );
  290. CategoryBag.Validate( BusinessKey, KeyedReferenceType.CategoryBag);
  291. Debug.Leave();
  292. }
  293. /// **********************************************************************
  294. /// public Save
  295. /// ----------------------------------------------------------------------
  296. /// <summary>
  297. /// </summary>
  298. /// **********************************************************************
  299. ///
  300. public override void Save()
  301. {
  302. Debug.Enter();
  303. //
  304. // Validate the business entity.
  305. //
  306. Validate();
  307. //
  308. // Check to see if a business key was specified. If not, this is a new
  309. // record and a business key will have to be generated.
  310. //
  311. if( Utility.StringEmpty( BusinessKey ) )
  312. BusinessKey = Guid.NewGuid().ToString();
  313. //
  314. // Save the entity to the database.
  315. //
  316. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_businessEntity_save" );
  317. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  318. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  319. sp.Parameters.Add( "@generic", SqlDbType.VarChar, UDDI.Constants.Lengths.generic );
  320. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  321. sp.Parameters.Add( "@lastChange", SqlDbType.BigInt );
  322. sp.Parameters.Add( "@authorizedName", SqlDbType.NVarChar, UDDI.Constants.Lengths.AuthorizedName, ParameterDirection.InputOutput );
  323. sp.Parameters.Add( "@operatorName", SqlDbType.NVarChar, UDDI.Constants.Lengths.Operator, ParameterDirection.InputOutput );
  324. sp.Parameters.SetGuidFromString( "@businessKey", BusinessKey );
  325. sp.Parameters.SetString( "@PUID", Context.User.ID );
  326. sp.Parameters.SetString( "@generic", Constants.Version );
  327. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  328. sp.Parameters.SetLong( "@lastChange", DateTime.UtcNow.Ticks );
  329. sp.Parameters.SetString( "@authorizedName", AuthorizedName );
  330. sp.Parameters.SetString( "@operatorName", this.Operator );
  331. //
  332. // We won't set the operatorName since this will be derived from the PUID
  333. //
  334. sp.ExecuteNonQuery();
  335. AuthorizedName = sp.Parameters.GetString( "@authorizedName" );
  336. Operator = sp.Parameters.GetString( "@operatorName" );
  337. //
  338. // Save all the contained objects.
  339. //
  340. DiscoveryUrls.Save( BusinessKey );
  341. if( Operator == Config.GetString( "Operator" ) )
  342. {
  343. //
  344. // Only add the default discovery Url to this business
  345. // If it was published at this site.
  346. //
  347. DiscoveryUrls.AddDefaultDiscoveryUrl( BusinessKey );
  348. }
  349. Names.Save( BusinessKey, EntityType.BusinessEntity );
  350. Descriptions.Save( BusinessKey, EntityType.BusinessEntity );
  351. Contacts.Save( BusinessKey );
  352. BusinessServices.Save( BusinessKey );
  353. IdentifierBag.Save( BusinessKey, EntityType.BusinessEntity, KeyedReferenceType.IdentifierBag );
  354. CategoryBag.Save( BusinessKey, EntityType.BusinessEntity, KeyedReferenceType.CategoryBag );
  355. //
  356. // Save the change log entry for replication
  357. //
  358. if( Context.LogChangeRecords )
  359. {
  360. //
  361. // If we used a V1 API message, make sure to add in language codes for the names. We will
  362. // then take these names out after we save the change record.
  363. //
  364. if( 1 == Context.ApiVersionMajor )
  365. {
  366. foreach( Name name in Names )
  367. {
  368. name.IsoLangCode = Context.User.IsoLangCode;
  369. }
  370. }
  371. ChangeRecord changeRecord = new ChangeRecord();
  372. changeRecord.Payload = new ChangeRecordNewData( this );
  373. changeRecord.Log();
  374. //
  375. // Take out language names if we are using V1.
  376. //
  377. if( 1 == Context.ApiVersionMajor )
  378. {
  379. foreach( Name name in Names )
  380. {
  381. name.IsoLangCode = null;
  382. }
  383. }
  384. }
  385. Debug.Leave();
  386. }
  387. /// ****************************************************************
  388. /// public Get
  389. /// ----------------------------------------------------------------
  390. /// <summary>
  391. /// </summary>
  392. /// ****************************************************************
  393. ///
  394. public override void Get()
  395. {
  396. Debug.Enter();
  397. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_businessEntity_get_batch" );
  398. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  399. sp.Parameters.Add( "@operatorName", SqlDbType.NVarChar, UDDI.Constants.Lengths.OperatorName, ParameterDirection.Output );
  400. sp.Parameters.Add( "@authorizedName", SqlDbType.NVarChar, UDDI.Constants.Lengths.AuthorizedName, ParameterDirection.Output );
  401. sp.Parameters.SetGuidFromString( "@businessKey", BusinessKey );
  402. SqlDataReaderAccessor reader = null;
  403. ArrayList contactIds = new ArrayList();
  404. try
  405. {
  406. //
  407. // net_businessEntity_get will return the objects contained in a business in the following order:
  408. //
  409. // - descriptions
  410. // - names
  411. // - discoveryURLs
  412. // - contacts
  413. // - identifier bags
  414. // - category bags
  415. // - services
  416. //
  417. reader = sp.ExecuteReader();
  418. //
  419. // Read the descriptions
  420. //
  421. Descriptions.Read( reader );
  422. //
  423. // Read the names
  424. //
  425. if ( true == reader.NextResult() )
  426. {
  427. Names.Read( reader );
  428. }
  429. //
  430. //
  431. // Read the discoveryURLs
  432. //
  433. if( true == reader.NextResult() )
  434. {
  435. DiscoveryUrls.Read( reader );
  436. }
  437. //
  438. // Read the contacts
  439. //
  440. if( true == reader.NextResult() )
  441. {
  442. contactIds = Contacts.Read( reader );
  443. }
  444. //
  445. // Read the identifier bags
  446. //
  447. if( true == reader.NextResult() )
  448. {
  449. IdentifierBag.Read( reader );
  450. }
  451. //
  452. // Read the category bags
  453. //
  454. if( true == reader.NextResult() )
  455. {
  456. CategoryBag.Read( reader );
  457. }
  458. //
  459. // Read the services
  460. //
  461. if( true == reader.NextResult() )
  462. {
  463. BusinessServices.Read( reader );
  464. }
  465. }
  466. finally
  467. {
  468. if( null != reader )
  469. {
  470. reader.Close();
  471. }
  472. }
  473. //
  474. // These calls will make separate sproc calls, so we have to close our reader first.
  475. //
  476. BusinessServices.Populate();
  477. Contacts.Populate( contactIds );
  478. //
  479. // Get our output parameters.
  480. //
  481. Operator = sp.Parameters.GetString( "@operatorName" );
  482. AuthorizedName = sp.Parameters.GetString( "@authorizedName" );
  483. //
  484. // If this entity was published to this node than add the
  485. // default discoveryURL.
  486. //
  487. if( Operator == Config.GetString( "Operator" ) )
  488. {
  489. //
  490. // Only add the default discovery Url to this business
  491. // if it was published at this site.
  492. //
  493. DiscoveryUrls.AddDefaultDiscoveryUrl( BusinessKey );
  494. }
  495. #if never
  496. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_businessEntity_get" );
  497. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  498. sp.Parameters.Add( "@operatorName", SqlDbType.NVarChar, UDDI.Constants.Lengths.OperatorName, ParameterDirection.Output );
  499. sp.Parameters.Add( "@authorizedName", SqlDbType.NVarChar, UDDI.Constants.Lengths.AuthorizedName, ParameterDirection.Output );
  500. sp.Parameters.SetGuidFromString( "@businessKey", BusinessKey );
  501. sp.ExecuteNonQuery();
  502. Operator = sp.Parameters.GetString( "@operatorName" );
  503. AuthorizedName = sp.Parameters.GetString( "@authorizedName" );
  504. //
  505. // Retrieve contained objects.
  506. //
  507. Descriptions.Get( BusinessKey, EntityType.BusinessEntity );
  508. Names.Get( BusinessKey, EntityType.BusinessEntity );
  509. DiscoveryUrls.Get( BusinessKey );
  510. //
  511. // If this entity was published to this node than add the
  512. // default discoveryURL.
  513. //
  514. if( Operator == Config.GetString( "Operator" ) )
  515. {
  516. //
  517. // Only add the default discovery Url to this business
  518. // if it was published at this site.
  519. //
  520. DiscoveryUrls.AddDefaultDiscoveryUrl( BusinessKey );
  521. }
  522. Contacts.Get( BusinessKey );
  523. BusinessServices.Get( BusinessKey );
  524. IdentifierBag.Get( BusinessKey, EntityType.BusinessEntity, KeyedReferenceType.IdentifierBag );
  525. CategoryBag.Get( BusinessKey, EntityType.BusinessEntity, KeyedReferenceType.CategoryBag );
  526. #endif
  527. QueryLog.Write( QueryType.Get, EntityType.BusinessEntity );
  528. Debug.Leave();
  529. }
  530. }
  531. public class BusinessInfoCollection : CollectionBase
  532. {
  533. public void GetForCurrentPublisher()
  534. {
  535. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_publisher_businessInfos_get" );
  536. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  537. sp.Parameters.SetString( "@PUID", Context.User.ID );
  538. SqlDataReaderAccessor reader = sp.ExecuteReader();
  539. try
  540. {
  541. while( reader.Read() )
  542. Add( reader.GetGuidString( "businessKey" ) );
  543. }
  544. finally
  545. {
  546. reader.Close();
  547. }
  548. foreach( BusinessInfo businessInfo in this )
  549. businessInfo.Get( true );
  550. }
  551. public BusinessInfo this[ int index ]
  552. {
  553. get { return (BusinessInfo)List[index]; }
  554. set { List[index] = value; }
  555. }
  556. public int Add()
  557. {
  558. return List.Add( new BusinessInfo() );
  559. }
  560. public int Add( string businessKey )
  561. {
  562. return List.Add( new BusinessInfo( businessKey ) );
  563. }
  564. public int Add( BusinessInfo businessInfo )
  565. {
  566. return List.Add( businessInfo );
  567. }
  568. public void Insert( int index, BusinessInfo businessInfo )
  569. {
  570. List.Insert( index, businessInfo );
  571. }
  572. public int IndexOf( BusinessInfo businessInfo )
  573. {
  574. return List.IndexOf( businessInfo );
  575. }
  576. public bool Contains( BusinessInfo businessInfo )
  577. {
  578. return List.Contains( businessInfo );
  579. }
  580. public void Remove( BusinessInfo businessInfo )
  581. {
  582. List.Remove( businessInfo );
  583. }
  584. public void CopyTo( BusinessInfo[] array, int index )
  585. {
  586. List.CopyTo( array, index );
  587. }
  588. public void Sort()
  589. {
  590. InnerList.Sort( new BusinessInfoComparer() );
  591. }
  592. internal class BusinessInfoComparer : IComparer
  593. {
  594. public int Compare( object x, object y )
  595. {
  596. BusinessInfo entity1 = (BusinessInfo)x;
  597. BusinessInfo entity2 = (BusinessInfo)y;
  598. return string.Compare( entity1.Names[ 0 ].Value, entity2.Names[ 0 ].Value, true );
  599. }
  600. }
  601. }
  602. public class BusinessEntityCollection : CollectionBase
  603. {
  604. public void Save()
  605. {
  606. foreach( BusinessEntity business in this )
  607. {
  608. business.Save();
  609. }
  610. }
  611. public BusinessEntity this[int index]
  612. {
  613. get { return (BusinessEntity)List[index]; }
  614. set { List[index] = value; }
  615. }
  616. public int Add()
  617. {
  618. return List.Add( new BusinessEntity() );
  619. }
  620. public int Add( string businessKey )
  621. {
  622. return List.Add( new BusinessEntity( businessKey ) );
  623. }
  624. public int Add( BusinessEntity value )
  625. {
  626. return List.Add( value );
  627. }
  628. public void Insert( int index, BusinessEntity value )
  629. {
  630. List.Insert( index, value );
  631. }
  632. public int IndexOf( BusinessEntity value )
  633. {
  634. return List.IndexOf( value );
  635. }
  636. public bool Contains( BusinessEntity value )
  637. {
  638. return List.Contains( value );
  639. }
  640. public void Remove( BusinessEntity value )
  641. {
  642. List.Remove( value );
  643. }
  644. public void CopyTo( BusinessEntity[] array, int index )
  645. {
  646. List.CopyTo( array, index );
  647. }
  648. public void Sort()
  649. {
  650. InnerList.Sort( new BusinessEntityComparer() );
  651. }
  652. internal class BusinessEntityComparer : IComparer
  653. {
  654. public int Compare( object x, object y )
  655. {
  656. BusinessEntity entity1 = (BusinessEntity)x;
  657. BusinessEntity entity2 = (BusinessEntity)y;
  658. return string.Compare( entity1.Names[ 0 ].Value, entity2.Names[ 0 ].Value, true );
  659. }
  660. }
  661. }
  662. public class BusinessEntityExtCollection : CollectionBase
  663. {
  664. public BusinessEntityExt this[ int index ]
  665. {
  666. get { return ( BusinessEntityExt)List[index]; }
  667. set { List[ index ] = value; }
  668. }
  669. public int Add()
  670. {
  671. return List.Add( new BusinessEntityExt() );
  672. }
  673. public int Add( BusinessEntityExt value )
  674. {
  675. return List.Add( value );
  676. }
  677. public int Add( string businessKey )
  678. {
  679. return List.Add( new BusinessEntityExt( businessKey ) );
  680. }
  681. public void Insert( int index, BusinessEntityExt value )
  682. {
  683. List.Insert( index, value );
  684. }
  685. public int IndexOf( BusinessEntityExt value )
  686. {
  687. return List.IndexOf( value );
  688. }
  689. public bool Contains( BusinessEntityExt value )
  690. {
  691. return List.Contains( value );
  692. }
  693. public void Remove( BusinessEntityExt value )
  694. {
  695. List.Remove( value );
  696. }
  697. public void CopyTo( BusinessEntityExt[] array, int index )
  698. {
  699. List.CopyTo( array, index );
  700. }
  701. }
  702. public class BusinessEntityExt
  703. {
  704. public BusinessEntityExt()
  705. {
  706. }
  707. public BusinessEntityExt( string businessKey )
  708. {
  709. BusinessEntity = new BusinessEntity( businessKey );
  710. }
  711. public void Get()
  712. {
  713. BusinessEntity.Get();
  714. }
  715. [XmlElement("businessEntity")]
  716. public BusinessEntity BusinessEntity;
  717. }
  718. public class BusinessInfo
  719. {
  720. //
  721. // Attribute: businessKey
  722. //
  723. [XmlAttribute("businessKey")]
  724. public string BusinessKey;
  725. //
  726. // Element: name
  727. //
  728. [XmlElement("name")]
  729. public NameCollection Names = new NameCollection();
  730. //
  731. // Element: description
  732. //
  733. [XmlElement("description")]
  734. public DescriptionCollection Descriptions = new DescriptionCollection();
  735. //
  736. // Element: serviceInfos
  737. //
  738. private ServiceInfoCollection serviceInfos;
  739. [ XmlArray( "serviceInfos" ), XmlArrayItem( "serviceInfo" ) ]
  740. public ServiceInfoCollection ServiceInfos
  741. {
  742. get
  743. {
  744. if( null == serviceInfos )
  745. serviceInfos = new ServiceInfoCollection();
  746. return serviceInfos;
  747. }
  748. set { serviceInfos = value; }
  749. }
  750. public BusinessInfo()
  751. {
  752. }
  753. public BusinessInfo( string businessKey )
  754. {
  755. BusinessKey = businessKey;
  756. }
  757. public void Get( bool getServiceInfos )
  758. {
  759. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_businessInfo_get_batch" );
  760. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  761. sp.Parameters.Add( "@getServiceInfos", SqlDbType.Bit );
  762. sp.Parameters.SetGuidFromString( "@businessKey", BusinessKey );
  763. sp.Parameters.SetBool( "@getServiceInfos", getServiceInfos );
  764. SqlDataReaderAccessor reader = null;
  765. ArrayList contactIds = new ArrayList();
  766. bool readServiceInfos = false;
  767. try
  768. {
  769. //
  770. // net_businessInfo_get_batch will return the objects contained in a business in the following order:
  771. //
  772. // - descriptions
  773. // - names
  774. // - serviceInfos (if specified)
  775. reader = sp.ExecuteReader();
  776. //
  777. // Read the descriptions
  778. //
  779. Descriptions.Read( reader );
  780. //
  781. // Read the names
  782. //
  783. if ( true == reader.NextResult() )
  784. {
  785. Names.Read( reader );
  786. }
  787. //
  788. // Read the service infos, maybe
  789. //
  790. if( true == getServiceInfos )
  791. {
  792. if ( true == reader.NextResult() )
  793. {
  794. ServiceInfos.Read( reader );
  795. readServiceInfos = true;
  796. }
  797. }
  798. }
  799. finally
  800. {
  801. if( null != reader )
  802. {
  803. reader.Close();
  804. }
  805. }
  806. if( true == getServiceInfos && true == readServiceInfos )
  807. {
  808. ServiceInfos.Populate();
  809. }
  810. #if never
  811. Names.Get( BusinessKey, EntityType.BusinessEntity );
  812. Descriptions.Get( BusinessKey, EntityType.BusinessEntity );
  813. if( getServiceInfos )
  814. ServiceInfos.Get( BusinessKey );
  815. #endif
  816. }
  817. }
  818. /// ****************************************************************
  819. /// class DeleteBusiness
  820. /// ----------------------------------------------------------------
  821. /// <summary>
  822. /// The DeleteBusiness class contains data and methods
  823. /// associated with the delete_business message. It is typically
  824. /// populated via deserialization by the .NET runtime as part of
  825. /// the message processing interface.
  826. ///
  827. /// As part of the publisher API, this message implements
  828. /// IAuthenticateable. This allows the enclosed authInfo to be
  829. /// authorized prior to processing
  830. /// </summary>
  831. /// ****************************************************************
  832. ///
  833. [XmlRootAttribute( "delete_business", Namespace=UDDI.API.Constants.Namespace )]
  834. public class DeleteBusiness : IAuthenticateable, IMessage
  835. {
  836. //
  837. // Attribute: generic
  838. //
  839. private string generic;
  840. [XmlAttribute("generic")]
  841. public string Generic
  842. {
  843. get { return generic; }
  844. set { generic = value; }
  845. }
  846. //
  847. // Element: authInfo
  848. //
  849. private string authInfo;
  850. [XmlElement("authInfo")]
  851. public string AuthInfo
  852. {
  853. get { return authInfo; }
  854. set { authInfo = value; }
  855. }
  856. //
  857. // Element: businessKey
  858. //
  859. [XmlElement("businessKey")]
  860. public StringCollection BusinessKeys;
  861. public DeleteBusiness()
  862. {
  863. Generic = UDDI.API.Constants.Version;
  864. }
  865. public void Delete()
  866. {
  867. foreach( string key in BusinessKeys )
  868. {
  869. BusinessEntity be = new BusinessEntity( key );
  870. be.Delete();
  871. }
  872. }
  873. }
  874. /// ********************************************************************
  875. /// public class FindBusiness
  876. /// --------------------------------------------------------------------
  877. /// <summary>
  878. /// </summary>
  879. /// ********************************************************************
  880. ///
  881. [XmlRootAttribute("find_business", Namespace=UDDI.API.Constants.Namespace)]
  882. public class FindBusiness : IMessage
  883. {
  884. //
  885. // Attribute: generic
  886. //
  887. private string generic;
  888. [XmlAttribute("generic")]
  889. public string Generic
  890. {
  891. get { return generic; }
  892. set { generic = value; }
  893. }
  894. //
  895. // Attribute: maxRows
  896. //
  897. private int maxRows = -1;
  898. [XmlAttribute( "maxRows" ), DefaultValue( -1 )]
  899. public int MaxRows
  900. {
  901. get { return maxRows; }
  902. set
  903. {
  904. if( value < 0 )
  905. {
  906. throw new UDDIException(
  907. ErrorType.E_fatalError,
  908. "UDDI_ERROR_FATALERROR_FINDBE_MAXROWSLESSTHANZERO" );
  909. }
  910. maxRows = value;
  911. }
  912. }
  913. //
  914. // Element: findQualifiers/findQualifier
  915. //
  916. [XmlArray( "findQualifiers" ), XmlArrayItem( "findQualifier" )]
  917. public FindQualifierCollection FindQualifiers = new FindQualifierCollection();
  918. //
  919. // Element: name
  920. //
  921. [XmlElement( "name" )]
  922. public NameCollection Names = new NameCollection();
  923. //
  924. // Element: identifierBag/keyedReference
  925. //
  926. [XmlArray( "identifierBag" ), XmlArrayItem( "keyedReference" ) ]
  927. public KeyedReferenceCollection IdentifierBag;
  928. //
  929. // Element: categoryBag/keyedReference
  930. //
  931. [XmlArray( "categoryBag" ), XmlArrayItem( "keyedReference" )]
  932. public KeyedReferenceCollection CategoryBag;
  933. //
  934. // Element: tModelBag/tModelKey
  935. //
  936. [XmlArray( "tModelBag" ), XmlArrayItem( "tModelKey" )]
  937. public StringCollection TModelBag;
  938. //
  939. // Element: discoveryURLs/discoveryURL
  940. //
  941. [XmlArray( "discoveryURLs" ), XmlArrayItem( "discoveryURL" )]
  942. public DiscoveryUrlCollection DiscoveryUrls;
  943. public BusinessList Find()
  944. {
  945. BusinessList businessList = new BusinessList();
  946. QueryLog.Write( QueryType.Find, EntityType.BusinessEntity );
  947. //
  948. // Process each find constraint.
  949. //
  950. FindBuilder find = new FindBuilder( EntityType.BusinessEntity, FindQualifiers );
  951. //
  952. // If no search arguments are specified, return an empty result
  953. // set.
  954. //
  955. if( Utility.CollectionEmpty( Names ) &&
  956. Utility.CollectionEmpty( DiscoveryUrls ) &&
  957. Utility.CollectionEmpty( IdentifierBag ) &&
  958. Utility.CollectionEmpty( CategoryBag ) &&
  959. Utility.CollectionEmpty( TModelBag ) )
  960. return businessList;
  961. //
  962. // Validate find parameters.
  963. //
  964. if( !Utility.CollectionEmpty( Names ) )
  965. {
  966. Names.ValidateForFind();
  967. }
  968. else
  969. {
  970. Debug.Verify( !find.CaseSensitiveMatch && !find.ExactNameMatch,
  971. "UDDI_ERROR_UNSUPPORTED_FINDBE_NAMEFQNONAMES", ErrorType.E_unsupported );
  972. }
  973. //
  974. // TODO: Override may be better for these calls to KeyedReference.Validate because no parent key is used
  975. //
  976. if( !Utility.CollectionEmpty( IdentifierBag ) )
  977. IdentifierBag.Validate( "", KeyedReferenceType.IdentifierBag );
  978. if( !Utility.CollectionEmpty( CategoryBag ) )
  979. CategoryBag.Validate( "", KeyedReferenceType.CategoryBag );
  980. try
  981. {
  982. int rows = 1;
  983. //
  984. // Find entities with matching identifier bag items.
  985. //
  986. if( !Utility.CollectionEmpty( IdentifierBag ) )
  987. rows = find.FindByKeyedReferences( KeyedReferenceType.IdentifierBag, IdentifierBag );
  988. //
  989. // Find entities with matching category bag items.
  990. //
  991. if( rows > 0 && !Utility.CollectionEmpty( CategoryBag ) )
  992. rows = find.FindByKeyedReferences( KeyedReferenceType.CategoryBag, CategoryBag );
  993. //
  994. // Find entities with matching TModel bag items.
  995. //
  996. if( rows > 0 && !Utility.CollectionEmpty( TModelBag ) )
  997. rows = find.FindByTModelBag( TModelBag );
  998. //
  999. // Find entities with matching discovery URLs
  1000. //
  1001. if( rows > 0 && !Utility.CollectionEmpty( DiscoveryUrls ) )
  1002. rows = find.FindByDiscoveryUrls( DiscoveryUrls );
  1003. //
  1004. // Find entities with matching names
  1005. //
  1006. if( rows > 0 && !Utility.CollectionEmpty( Names ) )
  1007. rows = find.FindByNames( Names );
  1008. //
  1009. // Process the find result set.
  1010. //
  1011. if( 0 == rows )
  1012. {
  1013. //
  1014. // Cleanup any temporary tables.
  1015. //
  1016. find.Abort();
  1017. } // TODO: review
  1018. else if( 0 == MaxRows )
  1019. {
  1020. businessList.Truncated = Truncated.True;
  1021. return businessList;
  1022. }
  1023. else
  1024. {
  1025. //
  1026. // Read in the find results.
  1027. //
  1028. SqlDataReaderAccessor reader;
  1029. SqlStoredProcedureAccessor sp;
  1030. sp = find.RetrieveResults( MaxRows);
  1031. //
  1032. // TODO: return reader, not the whole SPA
  1033. //
  1034. reader = sp.ExecuteReader();
  1035. try
  1036. {
  1037. if( find.ServiceSubset )
  1038. {
  1039. //
  1040. // For a service subset search, we limit the result set
  1041. // to those services that matched the category bag
  1042. // search criteria.
  1043. //
  1044. BusinessInfo businessInfo = null;
  1045. string prevKey = null;
  1046. while( reader.Read() )
  1047. {
  1048. string businessKey = reader.GetString( "entityKey" );
  1049. if( prevKey != businessKey )
  1050. {
  1051. businessInfo = new BusinessInfo( businessKey );
  1052. businessList.BusinessInfos.Add( businessInfo );
  1053. }
  1054. businessInfo.ServiceInfos.Add(
  1055. reader.GetString( "subEntityKey" ),
  1056. businessKey );
  1057. prevKey = businessKey;
  1058. }
  1059. }
  1060. else
  1061. {
  1062. //
  1063. // For non-service subset searches, we will simply
  1064. // return a list of businesses with all services.
  1065. //
  1066. while( reader.Read() )
  1067. businessList.BusinessInfos.Add( reader.GetString( "entityKey" ) );
  1068. }
  1069. }
  1070. finally
  1071. {
  1072. reader.Close();
  1073. }
  1074. if( sp.Parameters.GetBool( "@truncated" ) )
  1075. businessList.Truncated = Truncated.True;
  1076. else
  1077. businessList.Truncated = Truncated.False;
  1078. //
  1079. // Get the actual business info and service info data. For
  1080. // a service subset, we'll grab just those services that we
  1081. // populated. For all other searches, we'll get all service
  1082. // infos.
  1083. //
  1084. if( find.ServiceSubset )
  1085. {
  1086. foreach( BusinessInfo businessInfo in businessList.BusinessInfos )
  1087. {
  1088. businessInfo.Get( false );
  1089. foreach( ServiceInfo serviceInfo in businessInfo.ServiceInfos )
  1090. serviceInfo.Get();
  1091. }
  1092. }
  1093. else
  1094. {
  1095. foreach( BusinessInfo businessInfo in businessList.BusinessInfos )
  1096. businessInfo.Get( true );
  1097. }
  1098. }
  1099. }
  1100. catch( Exception )
  1101. {
  1102. find.Abort();
  1103. throw;
  1104. }
  1105. return businessList;
  1106. }
  1107. }
  1108. /// ********************************************************************
  1109. /// public class GetBusinessDetail
  1110. /// --------------------------------------------------------------------
  1111. /// <summary>
  1112. /// </summary>
  1113. /// ********************************************************************
  1114. ///
  1115. [XmlRootAttribute( "get_businessDetail", Namespace=UDDI.API.Constants.Namespace )]
  1116. public class GetBusinessDetail : IMessage
  1117. {
  1118. //
  1119. // Attribute: generic
  1120. //
  1121. private string generic;
  1122. [XmlAttribute("generic")]
  1123. public string Generic
  1124. {
  1125. get { return generic; }
  1126. set { generic = value; }
  1127. }
  1128. //
  1129. // Element: businessKey
  1130. //
  1131. [XmlElement("businessKey")]
  1132. public StringCollection BusinessKeys;
  1133. public GetBusinessDetail()
  1134. {
  1135. Generic = UDDI.API.Constants.Version;
  1136. }
  1137. }
  1138. [XmlRootAttribute("businessDetail", Namespace=UDDI.API.Constants.Namespace)]
  1139. public class BusinessDetail
  1140. {
  1141. [XmlAttribute("generic")]
  1142. public string Generic = UDDI.API.Constants.Version;
  1143. [XmlAttribute("operator")]
  1144. public string Operator = Config.GetString( "Operator" );
  1145. [XmlAttribute("truncated")]
  1146. public Truncated Truncated;
  1147. [XmlElement("businessEntity")]
  1148. public BusinessEntityCollection BusinessEntities = new BusinessEntityCollection();
  1149. public void Get( StringCollection businessKeys )
  1150. {
  1151. int n = 0;
  1152. foreach( string key in businessKeys )
  1153. {
  1154. n = BusinessEntities.Add( key );
  1155. BusinessEntities[ n ].Get();
  1156. }
  1157. }
  1158. }
  1159. /// ********************************************************************
  1160. /// public class SaveBusiness
  1161. /// --------------------------------------------------------------------
  1162. /// <summary>
  1163. /// </summary>
  1164. /// ********************************************************************
  1165. ///
  1166. [XmlRootAttribute( "save_business", Namespace=UDDI.API.Constants.Namespace )]
  1167. public class SaveBusiness : IAuthenticateable, IMessage
  1168. {
  1169. //
  1170. // Attribute: generic
  1171. //
  1172. private string generic;
  1173. [XmlAttribute("generic")]
  1174. public string Generic
  1175. {
  1176. get { return generic; }
  1177. set { generic = value; }
  1178. }
  1179. //
  1180. // Element: authInfo
  1181. //
  1182. private string authInfo;
  1183. [XmlElement("authInfo")]
  1184. public string AuthInfo
  1185. {
  1186. get { return authInfo; }
  1187. set { authInfo = value; }
  1188. }
  1189. //
  1190. // Element: businessEntity
  1191. //
  1192. [XmlElement("businessEntity")]
  1193. public BusinessEntityCollection BusinessEntities;
  1194. //
  1195. // Element: uploadRegister
  1196. //
  1197. [XmlElement("uploadRegister")]
  1198. public StringCollection UploadRegisters;
  1199. /// ****************************************************************
  1200. /// public Save
  1201. /// ----------------------------------------------------------------
  1202. /// <summary>
  1203. /// </summary>
  1204. /// ****************************************************************
  1205. ///
  1206. public void Save()
  1207. {
  1208. //
  1209. // This is outside of replication so any attempt to specify
  1210. // an upload register URL will force an E_unsupported response
  1211. //
  1212. if( 0 != UploadRegisters.Count )
  1213. throw new UDDIException( ErrorType.E_unsupported, "UDDI_ERROR_UNSUPPORTED_UPLOADREGISTER" );
  1214. BusinessEntities.Save();
  1215. }
  1216. }
  1217. /// ********************************************************************
  1218. /// public class GetBusinessDetailExt
  1219. /// --------------------------------------------------------------------
  1220. /// <summary>
  1221. /// </summary>
  1222. /// ********************************************************************
  1223. ///
  1224. [XmlRootAttribute( "get_businessDetailExt", Namespace=UDDI.API.Constants.Namespace )]
  1225. public class GetBusinessDetailExt : IMessage
  1226. {
  1227. //
  1228. // Attribute: generic
  1229. //
  1230. private string generic;
  1231. [XmlAttribute("generic")]
  1232. public string Generic
  1233. {
  1234. get { return generic; }
  1235. set { generic = value; }
  1236. }
  1237. //
  1238. // Element: businessKey
  1239. //
  1240. [XmlElement("businessKey")]
  1241. public StringCollection BusinessKeys;
  1242. public GetBusinessDetailExt()
  1243. {
  1244. }
  1245. }
  1246. [XmlRootAttribute("businessDetailExt", Namespace=UDDI.API.Constants.Namespace)]
  1247. public class BusinessDetailExt
  1248. {
  1249. [XmlAttribute("generic")]
  1250. public string Generic = UDDI.API.Constants.Version;
  1251. [XmlAttribute("operator")]
  1252. public string Operator = Config.GetString( "Operator" );
  1253. [XmlAttribute("truncated")]
  1254. public Truncated Truncated;
  1255. [XmlElement("businessEntityExt")]
  1256. public BusinessEntityExtCollection BusinessEntityExts = new BusinessEntityExtCollection();
  1257. public void Get( StringCollection businessKeys )
  1258. {
  1259. int n = 0;
  1260. foreach( string key in businessKeys )
  1261. {
  1262. n = BusinessEntityExts.Add( key );
  1263. BusinessEntityExts[ n ].Get();
  1264. }
  1265. }
  1266. }
  1267. [XmlRootAttribute("businessList", Namespace=UDDI.API.Constants.Namespace)]
  1268. public class BusinessList
  1269. {
  1270. //
  1271. // Attribute: generic
  1272. //
  1273. [XmlAttribute("generic")]
  1274. public string Generic = UDDI.API.Constants.Version;
  1275. //
  1276. // Attribute: operator
  1277. //
  1278. [XmlAttribute("operator")]
  1279. public string Operator = Config.GetString( "Operator" );
  1280. //
  1281. // Attribute: truncated
  1282. //
  1283. [XmlAttribute("truncated")]
  1284. public Truncated Truncated;
  1285. //
  1286. // Element: businessInfos
  1287. //
  1288. private BusinessInfoCollection businessInfos;
  1289. [ XmlArray( "businessInfos" ), XmlArrayItem( "businessInfo" ) ]
  1290. public BusinessInfoCollection BusinessInfos
  1291. {
  1292. get
  1293. {
  1294. if( null == businessInfos )
  1295. businessInfos = new BusinessInfoCollection();
  1296. return businessInfos;
  1297. }
  1298. set { businessInfos = value; }
  1299. }
  1300. }
  1301. }