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.

450 lines
15 KiB

  1. using System;
  2. using System.Data.SqlClient;
  3. using System.Drawing;
  4. using System.Collections;
  5. using System.ComponentModel;
  6. using System.Windows.Forms;
  7. using System.Xml;
  8. using System.Xml.Serialization;
  9. using System.IO;
  10. using UDDI;
  11. using UDDI.API;
  12. using UDDI.Replication;
  13. using UDDI.API.Binding;
  14. using UDDI.API.ServiceType;
  15. namespace UDDI.Tools
  16. {
  17. public class CorrectionAdmin : UserControl, IAdminObject
  18. {
  19. private XmlSerializer changeRecordSerializer;
  20. private System.Windows.Forms.Label usnLabel;
  21. private System.Windows.Forms.TextBox usnTextBox;
  22. private System.Windows.Forms.Button usnButton;
  23. private System.Windows.Forms.GroupBox findGroupBox;
  24. private System.Windows.Forms.GroupBox changeRecordGroupBox;
  25. private System.Windows.Forms.TextBox changeRecordTextBox;
  26. private System.Windows.Forms.GroupBox correctionGroupBox;
  27. private System.Windows.Forms.TextBox correctionTextBox;
  28. private System.Windows.Forms.Button correctionButton;
  29. private XmlSerializer correctionSerializer;
  30. public CorrectionAdmin()
  31. {
  32. changeRecordSerializer = new XmlSerializer( typeof( ChangeRecord ) );
  33. correctionSerializer = new XmlSerializer( typeof( ChangeRecordCorrection ) );
  34. }
  35. public void Initialize( IAdminFrame parent )
  36. {
  37. InitializeComponent();
  38. }
  39. public string GetNodeText()
  40. {
  41. return "Corrections";
  42. }
  43. public void Show( Control parentDisplay )
  44. {
  45. Parent = parentDisplay;
  46. Size = parentDisplay.Size;
  47. }
  48. private void InitializeComponent()
  49. {
  50. this.usnLabel = new System.Windows.Forms.Label();
  51. this.usnTextBox = new System.Windows.Forms.TextBox();
  52. this.usnButton = new System.Windows.Forms.Button();
  53. this.findGroupBox = new System.Windows.Forms.GroupBox();
  54. this.changeRecordGroupBox = new System.Windows.Forms.GroupBox();
  55. this.changeRecordTextBox = new System.Windows.Forms.TextBox();
  56. this.correctionGroupBox = new System.Windows.Forms.GroupBox();
  57. this.correctionButton = new System.Windows.Forms.Button();
  58. this.correctionTextBox = new System.Windows.Forms.TextBox();
  59. this.findGroupBox.SuspendLayout();
  60. this.changeRecordGroupBox.SuspendLayout();
  61. this.correctionGroupBox.SuspendLayout();
  62. this.SuspendLayout();
  63. //
  64. // usnLabel
  65. //
  66. this.usnLabel.Location = new System.Drawing.Point(8, 24);
  67. this.usnLabel.Name = "usnLabel";
  68. this.usnLabel.Size = new System.Drawing.Size(48, 16);
  69. this.usnLabel.TabIndex = 0;
  70. this.usnLabel.Text = "USN:";
  71. //
  72. // usnTextBox
  73. //
  74. this.usnTextBox.Location = new System.Drawing.Point(56, 22);
  75. this.usnTextBox.Name = "usnTextBox";
  76. this.usnTextBox.Size = new System.Drawing.Size(112, 20);
  77. this.usnTextBox.TabIndex = 1;
  78. this.usnTextBox.Text = "";
  79. //
  80. // usnButton
  81. //
  82. this.usnButton.Location = new System.Drawing.Point(176, 21);
  83. this.usnButton.Name = "usnButton";
  84. this.usnButton.Size = new System.Drawing.Size(120, 23);
  85. this.usnButton.TabIndex = 2;
  86. this.usnButton.Text = "Get ChangeRecord";
  87. this.usnButton.Click += new System.EventHandler(this.usnButton_Click);
  88. //
  89. // findGroupBox
  90. //
  91. this.findGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  92. | System.Windows.Forms.AnchorStyles.Right);
  93. this.findGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
  94. this.usnLabel,
  95. this.usnButton,
  96. this.usnTextBox});
  97. this.findGroupBox.Location = new System.Drawing.Point(8, 8);
  98. this.findGroupBox.Name = "findGroupBox";
  99. this.findGroupBox.Size = new System.Drawing.Size(568, 56);
  100. this.findGroupBox.TabIndex = 3;
  101. this.findGroupBox.TabStop = false;
  102. this.findGroupBox.Text = "Find Change Record";
  103. //
  104. // changeRecordGroupBox
  105. //
  106. this.changeRecordGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  107. | System.Windows.Forms.AnchorStyles.Right);
  108. this.changeRecordGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
  109. this.changeRecordTextBox});
  110. this.changeRecordGroupBox.Location = new System.Drawing.Point(8, 72);
  111. this.changeRecordGroupBox.Name = "changeRecordGroupBox";
  112. this.changeRecordGroupBox.Size = new System.Drawing.Size(568, 280);
  113. this.changeRecordGroupBox.TabIndex = 4;
  114. this.changeRecordGroupBox.TabStop = false;
  115. this.changeRecordGroupBox.Text = "Change Record";
  116. //
  117. // changeRecordTextBox
  118. //
  119. this.changeRecordTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  120. | System.Windows.Forms.AnchorStyles.Right);
  121. this.changeRecordTextBox.Location = new System.Drawing.Point(8, 24);
  122. this.changeRecordTextBox.Multiline = true;
  123. this.changeRecordTextBox.Name = "changeRecordTextBox";
  124. this.changeRecordTextBox.ReadOnly = true;
  125. this.changeRecordTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
  126. this.changeRecordTextBox.Size = new System.Drawing.Size(552, 240);
  127. this.changeRecordTextBox.TabIndex = 0;
  128. this.changeRecordTextBox.Text = "";
  129. //
  130. // correctionGroupBox
  131. //
  132. this.correctionGroupBox.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  133. | System.Windows.Forms.AnchorStyles.Left)
  134. | System.Windows.Forms.AnchorStyles.Right);
  135. this.correctionGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
  136. this.correctionButton,
  137. this.correctionTextBox});
  138. this.correctionGroupBox.Location = new System.Drawing.Point(8, 360);
  139. this.correctionGroupBox.Name = "correctionGroupBox";
  140. this.correctionGroupBox.Size = new System.Drawing.Size(568, 304);
  141. this.correctionGroupBox.TabIndex = 5;
  142. this.correctionGroupBox.TabStop = false;
  143. this.correctionGroupBox.Text = "Proposed Correction";
  144. //
  145. // correctionButton
  146. //
  147. this.correctionButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
  148. this.correctionButton.Enabled = false;
  149. this.correctionButton.Location = new System.Drawing.Point(8, 272);
  150. this.correctionButton.Name = "correctionButton";
  151. this.correctionButton.Size = new System.Drawing.Size(112, 23);
  152. this.correctionButton.TabIndex = 1;
  153. this.correctionButton.Text = "Issue Correction";
  154. this.correctionButton.Click += new System.EventHandler(this.correctionButton_Click);
  155. //
  156. // correctionTextBox
  157. //
  158. this.correctionTextBox.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  159. | System.Windows.Forms.AnchorStyles.Left)
  160. | System.Windows.Forms.AnchorStyles.Right);
  161. this.correctionTextBox.Location = new System.Drawing.Point(8, 24);
  162. this.correctionTextBox.Multiline = true;
  163. this.correctionTextBox.Name = "correctionTextBox";
  164. this.correctionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
  165. this.correctionTextBox.Size = new System.Drawing.Size(552, 240);
  166. this.correctionTextBox.TabIndex = 0;
  167. this.correctionTextBox.Text = "";
  168. //
  169. // CorrectionAdmin
  170. //
  171. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  172. this.correctionGroupBox,
  173. this.changeRecordGroupBox,
  174. this.findGroupBox});
  175. this.Name = "CorrectionAdmin";
  176. this.Size = new System.Drawing.Size(592, 680);
  177. this.findGroupBox.ResumeLayout(false);
  178. this.changeRecordGroupBox.ResumeLayout(false);
  179. this.correctionGroupBox.ResumeLayout(false);
  180. this.ResumeLayout(false);
  181. }
  182. void usnButton_Click(object sender, System.EventArgs e)
  183. {
  184. ShowChangeRecord();
  185. }
  186. private bool ValidatePublisher()
  187. {
  188. bool validPublisher = Context.User.IsRegistered;
  189. //
  190. // Make sure the user is a UDDI publisher.
  191. //
  192. if( false == validPublisher )
  193. {
  194. DialogResult dialogResult = MessageBox.Show( "You are not registered as a publisher on this UDDI Site? You must register before performing this operation. Would you like to register now?",
  195. "UDDI",
  196. MessageBoxButtons.YesNo );
  197. if( DialogResult.Yes == dialogResult )
  198. {
  199. try
  200. {
  201. Context.User.Register();
  202. validPublisher = Context.User.IsRegistered;
  203. }
  204. catch( Exception registrationException )
  205. {
  206. MessageBox.Show( "An exception occurred when trying to register:\r\n\r\n" + registrationException.ToString() );
  207. }
  208. }
  209. }
  210. return validPublisher;
  211. }
  212. private void correctionButton_Click(object sender, System.EventArgs e)
  213. {
  214. if( false == ValidatePublisher() )
  215. {
  216. return;
  217. }
  218. try
  219. {
  220. ConnectionManager.BeginTransaction();
  221. //
  222. // Deserialize into a change record object
  223. //
  224. StringReader reader = new StringReader( correctionTextBox.Text );
  225. ChangeRecordCorrection changeRecordCorrection = ( ChangeRecordCorrection ) correctionSerializer.Deserialize( reader );
  226. //
  227. // Validate what we created.
  228. //
  229. SchemaCollection.Validate( changeRecordCorrection );
  230. //
  231. // Create a new change record to hold the correction.
  232. //
  233. ChangeRecord changeRecord = new ChangeRecord( changeRecordCorrection );
  234. changeRecord.Process();
  235. ConnectionManager.Commit();
  236. //
  237. // If we made it this far, we were able to process the correction
  238. //
  239. MessageBox.Show( "Correction processed!" );
  240. //
  241. // Refresh our display.
  242. //
  243. ShowChangeRecord();
  244. }
  245. catch( Exception exception )
  246. {
  247. ConnectionManager.Abort();
  248. MessageBox.Show( "An exception occurred when trying to process the correction:\r\n\r\n" + exception.ToString() );
  249. }
  250. }
  251. void ShowChangeRecord()
  252. {
  253. try
  254. {
  255. //
  256. // Get the USN the user entered.
  257. //
  258. int usn = Convert.ToInt32( usnTextBox.Text );
  259. SqlDataReaderAccessor reader = null;
  260. try
  261. {
  262. //
  263. // Try to find the ChangeRecord by USN. We can only correct local change records, so always
  264. // use the local operator key.
  265. //
  266. FindChangeRecords.SetRange( Config.GetString( "OperatorKey" ), usn, usn );
  267. //
  268. // Get the results; we should only have 1 result.
  269. //
  270. reader = FindChangeRecords.RetrieveResults( 1 );
  271. //
  272. // Construct a ChangeRecord from the results.
  273. //
  274. ChangeRecord changeRecord = CreateChangeRecord( reader );
  275. if( null != changeRecord )
  276. {
  277. //
  278. // If we found a change record, show its XML and show the XML for a
  279. // proposed correction. The user will be allowed to edit the XML for the
  280. // proposed correction.
  281. //
  282. DisplayChangeRecord( changeRecord );
  283. DisplayCorrection( changeRecord );
  284. correctionButton.Enabled = true;
  285. }
  286. else
  287. {
  288. MessageBox.Show( "No ChangeRecord matching that USN was found." );
  289. }
  290. }
  291. catch( Exception innerException )
  292. {
  293. FindChangeRecords.CleanUp();
  294. throw innerException;
  295. }
  296. finally
  297. {
  298. if( null != reader )
  299. {
  300. reader.Close();
  301. }
  302. }
  303. }
  304. catch( Exception exception )
  305. {
  306. correctionButton.Enabled = false;
  307. MessageBox.Show( "Change Record for that USN could not be obtained\r\n\r\n:" + exception.ToString() );
  308. }
  309. }
  310. ChangeRecord CreateChangeRecord( SqlDataReaderAccessor reader )
  311. {
  312. ChangeRecord changeRecord = null;
  313. try
  314. {
  315. while( reader.Read() )
  316. {
  317. XmlSerializer serializer = null;
  318. switch( (ChangeRecordPayloadType)reader.GetShort( "changeTypeID" ) )
  319. {
  320. case ChangeRecordPayloadType.ChangeRecordNull:
  321. serializer = new XmlSerializer( typeof( ChangeRecordNull ) );
  322. break;
  323. case ChangeRecordPayloadType.ChangeRecordNewData:
  324. serializer = new XmlSerializer( typeof( ChangeRecordNewData ) );
  325. break;
  326. case ChangeRecordPayloadType.ChangeRecordDelete:
  327. serializer = new XmlSerializer( typeof( ChangeRecordDelete ) );
  328. break;
  329. case ChangeRecordPayloadType.ChangeRecordPublisherAssertion:
  330. serializer = new XmlSerializer( typeof( ChangeRecordPublisherAssertion ) );
  331. break;
  332. case ChangeRecordPayloadType.ChangeRecordHide:
  333. serializer = new XmlSerializer( typeof( ChangeRecordHide ) );
  334. break;
  335. case ChangeRecordPayloadType.ChangeRecordDeleteAssertion:
  336. serializer = new XmlSerializer( typeof( ChangeRecordDeleteAssertion ) );
  337. break;
  338. case ChangeRecordPayloadType.ChangeRecordAcknowledgement:
  339. serializer = new XmlSerializer( typeof( ChangeRecordAcknowledgement ) );
  340. break;
  341. case ChangeRecordPayloadType.ChangeRecordCorrection:
  342. serializer = new XmlSerializer( typeof( ChangeRecordCorrection ) );
  343. break;
  344. }
  345. StringReader stringReader = new StringReader( reader.GetString( "changeData" ) );
  346. try
  347. {
  348. changeRecord = new ChangeRecord();
  349. changeRecord.AcknowledgementRequested = ( reader.GetInt( "flag" ) & (int)ChangeRecordFlags.AcknowledgementRequested ) > 0;
  350. changeRecord.ChangeID.NodeID = reader.GetString( "OperatorKey" );
  351. changeRecord.ChangeID.OriginatingUSN = reader.GetLong( "USN" );
  352. ChangeRecordBase changeRecordBase = ( ChangeRecordBase ) serializer.Deserialize( stringReader );
  353. if( changeRecordBase is ChangeRecordCorrection )
  354. {
  355. //
  356. // The query to find change records will do correction 'fixups'. That is, the changeData of this
  357. // change record will be replaced with the changeData from the correction. The problem with this is
  358. // that the original change data will now look like a correction. To distinguish these types of
  359. // change records, we look to see if the OriginatingUSN's match. If the OriginatingUSN's match,
  360. // we want they payload of the change record in this correction. This payload will contain the
  361. // corrected data that we want.
  362. //
  363. ChangeRecordCorrection changeRecordCorrection = ( ChangeRecordCorrection ) changeRecordBase;
  364. if( changeRecordCorrection.ChangeRecord.ChangeID.OriginatingUSN == changeRecord.ChangeID.OriginatingUSN )
  365. {
  366. changeRecordBase = changeRecordCorrection.ChangeRecord.Payload;
  367. }
  368. }
  369. changeRecord.Payload = changeRecordBase;
  370. }
  371. finally
  372. {
  373. stringReader.Close();
  374. }
  375. }
  376. }
  377. finally
  378. {
  379. reader.Close();
  380. }
  381. return changeRecord;
  382. }
  383. void DisplayChangeRecord( ChangeRecord changeRecord )
  384. {
  385. UTF8EncodedStringWriter writer = new UTF8EncodedStringWriter();
  386. changeRecordSerializer.Serialize( writer, changeRecord );
  387. writer.Close();
  388. changeRecordTextBox.Text = writer.ToString();
  389. }
  390. void DisplayCorrection( ChangeRecord changeRecord )
  391. {
  392. ChangeRecordCorrection changeRecordCorrection = new ChangeRecordCorrection();
  393. changeRecordCorrection.ChangeRecord = changeRecord;
  394. UTF8EncodedStringWriter writer = new UTF8EncodedStringWriter();
  395. correctionSerializer.Serialize( writer, changeRecordCorrection );
  396. writer.Close();
  397. correctionTextBox.Text = writer.ToString();
  398. }
  399. }
  400. }