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.

612 lines
15 KiB

  1. /// ************************************************************************
  2. /// Microsoft UDDI version 2.0
  3. /// Copyright (c) 2000-2001 Microsoft Corporation
  4. /// All Rights Reserved
  5. /// ------------------------------------------------------------------------
  6. /// <summary>
  7. /// </summary>
  8. /// ************************************************************************
  9. ///
  10. using System;
  11. using System.Data;
  12. using System.Collections;
  13. using System.Data.SqlClient;
  14. using System.Xml.Serialization;
  15. using UDDI;
  16. using UDDI.Diagnostics;
  17. namespace UDDI.API.Business
  18. {
  19. /// ********************************************************************
  20. /// public class Address
  21. /// --------------------------------------------------------------------
  22. /// <summary>
  23. /// </summary>
  24. /// ********************************************************************
  25. ///
  26. public class Address
  27. {
  28. //
  29. // Attribute: useType
  30. //
  31. [XmlAttribute( "sortCode" )]
  32. public string SortCode;
  33. //
  34. // Attribute: useType
  35. //
  36. [XmlAttribute( "useType" )]
  37. public string UseType;
  38. //
  39. // Attribute: tModelKey
  40. //
  41. [XmlAttribute( "tModelKey" )]
  42. public string TModelKey;
  43. //
  44. // Element: addressLines
  45. //
  46. private AddressLineCollection addressLines;
  47. [XmlElement( "addressLine" )]
  48. public AddressLineCollection AddressLines
  49. {
  50. get
  51. {
  52. if( null == addressLines )
  53. addressLines = new AddressLineCollection();
  54. return addressLines;
  55. }
  56. set { addressLines = value; }
  57. }
  58. /// ****************************************************************
  59. /// public Address [constructor]
  60. /// ----------------------------------------------------------------
  61. /// <summary>
  62. /// </summary>
  63. /// ****************************************************************
  64. ///
  65. public Address()
  66. {
  67. }
  68. /// ****************************************************************
  69. /// public Address [constructor]
  70. /// ----------------------------------------------------------------
  71. /// <summary>
  72. /// </summary>
  73. /// ----------------------------------------------------------------
  74. /// <param name="sortCode">
  75. /// </param>
  76. ///
  77. /// <param name="useType">
  78. /// </param>
  79. ///
  80. /// <param name="tModelKey">
  81. /// </param>
  82. /// ****************************************************************
  83. ///
  84. public Address( string sortCode, string useType, string tModelKey )
  85. {
  86. this.SortCode = sortCode;
  87. this.UseType = useType;
  88. this.TModelKey = tModelKey;
  89. }
  90. /// ****************************************************************
  91. /// public Address [constructor]
  92. /// ----------------------------------------------------------------
  93. /// <summary>
  94. /// </summary>
  95. /// ----------------------------------------------------------------
  96. /// <param name="sortCode">
  97. /// </param>
  98. ///
  99. /// <param name="useType">
  100. /// </param>
  101. /// ****************************************************************
  102. ///
  103. public Address( string sortCode, string useType )
  104. : this( sortCode, useType, null )
  105. {
  106. }
  107. internal void Validate()
  108. {
  109. Debug.Enter();
  110. Utility.ValidateLength( ref UseType, "useType", UDDI.Constants.Lengths.UseType );
  111. Utility.ValidateLength( ref SortCode, "sortCode", UDDI.Constants.Lengths.SortCode );
  112. Utility.ValidateLength( ref TModelKey, "tModelKey", UDDI.Constants.Lengths.TModelKey );
  113. //
  114. // Verify that if the address is adorned with a tModelKey, each
  115. // of the address lines specifies a key name and value.
  116. //
  117. if( null != TModelKey )
  118. {
  119. if( Utility.StringEmpty( TModelKey ) )
  120. {
  121. //
  122. // trying to save a business with empty tModelKey attribute
  123. // in the address element should return E_invalidKeyPassed
  124. //
  125. throw new UDDIException(
  126. ErrorType.E_invalidKeyPassed,
  127. "UDDI_ERROR_INVALIDKEYPASSED_ADDRESS_BLANKTMODELKEY" );
  128. }
  129. else
  130. {
  131. foreach( AddressLine addressLine in AddressLines )
  132. {
  133. if( Utility.StringEmpty( addressLine.KeyName ) ||
  134. Utility.StringEmpty( addressLine.KeyValue ) )
  135. {
  136. throw new UDDIException(
  137. ErrorType.E_fatalError,
  138. "UDDI_ERROR_FATALERROR_ADDRESS_MISSINGKEYNAMEKEYVALUE" );
  139. }
  140. }
  141. //
  142. // call net_key_validate
  143. //
  144. SqlCommand cmd = new SqlCommand( "net_key_validate", ConnectionManager.GetConnection() );
  145. cmd.Transaction = ConnectionManager.GetTransaction();
  146. cmd.CommandType = CommandType.StoredProcedure;
  147. cmd.Parameters.Add( new SqlParameter( "@entityTypeID", SqlDbType.TinyInt ) ).Direction = ParameterDirection.Input;
  148. cmd.Parameters.Add( new SqlParameter( "@entityKey", SqlDbType.UniqueIdentifier ) ).Direction = ParameterDirection.Input;
  149. SqlParameterAccessor paramacc = new SqlParameterAccessor( cmd.Parameters );
  150. //
  151. // TODO: Need enumeration for the entityTypeID
  152. //
  153. paramacc.SetInt( "@entityTypeID", 0 );
  154. paramacc.SetGuidFromKey( "@entityKey", TModelKey );
  155. cmd.ExecuteNonQuery();
  156. }
  157. }
  158. AddressLines.Validate();
  159. Debug.Leave();
  160. }
  161. public void Get( long addressID )
  162. {
  163. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  164. sp.ProcedureName = "net_address_addressLines_get";
  165. sp.Parameters.Add( "@addressID", SqlDbType.BigInt );
  166. sp.Parameters.SetLong( "@addressID", addressID );
  167. //
  168. // Run the stored procedure
  169. //
  170. SqlDataReaderAccessor reader = sp.ExecuteReader();
  171. try
  172. {
  173. if( 1 == Context.ApiVersionMajor )
  174. {
  175. while( reader.Read() )
  176. AddressLines.Add( reader.GetString( "addressLine" ) );
  177. }
  178. else
  179. {
  180. while( reader.Read() )
  181. {
  182. AddressLines.Add(
  183. reader.GetString( "addressLine" ),
  184. reader.GetString( "keyName" ),
  185. reader.GetString( "keyValue" ) );
  186. }
  187. }
  188. }
  189. finally
  190. {
  191. reader.Close();
  192. }
  193. }
  194. public void Save( long contactID )
  195. {
  196. Debug.Enter();
  197. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  198. sp.ProcedureName = "net_contact_address_save";
  199. sp.Parameters.Add( "@contactID", SqlDbType.BigInt );
  200. sp.Parameters.Add( "@sortCode", SqlDbType.NVarChar, UDDI.Constants.Lengths.SortCode );
  201. sp.Parameters.Add( "@useType", SqlDbType.NVarChar, UDDI.Constants.Lengths.UseType );
  202. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  203. sp.Parameters.Add( "@addressID", SqlDbType.BigInt, ParameterDirection.Output );
  204. sp.Parameters.SetLong( "@contactID", contactID );
  205. sp.Parameters.SetString( "@sortCode", SortCode );
  206. sp.Parameters.SetString( "@useType", UseType );
  207. sp.Parameters.SetGuidFromKey( "@tModelKey", TModelKey );
  208. sp.ExecuteNonQuery();
  209. long addressID = sp.Parameters.GetLong( "@addressID" );
  210. //
  211. // Call save on individual address line instances
  212. //
  213. AddressLines.Save( addressID );
  214. Debug.Leave();
  215. }
  216. }
  217. /// ********************************************************************
  218. /// public class AddressCollection
  219. /// --------------------------------------------------------------------
  220. /// <summary>
  221. /// </summary>
  222. /// ********************************************************************
  223. ///
  224. public class AddressCollection : CollectionBase
  225. {
  226. internal void Validate()
  227. {
  228. //
  229. // Walk collection and call Validate on individual address
  230. // instances.
  231. //
  232. foreach( Address address in this )
  233. address.Validate();
  234. }
  235. public void Save( long contactID )
  236. {
  237. //
  238. // Walk collection and call save on individual address
  239. // instances.
  240. //
  241. foreach( Address address in this )
  242. address.Save( contactID );
  243. }
  244. public void Get( long contactID )
  245. {
  246. ArrayList addressIDs = new ArrayList();
  247. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_contact_addresses_get" );
  248. sp.Parameters.Add( "@contactID", SqlDbType.BigInt );
  249. sp.Parameters.SetLong( "@contactID", contactID );
  250. SqlDataReaderAccessor reader = sp.ExecuteReader();
  251. try
  252. {
  253. addressIDs = Read( reader );
  254. }
  255. finally
  256. {
  257. reader.Close();
  258. }
  259. Populate( addressIDs );
  260. #if never
  261. ArrayList addressIDs = new ArrayList();
  262. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  263. sp.ProcedureName = "net_contact_addresses_get";
  264. sp.Parameters.Add( "@contactID", SqlDbType.BigInt );
  265. sp.Parameters.SetLong( "@contactID", contactID );
  266. SqlDataReaderAccessor reader = sp.ExecuteReader();
  267. try
  268. {
  269. if( 1 == Context.ApiVersionMajor )
  270. {
  271. while( reader.Read() )
  272. {
  273. addressIDs.Add( reader.GetLong( "addressID" ) );
  274. Add( reader.GetString( "sortCode" ), reader.GetString( "useType" ) );
  275. }
  276. }
  277. else
  278. {
  279. while( reader.Read() )
  280. {
  281. addressIDs.Add( reader.GetLong( "addressID" ) );
  282. Add( reader.GetString( "sortCode" ), reader.GetString( "useType" ), reader.GetKeyFromGuid( "tModelKey" ) );
  283. }
  284. }
  285. }
  286. finally
  287. {
  288. reader.Close();
  289. }
  290. //
  291. // Retrieve the addressLines for this address
  292. //
  293. int index = 0;
  294. foreach( Address address in this )
  295. {
  296. address.Get( (long)addressIDs[ index ] );
  297. index ++;
  298. }
  299. #endif
  300. }
  301. public ArrayList Read( SqlDataReaderAccessor reader )
  302. {
  303. ArrayList addressIDs = new ArrayList();
  304. if( 1 == Context.ApiVersionMajor )
  305. {
  306. while( reader.Read() )
  307. {
  308. addressIDs.Add( reader.GetLong( "addressID" ) );
  309. Add( reader.GetString( "sortCode" ), reader.GetString( "useType" ) );
  310. }
  311. }
  312. else
  313. {
  314. while( reader.Read() )
  315. {
  316. addressIDs.Add( reader.GetLong( "addressID" ) );
  317. Add( reader.GetString( "sortCode" ), reader.GetString( "useType" ), reader.GetKeyFromGuid( "tModelKey" ) );
  318. }
  319. }
  320. return addressIDs;
  321. }
  322. public void Populate( ArrayList addressIDs )
  323. {
  324. //
  325. // Retrieve the addressLines for this address
  326. //
  327. int index = 0;
  328. foreach( Address address in this )
  329. {
  330. address.Get( (long)addressIDs[ index ] );
  331. index ++;
  332. }
  333. }
  334. public Address this[ int index ]
  335. {
  336. get
  337. { return ( Address)List[index]; }
  338. set
  339. { List[ index ] = value; }
  340. }
  341. public int Add( string sortCode, string useType )
  342. {
  343. return List.Add( new Address( sortCode, useType ) );
  344. }
  345. public int Add( string sortCode, string useType, string tModelKey )
  346. {
  347. return List.Add( new Address( sortCode, useType, tModelKey ) );
  348. }
  349. public int Add( Address value )
  350. {
  351. return List.Add( value );
  352. }
  353. public void Insert( int index, Address value )
  354. {
  355. List.Insert( index, value );
  356. }
  357. public int IndexOf( Address value )
  358. {
  359. return List.IndexOf( value );
  360. }
  361. public bool Contains( Address value )
  362. {
  363. return List.Contains( value );
  364. }
  365. public void Remove( Address value )
  366. {
  367. List.Remove( value );
  368. }
  369. public void CopyTo( Address[] array, int index )
  370. {
  371. List.CopyTo( array, index );
  372. }
  373. }
  374. /// ********************************************************************
  375. /// public class AddressLine
  376. /// --------------------------------------------------------------------
  377. /// <summary>
  378. /// </summary>
  379. /// ********************************************************************
  380. ///
  381. public class AddressLine
  382. {
  383. //
  384. // Attribute: keyName
  385. //
  386. [XmlAttribute( "keyName" )]
  387. public string KeyName;
  388. //
  389. // Attribute: keyValue
  390. //
  391. [XmlAttribute( "keyValue" )]
  392. public string KeyValue;
  393. //
  394. // InnerText
  395. //
  396. [XmlText]
  397. public string Value;
  398. public AddressLine()
  399. {
  400. }
  401. public AddressLine( string addressLine )
  402. : this( addressLine, null, null )
  403. {
  404. }
  405. public AddressLine( string addressLine, string keyName, string keyValue )
  406. {
  407. this.Value = addressLine;
  408. this.KeyName = keyName;
  409. this.KeyValue = keyValue;
  410. }
  411. internal void Validate()
  412. {
  413. Utility.ValidateLength( ref Value, "addressLine", UDDI.Constants.Lengths.AddressLine );
  414. Utility.ValidateLength( ref KeyName, "keyName", UDDI.Constants.Lengths.KeyName );
  415. Utility.ValidateLength( ref KeyValue, "keyValue", UDDI.Constants.Lengths.KeyValue );
  416. }
  417. public void Save( long addressID )
  418. {
  419. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  420. sp.ProcedureName = "net_address_addressLine_save";
  421. sp.Parameters.Add( "@addressID", SqlDbType.BigInt );
  422. sp.Parameters.Add( "@addressLine", SqlDbType.NVarChar, UDDI.Constants.Lengths.AddressLine );
  423. sp.Parameters.Add( "@keyName", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyName );
  424. sp.Parameters.Add( "@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue );
  425. sp.Parameters.SetLong( "@addressID", addressID );
  426. sp.Parameters.SetString( "@addressLine", Value );
  427. sp.Parameters.SetString( "@keyName", KeyName );
  428. sp.Parameters.SetString( "@keyValue", KeyValue );
  429. sp.ExecuteNonQuery();
  430. }
  431. }
  432. /// ********************************************************************
  433. /// public class AddressLineCollection
  434. /// --------------------------------------------------------------------
  435. /// <summary>
  436. /// </summary>
  437. /// ********************************************************************
  438. ///
  439. public class AddressLineCollection : CollectionBase
  440. {
  441. internal void Validate()
  442. {
  443. //
  444. // Walk the collection and call Validate on each individual
  445. // address line.
  446. //
  447. foreach( AddressLine addressLine in this )
  448. addressLine.Validate();
  449. }
  450. public void Save( long addressID )
  451. {
  452. //
  453. // Walk the collection and save each individual address
  454. // line.
  455. //
  456. foreach( AddressLine addressLine in this )
  457. addressLine.Save( addressID );
  458. }
  459. public void Get( long addressID )
  460. {
  461. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  462. sp.ProcedureName = "net_address_addressLines_get";
  463. sp.Parameters.Add( "@addressID", SqlDbType.BigInt );
  464. sp.Parameters.SetLong( "@addressID", addressID );
  465. SqlDataReaderAccessor reader = sp.ExecuteReader();
  466. try
  467. {
  468. while( reader.Read() )
  469. {
  470. Add(
  471. reader.GetString( "addressLine" ),
  472. reader.GetString( "keyName" ),
  473. reader.GetString( "keyValue" ) );
  474. }
  475. }
  476. finally
  477. {
  478. reader.Close();
  479. }
  480. }
  481. public AddressLine this[ int index ]
  482. {
  483. get
  484. { return (AddressLine)List[index]; }
  485. set
  486. { List[ index ] = value; }
  487. }
  488. public int Add( string addressLine, string keyName, string keyValue )
  489. {
  490. return List.Add( new AddressLine( addressLine, keyName, keyValue ) );
  491. }
  492. public int Add( string addressLine )
  493. {
  494. return List.Add( new AddressLine( addressLine ) );
  495. }
  496. public int Add( AddressLine addressLine )
  497. {
  498. return List.Add( addressLine );
  499. }
  500. public void Insert( int index, AddressLine addressLine )
  501. {
  502. List.Insert( index, addressLine );
  503. }
  504. public int IndexOf( AddressLine addressLine )
  505. {
  506. return List.IndexOf( addressLine );
  507. }
  508. public bool Contains( AddressLine addressLine )
  509. {
  510. return List.Contains( addressLine );
  511. }
  512. public void Remove( AddressLine addressLine )
  513. {
  514. List.Remove( addressLine );
  515. }
  516. public void CopyTo( AddressLine[] array, int index )
  517. {
  518. List.CopyTo( array, index );
  519. }
  520. }
  521. }