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.

510 lines
12 KiB

  1. using System;
  2. using System.Data;
  3. using System.IO;
  4. using System.Collections;
  5. using System.Data.SqlClient;
  6. using System.Xml;
  7. using System.Xml.Schema;
  8. using System.Xml.Serialization;
  9. using UDDI.API;
  10. using UDDI;
  11. using UDDI.Diagnostics;
  12. using UDDI.API.Binding;
  13. using UDDI.API.Service;
  14. using UDDI.API.Business;
  15. using UDDI.API.ServiceType;
  16. namespace UDDI.Admin
  17. {
  18. [XmlRootAttribute("resources", Namespace="urn:microsoft-com:uddi_bootstrap_v1")]
  19. public class Resources
  20. {
  21. private TModelDetail tModelDetail;
  22. [XmlElement("tModelDetail", Namespace=UDDI.API.Constants.Namespace)]
  23. public TModelDetail TModelDetail
  24. {
  25. get
  26. {
  27. if( null == (object) tModelDetail )
  28. {
  29. tModelDetail = new TModelDetail();
  30. }
  31. return tModelDetail;
  32. }
  33. set
  34. {
  35. tModelDetail = value;
  36. }
  37. }
  38. [XmlIgnore()]
  39. public TaxonomyCollection Taxonomies = new TaxonomyCollection();
  40. [XmlArray( "categorizationSchemes" ), XmlArrayItem( "categorizationScheme" )]
  41. public Taxonomy[] TaxonomiesSerialize
  42. {
  43. get
  44. {
  45. return Taxonomies.ToArray();
  46. }
  47. set
  48. {
  49. Taxonomies.CopyTo( value );
  50. }
  51. }
  52. private BusinessDetail businessDetail;
  53. [XmlElement("businessDetail", Namespace=UDDI.API.Constants.Namespace)]
  54. public BusinessDetail BusinessDetail
  55. {
  56. get
  57. {
  58. if( null == businessDetail )
  59. {
  60. businessDetail = new BusinessDetail();
  61. }
  62. return businessDetail;
  63. }
  64. set
  65. {
  66. businessDetail = value;
  67. }
  68. }
  69. private ServiceDetail serviceDetail;
  70. [XmlElement("serviceDetail", Namespace=UDDI.API.Constants.Namespace)]
  71. public ServiceDetail ServiceDetail
  72. {
  73. get
  74. {
  75. if( null == serviceDetail )
  76. {
  77. serviceDetail = new ServiceDetail();
  78. }
  79. return serviceDetail;
  80. }
  81. set
  82. {
  83. serviceDetail = value;
  84. }
  85. }
  86. private BindingDetail bindingDetail;
  87. [XmlElement("bindingDetail", Namespace=UDDI.API.Constants.Namespace)]
  88. public BindingDetail BindingDetail
  89. {
  90. get
  91. {
  92. if( null == bindingDetail )
  93. {
  94. bindingDetail = new BindingDetail();
  95. }
  96. return bindingDetail;
  97. }
  98. set
  99. {
  100. bindingDetail = value;
  101. }
  102. }
  103. public Resources(){}
  104. public static void Validate( Stream strm )
  105. {
  106. Debug.VerifySetting( "Schema-v2" );
  107. Debug.VerifySetting( "InstallRoot" );
  108. string apiSchema = Config.GetString( "Schema-v2" );
  109. string resourceSchema = Config.GetString( "InstallRoot") + "uddi.resources.xsd";
  110. Debug.Verify( File.Exists( apiSchema ), "The API schema was not found in the location " + apiSchema );
  111. Debug.Verify( File.Exists( resourceSchema ), "The UDDI data resource schema was not found in the location " + resourceSchema );
  112. XmlSchemaCollection xsc = new XmlSchemaCollection();
  113. xsc.Add( "urn:uddi-org:api_v2", apiSchema );
  114. xsc.Add( "urn:microsoft-com:uddi_bootstrap_v1", resourceSchema );
  115. //
  116. // Rewind stream (to be safe) and validate
  117. //
  118. strm.Seek( 0, SeekOrigin.Begin );
  119. //
  120. // Construct a validating reader to verify the document is kosher
  121. //
  122. XmlTextReader reader = new XmlTextReader( strm );
  123. XmlValidatingReader vreader = new XmlValidatingReader( reader );
  124. vreader.Schemas.Add( xsc );
  125. while( vreader.Read()){}
  126. //
  127. // Rewind stream again, so someone else can use it
  128. //
  129. strm.Seek( 0, SeekOrigin.Begin );
  130. }
  131. public void Save()
  132. {
  133. UDDI.Diagnostics.Debug.Enter();
  134. Debug.Write( SeverityType.Info, CategoryType.Data, "Importing tModels..." );
  135. foreach( TModel tm in TModelDetail.TModels )
  136. {
  137. tm.Save();
  138. }
  139. Debug.Write( SeverityType.Info, CategoryType.Data, "Importing Categorization schemes..." );
  140. foreach( Taxonomy cs in Taxonomies )
  141. {
  142. cs.Save();
  143. }
  144. Debug.Write( SeverityType.Info, CategoryType.Data, "Importing Providers..." );
  145. foreach( BusinessEntity be in BusinessDetail.BusinessEntities )
  146. {
  147. be.Save();
  148. }
  149. Debug.Write( SeverityType.Info, CategoryType.Data, "Importing Services..." );
  150. foreach( BusinessService bs in ServiceDetail.BusinessServices )
  151. {
  152. bs.Save();
  153. }
  154. Debug.Write( SeverityType.Info, CategoryType.Data, "Importing bindings..." );
  155. foreach( BindingTemplate bind in BindingDetail.BindingTemplates )
  156. {
  157. bind.Save();
  158. }
  159. }
  160. }
  161. public class Taxonomy
  162. {
  163. private string tModelKey = "";
  164. private int taxonomyFlag = 1;
  165. [XmlAttribute( "checked" )]
  166. public XmlBoolType Checked
  167. {
  168. get { return ( 1 == taxonomyFlag ) ? XmlBoolType.True : XmlBoolType.False; }
  169. set
  170. {
  171. if( XmlBoolType.True == value )
  172. taxonomyFlag = 1;
  173. else
  174. taxonomyFlag = 2;
  175. }
  176. }
  177. [XmlElement( "tModelKey" )]
  178. public string TModelKey
  179. {
  180. get
  181. {
  182. return tModelKey;
  183. }
  184. set
  185. {
  186. tModelKey = value;
  187. }
  188. }
  189. [XmlIgnore()]
  190. public TaxonomyValueCollection TaxonomyValues = new TaxonomyValueCollection();
  191. [XmlArray( "categoryValues" ), XmlArrayItem( "categoryValue" )]
  192. public TaxonomyValue[] TaxonomyValuesSerialize
  193. {
  194. get
  195. {
  196. return TaxonomyValues.ToArray();
  197. }
  198. set
  199. {
  200. TaxonomyValues.CopyTo( value );
  201. }
  202. }
  203. public Taxonomy()
  204. {
  205. }
  206. public void Delete()
  207. {
  208. Debug.Enter();
  209. SqlCommand cmd = new SqlCommand( "net_taxonomy_delete", ConnectionManager.GetConnection() );
  210. cmd.CommandType = CommandType.StoredProcedure;
  211. cmd.Transaction = ConnectionManager.GetTransaction();
  212. cmd.Parameters.Add( new SqlParameter( "@tModelKey", SqlDbType.UniqueIdentifier ) ).Direction = ParameterDirection.Input;
  213. SqlParameterAccessor paramacc = new SqlParameterAccessor( cmd.Parameters );
  214. paramacc.SetGuidFromKey( "@tModelKey", tModelKey );
  215. cmd.ExecuteNonQuery();
  216. Debug.Leave();
  217. }
  218. public void Save()
  219. {
  220. Debug.Enter();
  221. //
  222. // Save the taxonomy entry.
  223. //
  224. SqlCommand cmd = new SqlCommand( "net_taxonomy_save", ConnectionManager.GetConnection() );
  225. cmd.CommandType = CommandType.StoredProcedure;
  226. cmd.Transaction = ConnectionManager.GetTransaction();
  227. cmd.Parameters.Add( new SqlParameter( "@tModelKey", SqlDbType.UniqueIdentifier ) ).Direction = ParameterDirection.Input;
  228. cmd.Parameters.Add( new SqlParameter( "@flag", SqlDbType.Int ) ).Direction = ParameterDirection.Input;
  229. cmd.Parameters.Add( new SqlParameter( "@taxonomyID", SqlDbType.Int ) ).Direction = ParameterDirection.Output;
  230. SqlParameterAccessor paramacc = new SqlParameterAccessor( cmd.Parameters );
  231. paramacc.SetGuidFromKey( "@tModelKey", tModelKey );
  232. paramacc.SetInt( "@flag", taxonomyFlag );
  233. cmd.ExecuteNonQuery();
  234. int taxonomyID = paramacc.GetInt( "@taxonomyID" );
  235. foreach( TaxonomyValue tv in TaxonomyValues )
  236. {
  237. tv.Save( tModelKey );
  238. }
  239. }
  240. }
  241. public enum ValidForCategorization
  242. {
  243. [XmlEnumAttribute("false")]
  244. False = 0,
  245. [XmlEnumAttribute("true")]
  246. True = 1,
  247. }
  248. public class TaxonomyValue
  249. {
  250. [XmlAttribute( "categoryKey" )]
  251. public string KeyValue;
  252. private bool validForClassification = true;
  253. [XmlAttribute( "isValid" )]
  254. public ValidForCategorization ValidForClassification
  255. {
  256. get
  257. {
  258. return validForClassification ? ValidForCategorization.True : ValidForCategorization.False;
  259. }
  260. set
  261. {
  262. if( ValidForCategorization.True == value )
  263. validForClassification = true;
  264. else
  265. validForClassification = false;
  266. }
  267. }
  268. [XmlElement( "parentCategoryKey" )]
  269. public string ParentKeyValue;
  270. [XmlArray( "categoryNames" ), XmlArrayItem( "categoryName" )]
  271. public KeyName[] KeyNames;
  272. public TaxonomyValue(){}
  273. public TaxonomyValue( string keyValue, string parentKeyValue, string keyName, bool validForClassification )
  274. {
  275. this.KeyValue = keyValue;
  276. this.ParentKeyValue = parentKeyValue;
  277. KeyNames = new KeyName[ 1 ];
  278. KeyNames[0].Name = keyName;
  279. this.validForClassification = validForClassification;
  280. }
  281. public void Save( string tModelKey )
  282. {
  283. Debug.Enter();
  284. SqlCommand cmd = new SqlCommand( "net_taxonomyValue_save", ConnectionManager.GetConnection() );
  285. cmd.CommandType = CommandType.StoredProcedure;
  286. cmd.Transaction = ConnectionManager.GetTransaction();
  287. cmd.Parameters.Add( new SqlParameter( "@tModelKey", SqlDbType.UniqueIdentifier ) ).Direction = ParameterDirection.Input;
  288. cmd.Parameters.Add( new SqlParameter( "@keyValue", SqlDbType.NVarChar, 128 ) ).Direction = ParameterDirection.Input;
  289. cmd.Parameters.Add( new SqlParameter( "@parentKeyValue", SqlDbType.NVarChar, 128 ) ).Direction = ParameterDirection.Input;
  290. cmd.Parameters.Add( new SqlParameter( "@keyName", SqlDbType.NVarChar, 128 ) ).Direction = ParameterDirection.Input;
  291. cmd.Parameters.Add( new SqlParameter( "@valid", SqlDbType.Bit ) ).Direction = ParameterDirection.Input;
  292. SqlParameterAccessor paramacc = new SqlParameterAccessor( cmd.Parameters );
  293. paramacc.SetGuidFromKey( "@tModelKey", tModelKey );
  294. paramacc.SetString( "@keyValue", KeyValue );
  295. paramacc.SetString( "@keyName", KeyNames[0].Name );
  296. cmd.Parameters[ "@valid" ].Value = ValidForClassification;
  297. if( Utility.StringEmpty( ParentKeyValue ) )
  298. paramacc.SetString( "@parentKeyValue", KeyValue );
  299. else
  300. paramacc.SetString( "@parentKeyValue", ParentKeyValue );
  301. cmd.ExecuteNonQuery();
  302. }
  303. }
  304. public class KeyName
  305. {
  306. [XmlText()]
  307. public string Name;
  308. [XmlAttribute( "xml:lang" )]
  309. public string IsoLanguageCode;
  310. public KeyName(){}
  311. }
  312. public class TaxonomyCollection : CollectionBase
  313. {
  314. public TaxonomyCollection()
  315. {
  316. }
  317. public void Save()
  318. {
  319. Debug.Enter();
  320. foreach( Taxonomy tax in this )
  321. {
  322. tax.Save();
  323. }
  324. Debug.Leave();
  325. }
  326. public Taxonomy this[int index]
  327. {
  328. get
  329. { return (Taxonomy)List[index]; }
  330. set
  331. { List[index] = value; }
  332. }
  333. public int Add(Taxonomy value)
  334. {
  335. return List.Add(value);
  336. }
  337. public void Insert(int index, Taxonomy value)
  338. {
  339. List.Insert(index, value);
  340. }
  341. public int IndexOf( Taxonomy value )
  342. {
  343. return List.IndexOf( value );
  344. }
  345. public bool Contains( Taxonomy value )
  346. {
  347. return List.Contains( value );
  348. }
  349. public void Remove( Taxonomy value )
  350. {
  351. List.Remove( value );
  352. }
  353. public void CopyTo(Taxonomy[] array, int index)
  354. {
  355. List.CopyTo( array, index );
  356. }
  357. public void CopyTo( Taxonomy[] array )
  358. {
  359. foreach( Taxonomy tax in array )
  360. Add( tax );
  361. }
  362. public Taxonomy[] ToArray()
  363. {
  364. return (Taxonomy[]) InnerList.ToArray( typeof( Taxonomy ) );
  365. }
  366. }
  367. public class TaxonomyValueCollection : CollectionBase
  368. {
  369. public TaxonomyValueCollection()
  370. {
  371. }
  372. public TaxonomyValue this[int index]
  373. {
  374. get
  375. { return (TaxonomyValue)List[index]; }
  376. set
  377. { List[index] = value; }
  378. }
  379. public int Add(TaxonomyValue value)
  380. {
  381. return List.Add(value);
  382. }
  383. public void Insert(int index, TaxonomyValue value)
  384. {
  385. List.Insert(index, value);
  386. }
  387. public int IndexOf( TaxonomyValue value )
  388. {
  389. return List.IndexOf( value );
  390. }
  391. public bool Contains( TaxonomyValue value )
  392. {
  393. return List.Contains( value );
  394. }
  395. public void Remove( TaxonomyValue value )
  396. {
  397. List.Remove( value );
  398. }
  399. public void CopyTo(TaxonomyValue[] array, int index)
  400. {
  401. List.CopyTo( array, index );
  402. }
  403. public void CopyTo( TaxonomyValue[] array )
  404. {
  405. foreach( TaxonomyValue tax in array )
  406. Add( tax );
  407. }
  408. public TaxonomyValue[] ToArray()
  409. {
  410. return (TaxonomyValue[]) InnerList.ToArray( typeof( TaxonomyValue ) );
  411. }
  412. }
  413. }