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.

465 lines
12 KiB

  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using System.Data.SqlClient;
  5. using System.Xml.Serialization;
  6. using UDDI;
  7. using UDDI.Diagnostics;
  8. namespace UDDI.API
  9. {
  10. public class Description
  11. {
  12. //
  13. // Attribute: xml:lang
  14. //
  15. private string isoLangCode;
  16. [XmlAttribute("xml:lang")]
  17. public string IsoLangCode
  18. {
  19. get { return isoLangCode; }
  20. set { isoLangCode = value; }
  21. }
  22. //
  23. // Text
  24. //
  25. [XmlText]
  26. public string Value;
  27. public Description()
  28. {
  29. }
  30. //
  31. // 741019 - use the UDDI site language if one is not specified.
  32. //
  33. public Description( string description ) : this( Config.GetString( "Setup.WebServer.ProductLanguage", "en" ) , description )
  34. {
  35. }
  36. public Description( string isoLangCode, string description )
  37. {
  38. IsoLangCode = isoLangCode;
  39. Value = description;
  40. }
  41. public void Save( long parentID, EntityType parentType )
  42. {
  43. Debug.Enter();
  44. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  45. switch( parentType )
  46. {
  47. case EntityType.Contact:
  48. sp.ProcedureName = "net_contact_description_save";
  49. sp.Parameters.Add( "@contactID", SqlDbType.BigInt );
  50. sp.Parameters.SetLong( "@contactID", parentID );
  51. break;
  52. case EntityType.TModelInstanceInfo:
  53. sp.ProcedureName = "net_bindingTemplate_tModelInstanceInfo_description_save";
  54. sp.Parameters.Add( "@instanceID", SqlDbType.BigInt );
  55. sp.Parameters.SetLong( "@instanceID", parentID );
  56. break;
  57. case EntityType.InstanceDetail:
  58. sp.ProcedureName = "net_bindingTemplate_instanceDetails_description_save";
  59. sp.Parameters.Add( "@instanceID", SqlDbType.BigInt );
  60. sp.Parameters.SetLong( "@instanceID", parentID );
  61. break;
  62. case EntityType.InstanceDetailOverviewDoc:
  63. sp.ProcedureName = "net_bindingTemplate_instanceDetails_overviewDoc_description_save";
  64. sp.Parameters.Add( "@instanceID", SqlDbType.BigInt );
  65. sp.Parameters.SetLong( "@instanceID", parentID );
  66. break;
  67. default:
  68. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_DESCRPTION_INVALIDPARENTTYPE" , parentType.ToString() );
  69. }
  70. sp.Parameters.Add( "@isoLangCode", SqlDbType.VarChar, UDDI.Constants.Lengths.IsoLangCode );
  71. sp.Parameters.Add( "@description", SqlDbType.NVarChar, UDDI.Constants.Lengths.Description );
  72. sp.Parameters.SetString( "@isoLangCode", IsoLangCode );
  73. sp.Parameters.SetString( "@description", Value );
  74. sp.ExecuteNonQuery();
  75. Debug.Leave();
  76. }
  77. public void Save( string parentKey, EntityType parentType )
  78. {
  79. Debug.Enter();
  80. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  81. switch( parentType )
  82. {
  83. case EntityType.BusinessEntity:
  84. sp.ProcedureName = "net_businessEntity_description_save";
  85. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  86. sp.Parameters.SetGuidFromString( "@businessKey", parentKey );
  87. break;
  88. case EntityType.BusinessService:
  89. sp.ProcedureName = "net_businessService_description_save";
  90. sp.Parameters.Add( "@serviceKey", SqlDbType.UniqueIdentifier );
  91. sp.Parameters.SetGuidFromString( "@serviceKey", parentKey );
  92. break;
  93. case EntityType.BindingTemplate:
  94. sp.ProcedureName = "net_bindingTemplate_description_save";
  95. sp.Parameters.Add( "@bindingKey", SqlDbType.UniqueIdentifier );
  96. sp.Parameters.SetGuidFromString( "@bindingKey", parentKey );
  97. break;
  98. case EntityType.TModel:
  99. sp.ProcedureName = "net_tModel_description_save";
  100. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  101. sp.Parameters.SetGuidFromKey( "@tModelKey", parentKey );
  102. break;
  103. case EntityType.TModelOverviewDoc:
  104. sp.ProcedureName = "net_tModel_overviewDoc_description_save";
  105. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  106. sp.Parameters.SetGuidFromKey( "@tModelKey", parentKey );
  107. break;
  108. default:
  109. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_DESCRPTION_INVALIDPARENTTYPE" , parentType.ToString() );
  110. }
  111. sp.Parameters.Add( "@isoLangCode", SqlDbType.VarChar, UDDI.Constants.Lengths.IsoLangCode );
  112. sp.Parameters.Add( "@description", SqlDbType.NVarChar, UDDI.Constants.Lengths.Description );
  113. sp.Parameters.SetString( "@isoLangCode", IsoLangCode );
  114. sp.Parameters.SetString( "@description", Value );
  115. sp.ExecuteNonQuery();
  116. Debug.Leave();
  117. }
  118. }
  119. public class DescriptionCollection : CollectionBase
  120. {
  121. public DescriptionCollection()
  122. {
  123. }
  124. public void Get( int parentID, EntityType parentType )
  125. {
  126. Debug.Enter();
  127. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  128. switch( parentType )
  129. {
  130. case EntityType.Contact:
  131. sp.ProcedureName = "net_contact_descriptions_get";
  132. sp.Parameters.Add( "@contactID", SqlDbType.BigInt );
  133. sp.Parameters.SetLong( "@contactID", parentID );
  134. break;
  135. case EntityType.TModelInstanceInfo:
  136. sp.ProcedureName = "net_bindingTemplate_tModelInstanceInfo_descriptions_get";
  137. sp.Parameters.Add( "@instanceID", SqlDbType.BigInt );
  138. sp.Parameters.SetLong( "@instanceID", parentID );
  139. break;
  140. case EntityType.InstanceDetail:
  141. sp.ProcedureName = "net_bindingTemplate_instanceDetails_descriptions_get";
  142. sp.Parameters.Add( "@instanceID", SqlDbType.BigInt );
  143. sp.Parameters.SetLong( "@instanceID", parentID );
  144. break;
  145. case EntityType.InstanceDetailOverviewDoc:
  146. sp.ProcedureName = "net_bindingTemplate_instanceDetails_overviewDoc_descriptions_get";
  147. sp.Parameters.Add( "@instanceID", SqlDbType.BigInt );
  148. sp.Parameters.SetLong( "@instanceID", parentID );
  149. break;
  150. default:
  151. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_DESCRPTION_INVALIDPARENTTYPE" , parentType.ToString() );
  152. }
  153. SqlDataReaderAccessor reader = sp.ExecuteReader();
  154. try
  155. {
  156. Read( reader );
  157. #if never
  158. while( reader.Read() )
  159. {
  160. Add( reader.GetString( "isoLangCode" ),
  161. reader.GetString( "description" ) );
  162. }
  163. #endif
  164. }
  165. finally
  166. {
  167. reader.Close();
  168. }
  169. Debug.Leave();
  170. }
  171. public void Get( string parentKey, EntityType parentType )
  172. {
  173. Debug.Enter();
  174. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  175. switch( parentType )
  176. {
  177. case EntityType.BusinessEntity:
  178. sp.ProcedureName = "net_businessEntity_descriptions_get";
  179. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  180. sp.Parameters.SetGuidFromString( "@businessKey", parentKey );
  181. break;
  182. case EntityType.BusinessService:
  183. sp.ProcedureName = "net_businessService_descriptions_get";
  184. sp.Parameters.Add( "@serviceKey", SqlDbType.UniqueIdentifier );
  185. sp.Parameters.SetGuidFromString( "@serviceKey", parentKey );
  186. break;
  187. case EntityType.BindingTemplate:
  188. sp.ProcedureName = "net_bindingTemplate_descriptions_get";
  189. sp.Parameters.Add( "@bindingKey", SqlDbType.UniqueIdentifier );
  190. sp.Parameters.SetGuidFromString( "@bindingKey", parentKey );
  191. break;
  192. case EntityType.TModel:
  193. sp.ProcedureName = "net_tModel_descriptions_get";
  194. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  195. sp.Parameters.SetGuidFromKey( "@tModelKey", parentKey );
  196. break;
  197. case EntityType.TModelOverviewDoc:
  198. sp.ProcedureName = "net_tModel_overviewDoc_descriptions_get";
  199. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  200. sp.Parameters.SetGuidFromKey( "@tModelKey", parentKey );
  201. break;
  202. default:
  203. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_DESCRPTION_INVALIDPARENTTYPE", parentType.ToString() );
  204. }
  205. SqlDataReaderAccessor reader = sp.ExecuteReader();
  206. try
  207. {
  208. Read( reader );
  209. #if never
  210. while( reader.Read() )
  211. {
  212. Add( reader.GetString( "isoLangCode" ),
  213. reader.GetString( "description" ) );
  214. }
  215. #endif
  216. }
  217. finally
  218. {
  219. reader.Close();
  220. }
  221. Debug.Leave();
  222. }
  223. public void Read( SqlDataReaderAccessor reader )
  224. {
  225. while( reader.Read() )
  226. {
  227. Add( reader.GetString( "isoLangCode" ),
  228. reader.GetString( "description" ) );
  229. }
  230. }
  231. internal void Validate()
  232. {
  233. int maxLength = UDDI.Constants.Lengths.Description;
  234. int count = this.Count;
  235. bool languageAssigned = false;
  236. for( int i = 0; i < count; i ++ )
  237. {
  238. //
  239. // Validate the description string length.
  240. //
  241. Utility.ValidateLength( ref this[ i ].Value, "description", maxLength );
  242. //
  243. // Validate the language code. If one was not specified,
  244. // we'll use the publisher's default language.
  245. //
  246. if( Utility.StringEmpty( this[ i ].IsoLangCode ) )
  247. {
  248. //
  249. // Only one description can have an unassigned language.
  250. //
  251. if( languageAssigned )
  252. {
  253. throw new UDDIException(
  254. ErrorType.E_languageError,
  255. "UDDI_ERROR_LANGUAGEERROR_MULTIPLEBLANKLANG" );
  256. }
  257. languageAssigned = true;
  258. //
  259. // Fix: Bug 2340 9/9/2002, creeves
  260. //
  261. // if( i > 0 )
  262. // {
  263. // throw new UDDIException(
  264. // ErrorType.E_languageError,
  265. // "Only the first description can have a blank or missing xml:lang attribute. All other descriptions must have a valid xml:lang attribute." );
  266. // }
  267. this[ i ].IsoLangCode = Context.User.IsoLangCode;
  268. }
  269. }
  270. //
  271. // Fix: Bug 2397, 9/16/2002, a-kirkma
  272. //
  273. // Split loops and fill in default IsoLangCode first (if needed),
  274. // then look for repeated languages
  275. //
  276. for( int i = 0; i < count; i ++ )
  277. {
  278. //
  279. // Check to make sure there is only one description
  280. // per language.
  281. //
  282. string isoLangCode = this[ i ].IsoLangCode;
  283. Debug.Write( SeverityType.Info, CategoryType.Data, "Description[" + i + "]: " + this[ i ].Value + ", IsoLangCode: " + isoLangCode );
  284. for( int j = i + 1; j < count; j ++ )
  285. {
  286. if (false == Utility.StringEmpty(this[ j ].IsoLangCode)
  287. && isoLangCode.ToLower() == this[ j ].IsoLangCode.ToLower() )
  288. {
  289. Debug.Write( SeverityType.Info, CategoryType.Data, "Error: Description[" + j + "]: " + this[ j ].Value + ", IsoLangCode " + this[ j ].IsoLangCode + " matches IsoLangCode[" + i + "]: " + isoLangCode );
  290. throw new UDDIException(
  291. ErrorType.E_languageError,
  292. "UDDI_ERROR_LANGUAGEERROR_MULTIPLESAMELANG",isoLangCode );
  293. }
  294. }
  295. }
  296. }
  297. public void Save( long ID, EntityType parentType )
  298. {
  299. Debug.Enter();
  300. foreach( Description desc in this )
  301. desc.Save( ID, parentType );
  302. Debug.Leave();
  303. }
  304. public void Save( string key, EntityType parentType )
  305. {
  306. Debug.Enter();
  307. foreach( Description desc in this )
  308. desc.Save( key, parentType );
  309. Debug.Leave();
  310. }
  311. public Description this[int index]
  312. {
  313. get
  314. { return (Description)List[index]; }
  315. set
  316. { List[index] = value; }
  317. }
  318. public int Add(Description value)
  319. {
  320. return List.Add(value);
  321. }
  322. public int Add(string value)
  323. {
  324. return List.Add( new Description(value) );
  325. }
  326. public int Add(string isoLangCode, string description)
  327. {
  328. return List.Add( new Description(isoLangCode, description) );
  329. }
  330. public void Insert(int index, Description value)
  331. {
  332. List.Insert(index, value);
  333. }
  334. public int IndexOf(Description value)
  335. {
  336. return List.IndexOf(value);
  337. }
  338. public bool Contains(Description value)
  339. {
  340. return List.Contains(value);
  341. }
  342. public void Remove(Description value)
  343. {
  344. List.Remove(value);
  345. }
  346. public void CopyTo(Description[] array, int index)
  347. {
  348. List.CopyTo(array, index);
  349. }
  350. }
  351. }