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.

183 lines
4.1 KiB

  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using System.Diagnostics;
  5. using System.Data.SqlClient;
  6. using System.Xml.Serialization;
  7. using UDDI;
  8. namespace UDDI.API.Business
  9. {
  10. public class Email
  11. {
  12. [XmlAttribute("useType")]
  13. public string UseType;
  14. [XmlText()]
  15. public string Value;
  16. public Email()
  17. {
  18. }
  19. public Email( string email, string useType )
  20. {
  21. Value = email;
  22. UseType = useType;
  23. }
  24. internal void Validate()
  25. {
  26. Utility.ValidateLength( ref UseType, "useType", UDDI.Constants.Lengths.UseType );
  27. Utility.ValidateLength( ref Value, "email", UDDI.Constants.Lengths.Email );
  28. }
  29. public void Save( long contactID )
  30. {
  31. //
  32. // Create a command object to invoke the stored procedure
  33. //
  34. SqlCommand cmd = new SqlCommand( "net_contact_email_save", ConnectionManager.GetConnection() );
  35. cmd.Transaction = ConnectionManager.GetTransaction();
  36. cmd.CommandType = CommandType.StoredProcedure;
  37. //
  38. // Input parameters
  39. //
  40. cmd.Parameters.Add( new SqlParameter( "@contactID", SqlDbType.BigInt ) ).Direction = ParameterDirection.Input;
  41. cmd.Parameters.Add( new SqlParameter( "@email", SqlDbType.NVarChar, UDDI.Constants.Lengths.Email ) ).Direction = ParameterDirection.Input;
  42. cmd.Parameters.Add( new SqlParameter( "@useType", SqlDbType.NVarChar, UDDI.Constants.Lengths.UseType ) ).Direction = ParameterDirection.Input;
  43. //
  44. // Set parameter values
  45. //
  46. SqlParameterAccessor parmacc = new SqlParameterAccessor( cmd.Parameters );
  47. parmacc.SetLong( "@contactID", contactID );
  48. parmacc.SetString( "@email", Value );
  49. parmacc.SetString( "@useType", UseType );
  50. cmd.ExecuteNonQuery();
  51. }
  52. }
  53. public class EmailCollection : CollectionBase
  54. {
  55. internal void Validate()
  56. {
  57. foreach( Email email in this)
  58. {
  59. email.Validate();
  60. }
  61. }
  62. public void Save( long contactID )
  63. {
  64. //
  65. // Walk collection and call save on individual contact instances
  66. //
  67. foreach( Email email in this)
  68. email.Save( contactID );
  69. }
  70. public void Get( long contactID )
  71. {
  72. //
  73. // Create a command object to invoke the stored procedure net_get_contacts
  74. //
  75. SqlStoredProcedureAccessor cmd = new SqlStoredProcedureAccessor( "net_contact_emails_get" );
  76. //
  77. // Add parameters and set values
  78. //
  79. cmd.Parameters.Add( "@contactID", SqlDbType.BigInt, ParameterDirection.Input );
  80. cmd.Parameters.SetLong( "@contactID", contactID );
  81. //
  82. // Run the stored procedure
  83. //
  84. SqlDataReaderAccessor reader = cmd.ExecuteReader();
  85. try
  86. {
  87. #if never
  88. while( reader.Read() )
  89. {
  90. //
  91. // Construct a new Email from the data in this row
  92. //
  93. this.Add( dracc.GetString( EmailIndex ), dracc.GetString( UseTypeIndex ) );
  94. }
  95. #endif
  96. }
  97. finally
  98. {
  99. reader.Close();
  100. }
  101. }
  102. public void Read( SqlDataReaderAccessor reader )
  103. {
  104. const int UseTypeIndex = 0;
  105. const int EmailIndex = 1;
  106. while( reader.Read() )
  107. {
  108. //
  109. // Construct a new Email from the data in this row
  110. //
  111. this.Add( reader.GetString( EmailIndex ), reader.GetString( UseTypeIndex ) );
  112. }
  113. }
  114. public Email this[ int index ]
  115. {
  116. get { return (Email)List[index]; }
  117. set { List[ index ] = value; }
  118. }
  119. public int Add()
  120. {
  121. return List.Add( new Email() );
  122. }
  123. public int Add( Email emailObject )
  124. {
  125. return List.Add( emailObject );
  126. }
  127. public int Add( string email )
  128. {
  129. return ( Add( email, null ) );
  130. }
  131. public int Add( string email, string useType )
  132. {
  133. return List.Add( new Email( email, useType ) );
  134. }
  135. public void Insert( int index, Email value )
  136. {
  137. List.Insert( index, value );
  138. }
  139. public int IndexOf( Email value )
  140. {
  141. return List.IndexOf( value );
  142. }
  143. public bool Contains( Email value )
  144. {
  145. return List.Contains( value );
  146. }
  147. public void Remove( Email value )
  148. {
  149. List.Remove( value );
  150. }
  151. public void CopyTo( Email[] array, int index )
  152. {
  153. List.CopyTo( array, index );
  154. }
  155. }
  156. }