PageRenderTime 71ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Branches/V1/Thinktecture.Tools.Web.Services.WsdlWizard/WsdlWizardForm.cs

#
C# | 3476 lines | 2576 code | 323 blank | 577 comment | 177 complexity | 47c07a079c8fb78a5dc1da4d2fcbf350 MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Globalization;
  7. using System.Linq;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Text;
  11. using System.Reflection;
  12. using System.Net;
  13. using Thinktecture.Tools.Web.Services.ServiceDescription;
  14. using WizardControl;
  15. using WRM.Windows.Forms;
  16. using Message = Thinktecture.Tools.Web.Services.ServiceDescription.Message;
  17. using Thinktecture.Tools.Web.Services.Wscf.Environment;
  18. namespace Thinktecture.Tools.Web.Services.WsdlWizard
  19. {
  20. /// <summary>
  21. /// Represents the user interface handler for WsdlWizardForm.
  22. /// </summary>
  23. public class WsdlWizardForm : Form
  24. {
  25. #region Private fields
  26. private int operationCount;
  27. private string schemaLocation = "";
  28. private string wsdlLocation = "";
  29. private string schemaNamespace = "";
  30. private bool openCodeGenDialog;
  31. private bool alreadyCancelled = false;
  32. private bool roundtripMode = false;
  33. private string currentFolder;
  34. private string wsdlFile = string.Empty;
  35. private string defaultPathForImports = string.Empty;
  36. private string projectRootDirectory = string.Empty;
  37. private ArrayList importedSchemaNamespaces = new ArrayList();
  38. private Wizard wsdlWizardCtrl;
  39. private WizardPage wizardPageBasicMetadata;
  40. private TextBox tbServiceName;
  41. private Label lblServiceName;
  42. private Label lblNamespace;
  43. private WizardPage wizardPageOperationsList;
  44. private GroupBox groupBox1;
  45. private TextBox tbEdit;
  46. private ComboBox cbMEPs;
  47. private Panel panel1;
  48. private ToolTip toolTip1;
  49. private IContainer components;
  50. private TextBox tbNamespace;
  51. private LinkLabel llAddOperation;
  52. private EditableListView operationsListView;
  53. private InterfaceContract serviceInterfaceContract;
  54. private InterfaceContract importedContract = null;
  55. private SchemaElements messageSchemas = new SchemaElements();
  56. private SchemaElements headerSchemas = new SchemaElements();
  57. private SchemaElements faultSchemas = new SchemaElements();
  58. private LinkLabel llRemoveOperation;
  59. private Label lblServiceDoc;
  60. private TextBox tbServiceDoc;
  61. private WizardPage wizardPageMessageMapping;
  62. private WizardControl.WizardPage wizardPageAdditionalOptions;
  63. private System.Windows.Forms.CheckBox cbNeedsServiceElement;
  64. private System.Windows.Forms.CheckBox cbCodeGenDialog;
  65. private WRM.Windows.Forms.PropertyTree ptvServiceOperations;
  66. private WizardControl.WizardPage wizardPageSchemaImports;
  67. private System.Windows.Forms.GroupBox groupBox2;
  68. private Thinktecture.Tools.Web.Services.WsdlWizard.EditableListView importsListView;
  69. private System.Windows.Forms.LinkLabel llAddImport;
  70. private System.Windows.Forms.LinkLabel llRemoveImport;
  71. private System.Windows.Forms.OpenFileDialog openFileDialog1;
  72. private WizardControl.WizardPage wizardPageAlternativeXSDPaths;
  73. private Thinktecture.Tools.Web.Services.WsdlWizard.EditableListView xsdpathsListView;
  74. private System.Windows.Forms.ToolTip toolTipPath;
  75. private System.Windows.Forms.CheckBox cbInfer;
  76. private OperationsCollection inferOperations = new OperationsCollection(10);
  77. private CheckBox cbSoap12;
  78. private CheckBox cbSoap11;
  79. private OperationsCollection oldOperations =
  80. new OperationsCollection(); // Holds a list of old operations configured by the user.
  81. #endregion
  82. #region Public properties.
  83. /// <summary>
  84. /// Gets a value indicating whether the code generation dialog should be opened or not.
  85. /// </summary>
  86. public bool OpenCodeGenDialog
  87. {
  88. get { return openCodeGenDialog; }
  89. }
  90. /// <summary>
  91. /// Gets or sets the location to create the WSDL file.
  92. /// </summary>
  93. public string WsdlLocation
  94. {
  95. get { return wsdlLocation; }
  96. set { wsdlLocation = value; }
  97. }
  98. /// <summary>
  99. /// Gets or sets the schema namespace.
  100. /// </summary>
  101. public string SchemaNamespace
  102. {
  103. get { return schemaNamespace; }
  104. set { schemaNamespace = value; }
  105. }
  106. /// <summary>
  107. /// Gets or sets the schema location.
  108. /// </summary>
  109. public string SchemaLocation
  110. {
  111. get { return schemaLocation; }
  112. set
  113. {
  114. schemaLocation = value;
  115. this.UpdateCurrentFolder(schemaLocation);
  116. }
  117. }
  118. /// <summary>
  119. /// Gets or sets a value indicating whether the round tripping mode is on or off.
  120. /// </summary>
  121. public bool RoundtripMode
  122. {
  123. get { return roundtripMode; }
  124. set { roundtripMode = value; }
  125. }
  126. /// <summary>
  127. /// Gets or sets the default path for the imported XSD files.
  128. /// </summary>
  129. public string DefaultPathForImports
  130. {
  131. get { return defaultPathForImports; }
  132. set { defaultPathForImports = value; }
  133. }
  134. /// <summary>
  135. /// Gets or sets the root directory for the project.
  136. /// </summary>
  137. public string ProjectRootDirectory
  138. {
  139. get { return projectRootDirectory; }
  140. set { projectRootDirectory = value; }
  141. }
  142. #endregion
  143. #region Constructors
  144. /// <summary>
  145. /// Initializes a new instance of WsdlWizardForm class with the specified values.
  146. /// </summary>
  147. /// <param name="xsdLocation">
  148. /// Location of the XSD file containing the message contract definitions for the WSDL.
  149. /// </param>
  150. public WsdlWizardForm(string xsdLocation)
  151. {
  152. //
  153. // Required for Windows Form Designer support.
  154. //
  155. InitializeComponent();
  156. schemaLocation = xsdLocation;
  157. this.UpdateCurrentFolder(schemaLocation);
  158. serviceInterfaceContract = new InterfaceContract();
  159. serviceInterfaceContract.SchemaNamespace = schemaLocation;
  160. }
  161. /// <summary>
  162. /// Initializes a new instance of WsdlWizardForm class with the specified values.
  163. /// </summary>
  164. /// <param name="wsdlLocation">Location of the WSDL file to modify.</param>
  165. /// <param name="roundTripping">
  166. /// Value indicating that the round tripping is required.
  167. /// </param>
  168. /// <remarks>
  169. /// The roundTripping parameter must be set to true in order to use the round tripping feature.
  170. /// </remarks>
  171. public WsdlWizardForm(string wsdlLocation, bool roundTripping)
  172. {
  173. //
  174. // Required for Windows Form Designer support.
  175. //
  176. InitializeComponent();
  177. // Import the interface contract from the selected WSDL file.
  178. try
  179. {
  180. this.importedContract =
  181. ServiceDescriptionEngine.GetInterfaceContract(wsdlLocation);
  182. this.wsdlFile = wsdlLocation;
  183. }
  184. catch(WsdlModifiedException ex)
  185. {
  186. throw new WsdlFileLoadException(
  187. "Could not import the specified WSDL file for round-triping.\nThis file is not compatible for round-tripping.", ex);
  188. }
  189. catch(WsdlNotCompatibleForRoundTrippingException ex)
  190. {
  191. throw new WsdlFileLoadException(
  192. "Could not import the specified WSDL file for round-triping.\nThis file is not compatible for round-tripping.", ex);
  193. }
  194. catch
  195. {
  196. throw new WsdlFileLoadException(
  197. "System could not import the specified WSDL file for round triping.\nThis file is either modified or not a valid WSDL file created using WSCF.exe.");
  198. }
  199. this.UpdateCurrentFolder(wsdlLocation);
  200. serviceInterfaceContract = new InterfaceContract();
  201. serviceInterfaceContract.SchemaNamespace = schemaLocation;
  202. this.roundtripMode = roundTripping;
  203. }
  204. #endregion
  205. #region Dispose
  206. /// <summary>
  207. /// Clean up any resources being used.
  208. /// </summary>
  209. protected override void Dispose( bool disposing )
  210. {
  211. if( disposing )
  212. {
  213. if(components != null)
  214. {
  215. components.Dispose();
  216. }
  217. }
  218. base.Dispose( disposing );
  219. }
  220. #endregion
  221. #region Windows Form Designer generated code
  222. /// <summary>
  223. /// Required method for Designer support - do not modify
  224. /// the contents of this method with the code editor.
  225. /// </summary>
  226. private void InitializeComponent()
  227. {
  228. this.components = new System.ComponentModel.Container();
  229. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WsdlWizardForm));
  230. this.wsdlWizardCtrl = new WizardControl.Wizard();
  231. this.wizardPageBasicMetadata = new WizardControl.WizardPage();
  232. this.tbServiceDoc = new System.Windows.Forms.TextBox();
  233. this.lblServiceDoc = new System.Windows.Forms.Label();
  234. this.lblNamespace = new System.Windows.Forms.Label();
  235. this.tbNamespace = new System.Windows.Forms.TextBox();
  236. this.lblServiceName = new System.Windows.Forms.Label();
  237. this.tbServiceName = new System.Windows.Forms.TextBox();
  238. this.wizardPageSchemaImports = new WizardControl.WizardPage();
  239. this.groupBox2 = new System.Windows.Forms.GroupBox();
  240. this.llRemoveImport = new System.Windows.Forms.LinkLabel();
  241. this.llAddImport = new System.Windows.Forms.LinkLabel();
  242. this.importsListView = new Thinktecture.Tools.Web.Services.WsdlWizard.EditableListView();
  243. this.wizardPageOperationsList = new WizardControl.WizardPage();
  244. this.groupBox1 = new System.Windows.Forms.GroupBox();
  245. this.operationsListView = new Thinktecture.Tools.Web.Services.WsdlWizard.EditableListView();
  246. this.llAddOperation = new System.Windows.Forms.LinkLabel();
  247. this.llRemoveOperation = new System.Windows.Forms.LinkLabel();
  248. this.cbInfer = new System.Windows.Forms.CheckBox();
  249. this.panel1 = new System.Windows.Forms.Panel();
  250. this.tbEdit = new System.Windows.Forms.TextBox();
  251. this.cbMEPs = new System.Windows.Forms.ComboBox();
  252. this.wizardPageMessageMapping = new WizardControl.WizardPage();
  253. this.ptvServiceOperations = new WRM.Windows.Forms.PropertyTree();
  254. this.wizardPageAdditionalOptions = new WizardControl.WizardPage();
  255. this.cbSoap12 = new System.Windows.Forms.CheckBox();
  256. this.cbSoap11 = new System.Windows.Forms.CheckBox();
  257. this.cbNeedsServiceElement = new System.Windows.Forms.CheckBox();
  258. this.cbCodeGenDialog = new System.Windows.Forms.CheckBox();
  259. this.wizardPageAlternativeXSDPaths = new WizardControl.WizardPage();
  260. this.xsdpathsListView = new Thinktecture.Tools.Web.Services.WsdlWizard.EditableListView();
  261. this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
  262. this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
  263. this.toolTipPath = new System.Windows.Forms.ToolTip(this.components);
  264. this.wsdlWizardCtrl.SuspendLayout();
  265. this.wizardPageBasicMetadata.SuspendLayout();
  266. this.wizardPageSchemaImports.SuspendLayout();
  267. this.groupBox2.SuspendLayout();
  268. this.wizardPageOperationsList.SuspendLayout();
  269. this.groupBox1.SuspendLayout();
  270. this.panel1.SuspendLayout();
  271. this.wizardPageMessageMapping.SuspendLayout();
  272. ((System.ComponentModel.ISupportInitialize)(this.ptvServiceOperations)).BeginInit();
  273. this.wizardPageAdditionalOptions.SuspendLayout();
  274. this.wizardPageAlternativeXSDPaths.SuspendLayout();
  275. this.SuspendLayout();
  276. //
  277. // wsdlWizardCtrl
  278. //
  279. this.wsdlWizardCtrl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  280. | System.Windows.Forms.AnchorStyles.Left)
  281. | System.Windows.Forms.AnchorStyles.Right)));
  282. this.wsdlWizardCtrl.BannerBitmap = ((System.Drawing.Image)(resources.GetObject("wsdlWizardCtrl.BannerBitmap")));
  283. this.wsdlWizardCtrl.CloseForm = false;
  284. this.wsdlWizardCtrl.Controls.Add(this.wizardPageBasicMetadata);
  285. this.wsdlWizardCtrl.Controls.Add(this.wizardPageSchemaImports);
  286. this.wsdlWizardCtrl.Controls.Add(this.wizardPageOperationsList);
  287. this.wsdlWizardCtrl.Controls.Add(this.wizardPageMessageMapping);
  288. this.wsdlWizardCtrl.Controls.Add(this.wizardPageAdditionalOptions);
  289. this.wsdlWizardCtrl.Controls.Add(this.wizardPageAlternativeXSDPaths);
  290. this.wsdlWizardCtrl.Location = new System.Drawing.Point(0, 0);
  291. this.wsdlWizardCtrl.Name = "wsdlWizardCtrl";
  292. this.wsdlWizardCtrl.Size = new System.Drawing.Size(497, 360);
  293. this.wsdlWizardCtrl.TabIndex = 0;
  294. this.wsdlWizardCtrl.Title = "Generate WSDL";
  295. this.wsdlWizardCtrl.WelcomeBitmap = ((System.Drawing.Image)(resources.GetObject("wsdlWizardCtrl.WelcomeBitmap")));
  296. this.wsdlWizardCtrl.WelcomeText = resources.GetString("wsdlWizardCtrl.WelcomeText");
  297. this.wsdlWizardCtrl.Load += new System.EventHandler(this.wsdlWizardCtrl_Load);
  298. this.wsdlWizardCtrl.Cancelled += new WizardControl.Wizard.CancelledEventHandler(this.wsdlWizardCtrl_Cancelled);
  299. this.wsdlWizardCtrl.BeforeSummaryPageDisplayed += new WizardControl.Wizard.BeforeSummaryPageDisplayedEventHandler(this.wsdlWizardCtrl_BeforeSummaryPageDisplayed);
  300. this.wsdlWizardCtrl.BeforePageDisplayed += new WizardControl.Wizard.BeforePageDisplayedEventHandler(this.wsdlWizardCtrl_BeforePageDisplayed);
  301. this.wsdlWizardCtrl.Finished += new WizardControl.Wizard.FinishedEventHandler(this.wsdlWizardCtrl_Finished);
  302. this.wsdlWizardCtrl.AfterPageDisplayed += new WizardControl.Wizard.AfterPageDisplayedEventHandler(this.wsdlWizardCtrl_AfterPageDisplayed);
  303. this.wsdlWizardCtrl.ValidatePage += new WizardControl.Wizard.ValidatePageEventHandler(this.wsdlWizardCtrl_ValidatePage);
  304. //
  305. // wizardPageBasicMetadata
  306. //
  307. this.wizardPageBasicMetadata.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  308. | System.Windows.Forms.AnchorStyles.Left)
  309. | System.Windows.Forms.AnchorStyles.Right)));
  310. this.wizardPageBasicMetadata.Controls.Add(this.tbServiceDoc);
  311. this.wizardPageBasicMetadata.Controls.Add(this.lblServiceDoc);
  312. this.wizardPageBasicMetadata.Controls.Add(this.lblNamespace);
  313. this.wizardPageBasicMetadata.Controls.Add(this.tbNamespace);
  314. this.wizardPageBasicMetadata.Controls.Add(this.lblServiceName);
  315. this.wizardPageBasicMetadata.Controls.Add(this.tbServiceName);
  316. this.wizardPageBasicMetadata.Description = "Please enter the name and the XML namespace of the Web Service.";
  317. this.wizardPageBasicMetadata.Heading = "Step 1: Specify your Web Service\'s basic settings";
  318. this.wizardPageBasicMetadata.Location = new System.Drawing.Point(21, 71);
  319. this.wizardPageBasicMetadata.Name = "wizardPageBasicMetadata";
  320. this.wizardPageBasicMetadata.Size = new System.Drawing.Size(456, 230);
  321. this.wizardPageBasicMetadata.TabIndex = 0;
  322. //
  323. // tbServiceDoc
  324. //
  325. this.tbServiceDoc.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  326. | System.Windows.Forms.AnchorStyles.Left)
  327. | System.Windows.Forms.AnchorStyles.Right)));
  328. this.tbServiceDoc.Location = new System.Drawing.Point(120, 72);
  329. this.tbServiceDoc.Multiline = true;
  330. this.tbServiceDoc.Name = "tbServiceDoc";
  331. this.tbServiceDoc.Size = new System.Drawing.Size(312, 88);
  332. this.tbServiceDoc.TabIndex = 5;
  333. //
  334. // lblServiceDoc
  335. //
  336. this.lblServiceDoc.Location = new System.Drawing.Point(24, 72);
  337. this.lblServiceDoc.Name = "lblServiceDoc";
  338. this.lblServiceDoc.Size = new System.Drawing.Size(100, 23);
  339. this.lblServiceDoc.TabIndex = 4;
  340. this.lblServiceDoc.Text = "Documentation:";
  341. //
  342. // lblNamespace
  343. //
  344. this.lblNamespace.Location = new System.Drawing.Point(24, 40);
  345. this.lblNamespace.Name = "lblNamespace";
  346. this.lblNamespace.Size = new System.Drawing.Size(96, 23);
  347. this.lblNamespace.TabIndex = 3;
  348. this.lblNamespace.Text = "XML namespace:";
  349. //
  350. // tbNamespace
  351. //
  352. this.tbNamespace.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  353. | System.Windows.Forms.AnchorStyles.Right)));
  354. this.tbNamespace.Location = new System.Drawing.Point(120, 40);
  355. this.tbNamespace.Name = "tbNamespace";
  356. this.tbNamespace.Size = new System.Drawing.Size(312, 20);
  357. this.tbNamespace.TabIndex = 2;
  358. //
  359. // lblServiceName
  360. //
  361. this.lblServiceName.Location = new System.Drawing.Point(24, 8);
  362. this.lblServiceName.Name = "lblServiceName";
  363. this.lblServiceName.Size = new System.Drawing.Size(88, 23);
  364. this.lblServiceName.TabIndex = 1;
  365. this.lblServiceName.Text = "Service name:";
  366. this.toolTip1.SetToolTip(this.lblServiceName, "\'Service name\' specifies the name of the Web Service binding to be generated. Thi" +
  367. "s will be the e.g. the class name for your Web Service proxy when generated from" +
  368. " the service description.");
  369. //
  370. // tbServiceName
  371. //
  372. this.tbServiceName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  373. | System.Windows.Forms.AnchorStyles.Right)));
  374. this.tbServiceName.Location = new System.Drawing.Point(120, 6);
  375. this.tbServiceName.Name = "tbServiceName";
  376. this.tbServiceName.Size = new System.Drawing.Size(312, 20);
  377. this.tbServiceName.TabIndex = 0;
  378. this.toolTip1.SetToolTip(this.tbServiceName, "\'Service name\' specifies the name of the Web Service binding to be generated. Thi" +
  379. "s will be the e.g. the class name for your Web Service proxy when generated from" +
  380. " the service description.");
  381. //
  382. // wizardPageSchemaImports
  383. //
  384. this.wizardPageSchemaImports.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  385. | System.Windows.Forms.AnchorStyles.Left)
  386. | System.Windows.Forms.AnchorStyles.Right)));
  387. this.wizardPageSchemaImports.Controls.Add(this.groupBox2);
  388. this.wizardPageSchemaImports.Cursor = System.Windows.Forms.Cursors.Default;
  389. this.wizardPageSchemaImports.Description = "Please add additional message schemas from XSD files as appropriate.";
  390. this.wizardPageSchemaImports.Heading = "Step 2: Specify additional message schemas";
  391. this.wizardPageSchemaImports.Location = new System.Drawing.Point(21, 71);
  392. this.wizardPageSchemaImports.Name = "wizardPageSchemaImports";
  393. this.wizardPageSchemaImports.Size = new System.Drawing.Size(456, 230);
  394. this.wizardPageSchemaImports.TabIndex = 2;
  395. //
  396. // groupBox2
  397. //
  398. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  399. | System.Windows.Forms.AnchorStyles.Left)
  400. | System.Windows.Forms.AnchorStyles.Right)));
  401. this.groupBox2.Controls.Add(this.llRemoveImport);
  402. this.groupBox2.Controls.Add(this.llAddImport);
  403. this.groupBox2.Controls.Add(this.importsListView);
  404. this.groupBox2.Location = new System.Drawing.Point(8, 3);
  405. this.groupBox2.Name = "groupBox2";
  406. this.groupBox2.Size = new System.Drawing.Size(440, 224);
  407. this.groupBox2.TabIndex = 2;
  408. this.groupBox2.TabStop = false;
  409. this.groupBox2.Text = "XSD Imports:";
  410. //
  411. // llRemoveImport
  412. //
  413. this.llRemoveImport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  414. this.llRemoveImport.Location = new System.Drawing.Point(95, 205);
  415. this.llRemoveImport.Name = "llRemoveImport";
  416. this.llRemoveImport.Size = new System.Drawing.Size(100, 16);
  417. this.llRemoveImport.TabIndex = 4;
  418. this.llRemoveImport.TabStop = true;
  419. this.llRemoveImport.Text = "Remove import";
  420. this.llRemoveImport.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llRemoveImport_LinkClicked);
  421. //
  422. // llAddImport
  423. //
  424. this.llAddImport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  425. this.llAddImport.Location = new System.Drawing.Point(8, 205);
  426. this.llAddImport.Name = "llAddImport";
  427. this.llAddImport.Size = new System.Drawing.Size(81, 15);
  428. this.llAddImport.TabIndex = 3;
  429. this.llAddImport.TabStop = true;
  430. this.llAddImport.Text = "Add import";
  431. this.llAddImport.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llAddImport_LinkClicked);
  432. //
  433. // importsListView
  434. //
  435. this.importsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  436. | System.Windows.Forms.AnchorStyles.Left)
  437. | System.Windows.Forms.AnchorStyles.Right)));
  438. this.importsListView.DisabledColumns = ((System.Collections.ArrayList)(resources.GetObject("importsListView.DisabledColumns")));
  439. this.importsListView.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  440. this.importsListView.FullRowSelect = true;
  441. this.importsListView.GridLines = true;
  442. this.importsListView.Location = new System.Drawing.Point(8, 16);
  443. this.importsListView.Name = "importsListView";
  444. this.importsListView.Size = new System.Drawing.Size(424, 184);
  445. this.importsListView.TabIndex = 2;
  446. this.importsListView.UseCompatibleStateImageBehavior = false;
  447. this.importsListView.View = System.Windows.Forms.View.Details;
  448. this.importsListView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.importsListView_MouseMove);
  449. //
  450. // wizardPageOperationsList
  451. //
  452. this.wizardPageOperationsList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  453. | System.Windows.Forms.AnchorStyles.Left)
  454. | System.Windows.Forms.AnchorStyles.Right)));
  455. this.wizardPageOperationsList.Controls.Add(this.groupBox1);
  456. this.wizardPageOperationsList.Controls.Add(this.panel1);
  457. this.wizardPageOperationsList.Description = "Please add operations to the Web Service as needed.";
  458. this.wizardPageOperationsList.Heading = "Step 3: Specify settings for your Web Service\'s operations.";
  459. this.wizardPageOperationsList.Location = new System.Drawing.Point(21, 71);
  460. this.wizardPageOperationsList.Name = "wizardPageOperationsList";
  461. this.wizardPageOperationsList.Size = new System.Drawing.Size(456, 230);
  462. this.wizardPageOperationsList.TabIndex = 1;
  463. //
  464. // groupBox1
  465. //
  466. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  467. | System.Windows.Forms.AnchorStyles.Left)
  468. | System.Windows.Forms.AnchorStyles.Right)));
  469. this.groupBox1.Controls.Add(this.operationsListView);
  470. this.groupBox1.Controls.Add(this.llAddOperation);
  471. this.groupBox1.Controls.Add(this.llRemoveOperation);
  472. this.groupBox1.Controls.Add(this.cbInfer);
  473. this.groupBox1.Location = new System.Drawing.Point(8, 3);
  474. this.groupBox1.Name = "groupBox1";
  475. this.groupBox1.Size = new System.Drawing.Size(440, 224);
  476. this.groupBox1.TabIndex = 4;
  477. this.groupBox1.TabStop = false;
  478. this.groupBox1.Text = "Operations:";
  479. //
  480. // operationsListView
  481. //
  482. this.operationsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  483. | System.Windows.Forms.AnchorStyles.Left)
  484. | System.Windows.Forms.AnchorStyles.Right)));
  485. this.operationsListView.DisabledColumns = ((System.Collections.ArrayList)(resources.GetObject("operationsListView.DisabledColumns")));
  486. this.operationsListView.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  487. this.operationsListView.FullRowSelect = true;
  488. this.operationsListView.GridLines = true;
  489. this.operationsListView.Location = new System.Drawing.Point(8, 16);
  490. this.operationsListView.Name = "operationsListView";
  491. this.operationsListView.Size = new System.Drawing.Size(424, 184);
  492. this.operationsListView.TabIndex = 0;
  493. this.operationsListView.UseCompatibleStateImageBehavior = false;
  494. this.operationsListView.View = System.Windows.Forms.View.Details;
  495. //
  496. // llAddOperation
  497. //
  498. this.llAddOperation.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  499. this.llAddOperation.Location = new System.Drawing.Point(7, 205);
  500. this.llAddOperation.Name = "llAddOperation";
  501. this.llAddOperation.Size = new System.Drawing.Size(81, 15);
  502. this.llAddOperation.TabIndex = 1;
  503. this.llAddOperation.TabStop = true;
  504. this.llAddOperation.Text = "Add operation";
  505. this.llAddOperation.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llAddItem_LinkClicked);
  506. //
  507. // llRemoveOperation
  508. //
  509. this.llRemoveOperation.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  510. this.llRemoveOperation.Location = new System.Drawing.Point(95, 205);
  511. this.llRemoveOperation.Name = "llRemoveOperation";
  512. this.llRemoveOperation.Size = new System.Drawing.Size(100, 16);
  513. this.llRemoveOperation.TabIndex = 2;
  514. this.llRemoveOperation.TabStop = true;
  515. this.llRemoveOperation.Text = "Remove operation";
  516. this.llRemoveOperation.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llRemoveItem_LinkClicked);
  517. //
  518. // cbInfer
  519. //
  520. this.cbInfer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  521. this.cbInfer.Location = new System.Drawing.Point(336, 204);
  522. this.cbInfer.Name = "cbInfer";
  523. this.cbInfer.Size = new System.Drawing.Size(104, 16);
  524. this.cbInfer.TabIndex = 4;
  525. this.cbInfer.Text = "Infer Operations";
  526. this.cbInfer.CheckedChanged += new System.EventHandler(this.cbInfer_CheckedChanged);
  527. //
  528. // panel1
  529. //
  530. this.panel1.Controls.Add(this.tbEdit);
  531. this.panel1.Controls.Add(this.cbMEPs);
  532. this.panel1.Location = new System.Drawing.Point(24, 32);
  533. this.panel1.Name = "panel1";
  534. this.panel1.Size = new System.Drawing.Size(408, 192);
  535. this.panel1.TabIndex = 2;
  536. //
  537. // tbEdit
  538. //
  539. this.tbEdit.Location = new System.Drawing.Point(16, 16);
  540. this.tbEdit.Name = "tbEdit";
  541. this.tbEdit.Size = new System.Drawing.Size(100, 20);
  542. this.tbEdit.TabIndex = 3;
  543. this.tbEdit.Text = "textBox2";
  544. this.tbEdit.Visible = false;
  545. //
  546. // cbMEPs
  547. //
  548. this.cbMEPs.ItemHeight = 13;
  549. this.cbMEPs.Items.AddRange(new object[] {
  550. "Request/Response",
  551. "One-Way"});
  552. this.cbMEPs.Location = new System.Drawing.Point(272, 16);
  553. this.cbMEPs.Name = "cbMEPs";
  554. this.cbMEPs.Size = new System.Drawing.Size(121, 21);
  555. this.cbMEPs.TabIndex = 2;
  556. this.cbMEPs.Text = "comboBox1";
  557. this.cbMEPs.Visible = false;
  558. //
  559. // wizardPageMessageMapping
  560. //
  561. this.wizardPageMessageMapping.Controls.Add(this.ptvServiceOperations);
  562. this.wizardPageMessageMapping.Description = "Please enter all details for the service\'s operations and messages.";
  563. this.wizardPageMessageMapping.Heading = "Step 4: Specify the operation\'s message parameters";
  564. this.wizardPageMessageMapping.Location = new System.Drawing.Point(21, 71);
  565. this.wizardPageMessageMapping.Name = "wizardPageMessageMapping";
  566. this.wizardPageMessageMapping.Size = new System.Drawing.Size(456, 230);
  567. this.wizardPageMessageMapping.TabIndex = 3;
  568. //
  569. // ptvServiceOperations
  570. //
  571. this.ptvServiceOperations.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  572. | System.Windows.Forms.AnchorStyles.Left)
  573. | System.Windows.Forms.AnchorStyles.Right)));
  574. this.ptvServiceOperations.ImageList = null;
  575. this.ptvServiceOperations.Indent = 19;
  576. this.ptvServiceOperations.Location = new System.Drawing.Point(0, -1);
  577. this.ptvServiceOperations.Name = "ptvServiceOperations";
  578. this.ptvServiceOperations.PaneHeaderVisible = false;
  579. this.ptvServiceOperations.SelectedImageIndex = -1;
  580. this.ptvServiceOperations.SelectedPaneNode = null;
  581. this.ptvServiceOperations.ShowLines = true;
  582. this.ptvServiceOperations.ShowPlusMinus = true;
  583. this.ptvServiceOperations.ShowRootLines = true;
  584. this.ptvServiceOperations.Size = new System.Drawing.Size(456, 232);
  585. this.ptvServiceOperations.SplitterColor = System.Drawing.SystemColors.AppWorkspace;
  586. this.ptvServiceOperations.SplitterLeft = 184;
  587. this.ptvServiceOperations.TabIndex = 1;
  588. //
  589. // wizardPageAdditionalOptions
  590. //
  591. this.wizardPageAdditionalOptions.Controls.Add(this.cbSoap12);
  592. this.wizardPageAdditionalOptions.Controls.Add(this.cbSoap11);
  593. this.wizardPageAdditionalOptions.Controls.Add(this.cbNeedsServiceElement);
  594. this.wizardPageAdditionalOptions.Controls.Add(this.cbCodeGenDialog);
  595. this.wizardPageAdditionalOptions.Description = "Please select any additional options to configure.";
  596. this.wizardPageAdditionalOptions.Heading = "Step 5: Additional options";
  597. this.wizardPageAdditionalOptions.Location = new System.Drawing.Point(21, 71);
  598. this.wizardPageAdditionalOptions.Name = "wizardPageAdditionalOptions";
  599. this.wizardPageAdditionalOptions.Size = new System.Drawing.Size(456, 230);
  600. this.wizardPageAdditionalOptions.TabIndex = 4;
  601. //
  602. // cbSoap12
  603. //
  604. this.cbSoap12.AutoSize = true;
  605. this.cbSoap12.Location = new System.Drawing.Point(24, 87);
  606. this.cbSoap12.Name = "cbSoap12";
  607. this.cbSoap12.Size = new System.Drawing.Size(144, 17);
  608. this.cbSoap12.TabIndex = 12;
  609. this.cbSoap12.Text = "Create SOAP 1.2 binding";
  610. this.cbSoap12.UseVisualStyleBackColor = true;
  611. //
  612. // cbSoap11
  613. //
  614. this.cbSoap11.AutoSize = true;
  615. this.cbSoap11.Checked = true;
  616. this.cbSoap11.CheckState = System.Windows.Forms.CheckState.Checked;
  617. this.cbSoap11.Enabled = false;
  618. this.cbSoap11.Location = new System.Drawing.Point(24, 51);
  619. this.cbSoap11.Name = "cbSoap11";
  620. this.cbSoap11.Size = new System.Drawing.Size(144, 17);
  621. this.cbSoap11.TabIndex = 11;
  622. this.cbSoap11.Text = "Create SOAP 1.1 binding";
  623. this.cbSoap11.UseVisualStyleBackColor = true;
  624. //
  625. // cbNeedsServiceElement
  626. //
  627. this.cbNeedsServiceElement.Location = new System.Drawing.Point(24, 8);
  628. this.cbNeedsServiceElement.Name = "cbNeedsServiceElement";
  629. this.cbNeedsServiceElement.Size = new System.Drawing.Size(192, 24);
  630. this.cbNeedsServiceElement.TabIndex = 10;
  631. this.cbNeedsServiceElement.Text = "Generate <service> element.";
  632. this.toolTip1.SetToolTip(this.cbNeedsServiceElement, "Enable this option if you want to have a <service> element generated for the WSDL" +
  633. " service description.");
  634. //
  635. // cbCodeGenDialog
  636. //
  637. this.cbCodeGenDialog.Location = new System.Drawing.Point(24, 169);
  638. this.cbCodeGenDialog.Name = "cbCodeGenDialog";
  639. this.cbCodeGenDialog.Size = new System.Drawing.Size(408, 24);
  640. this.cbCodeGenDialog.TabIndex = 6;
  641. this.cbCodeGenDialog.Text = "Open the code generation dialog after this wizard closes.";
  642. this.cbCodeGenDialog.CheckedChanged += new System.EventHandler(this.cbCodeGenDialog_CheckedChanged);
  643. //
  644. // wizardPageAlternativeXSDPaths
  645. //
  646. this.wizardPageAlternativeXSDPaths.Controls.Add(this.xsdpathsListView);
  647. this.wizardPageAlternativeXSDPaths.Description = "Please select the alternative XSD path for each XSD file imported.";
  648. this.wizardPageAlternativeXSDPaths.Heading = "Step 6: Alternative XSD Paths";
  649. this.wizardPageAlternativeXSDPaths.Location = new System.Drawing.Point(21, 71);
  650. this.wizardPageAlternativeXSDPaths.Name = "wizardPageAlternativeXSDPaths";
  651. this.wizardPageAlternativeXSDPaths.Size = new System.Drawing.Size(456, 230);
  652. this.wizardPageAlternativeXSDPaths.TabIndex = 5;
  653. //
  654. // xsdpathsListView
  655. //
  656. this.xsdpathsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  657. | System.Windows.Forms.AnchorStyles.Left)
  658. | System.Windows.Forms.AnchorStyles.Right)));
  659. this.xsdpathsListView.DisabledColumns = ((System.Collections.ArrayList)(resources.GetObject("xsdpathsListView.DisabledColumns")));
  660. this.xsdpathsListView.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  661. this.xsdpathsListView.FullRowSelect = true;
  662. this.xsdpathsListView.GridLines = true;
  663. this.xsdpathsListView.Location = new System.Drawing.Point(0, 0);
  664. this.xsdpathsListView.Name = "xsdpathsListView";
  665. this.xsdpathsListView.Size = new System.Drawing.Size(456, 224);
  666. this.xsdpathsListView.TabIndex = 3;
  667. this.xsdpathsListView.UseCompatibleStateImageBehavior = false;
  668. this.xsdpathsListView.View = System.Windows.Forms.View.Details;
  669. //
  670. // openFileDialog1
  671. //
  672. this.openFileDialog1.Filter = "XSD Files(*.xsd)|*.xsd";
  673. //
  674. // toolTipPath
  675. //
  676. this.toolTipPath.AutomaticDelay = 1000;
  677. //
  678. // WsdlWizardForm
  679. //
  680. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  681. this.ClientSize = new System.Drawing.Size(497, 360);
  682. this.Controls.Add(this.wsdlWizardCtrl);
  683. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  684. this.HelpButton = true;
  685. this.Name = "WsdlWizardForm";
  686. this.ShowInTaskbar = false;
  687. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  688. this.Text = "Create a WSDL Interface Description";
  689. this.Load += new System.EventHandler(this.WSDLWizard_Load);
  690. this.Closing += new System.ComponentModel.CancelEventHandler(this.WsdlWizardForm_Closing);
  691. this.wsdlWizardCtrl.ResumeLayout(false);
  692. this.wizardPageBasicMetadata.ResumeLayout(false);
  693. this.wizardPageBasicMetadata.PerformLayout();
  694. this.wizardPageSchemaImports.ResumeLayout(false);
  695. this.groupBox2.ResumeLayout(false);
  696. this.wizardPageOperationsList.ResumeLayout(false);
  697. this.groupBox1.ResumeLayout(false);
  698. this.panel1.ResumeLayout(false);
  699. this.panel1.PerformLayout();
  700. this.wizardPageMessageMapping.ResumeLayout(false);
  701. ((System.ComponentModel.ISupportInitialize)(this.ptvServiceOperations)).EndInit();
  702. this.wizardPageAdditionalOptions.ResumeLayout(false);
  703. this.wizardPageAdditionalOptions.PerformLayout();
  704. this.wizardPageAlternativeXSDPaths.ResumeLayout(false);
  705. this.ResumeLayout(false);
  706. }
  707. #endregion
  708. #region Event handlers
  709. /// <summary>
  710. /// Adds an operation to the operationsListView.
  711. /// </summary>
  712. /// <param name="sender">The source of the event.</param>
  713. /// <param name="e">An instance of <see cref="LinkLabelLinkClickedEventArgs"/> class with Event data.</param>
  714. private void llAddItem_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  715. {
  716. ListViewItem listViewItem1 =
  717. new ListViewItem(new string[] {
  718. "Operation" + operationCount,
  719. "Request/Response",
  720. "",
  721. ""},
  722. -1);
  723. operationsListView.Items.AddRange(
  724. new ListViewItem[] {listViewItem1});
  725. operationCount++;
  726. }
  727. /// <summary>
  728. /// Removes an operation from the operationsListView.
  729. /// </summary>
  730. /// <param name="sender">The source of the event.</param>
  731. /// <param name="e">An instance of <see cref="LinkLabelLinkClickedEventArgs"/> class with Event data.</param>
  732. /// <remarks>
  733. /// This method will remove the first item of the selected items collection. If no item is selected then
  734. /// it removes the last item available in the list.
  735. /// </remarks>
  736. private void llRemoveItem_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  737. {
  738. if(operationsListView.Items.Count > 0)
  739. {
  740. // Remove the first item of the selected items.
  741. if(operationsListView.SelectedItems.Count > 0)
  742. {
  743. while (operationsListView.SelectedItems.Count != 0)
  744. {
  745. ListViewItem lvi = operationsListView.SelectedItems[0];
  746. operationsListView.Items.Remove(lvi);
  747. }
  748. }
  749. else
  750. {
  751. // If anything is not selected, remove the last item on the list.
  752. operationsListView.Items.RemoveAt(operationsListView.Items.Count - 1);
  753. operationCount--;
  754. }
  755. }
  756. }
  757. /// <summary>
  758. /// Performs the necessary initialization when the wizard control loads.
  759. /// </summary>
  760. /// <param name="sender">The source of the event.</param>
  761. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  762. private void wsdlWizardCtrl_Load(object sender, EventArgs e)
  763. {
  764. // Add the columns to the operationsListView.
  765. operationsListView.Columns.Add("Operation Name", 210, HorizontalAlignment.Left);
  766. operationsListView.Columns.Add("Message Exchange Pattern", -2, HorizontalAlignment.Left);
  767. // Add the columns to the importsListView.
  768. importsListView.Columns.Add("File Name", 210, HorizontalAlignment.Left);
  769. importsListView.Columns.Add("Location", -1, HorizontalAlignment.Left);
  770. // Set the non editable columns.
  771. importsListView.DisabledColumns.Add("File Name");
  772. importsListView.DisabledColumns.Add("Location");
  773. // Add the columns to the xsdpathsListView.
  774. xsdpathsListView.Columns.Add("File Name", 210, HorizontalAlignment.Left);
  775. xsdpathsListView.Columns.Add("Alternative Path", -2, HorizontalAlignment.Left);
  776. // Set the non editable columns.
  777. xsdpathsListView.DisabledColumns.Add("File Name");
  778. // Load the default XSD to the schema imports list.
  779. string fname = schemaLocation.Substring(schemaLocation.LastIndexOf("\\") + 1);
  780. ListViewItem defaultLocation = new ListViewItem();
  781. defaultLocation.Text = fname;
  782. defaultLocation.SubItems.Add(schemaLocation);
  783. importsListView.Items.Add(defaultLocation);
  784. // Skip the wizard welcome page if the round tripping is on.
  785. if(RoundtripMode == true)
  786. {
  787. wsdlWizardCtrl.AdvancePage();
  788. tbNamespace.Enabled = false;
  789. }
  790. // Focus the first tbServiceName text box.
  791. tbServiceName.Focus();
  792. // Assign the cancel button.
  793. this.CancelButton = wsdlWizardCtrl.CancelButton;
  794. }
  795. /// <summary>
  796. /// Asks the confirmation question and quits the wizard upon the click of the "Cancel" button.
  797. /// </summary>
  798. /// <param name="sender">The source of the event.</param>
  799. /// <param name="e">An instance of <see cref="EventArgs"/> class with the event data.</param>
  800. private void wsdlWizardCtrl_Cancelled(object sender, EventArgs e)
  801. {
  802. /*
  803. if(MessageBox.Show("Do you really want to quit?",
  804. "WSDL Wizard", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  805. {
  806. alreadyCancelled = true;
  807. this.Close();
  808. }
  809. */
  810. }
  811. /// <summary>
  812. /// Performs the actions, when the wizard's "Finish" button is clicked.
  813. /// </summary>
  814. /// <param name="sender">The source of the event.</param>
  815. /// <param name="e">An instance of <see cref="EventArgs"/> class with the event data.</param>
  816. /// <remarks>
  817. /// This method finally wraps up the necessary details and calls the
  818. /// <see cref="ServiceDescriptionEngine"/> class to generate the WSDL file.
  819. /// </remarks>
  820. private void wsdlWizardCtrl_Finished(object sender, EventArgs e)
  821. {
  822. try
  823. {
  824. // Set additional options for WSDL generation.
  825. serviceInterfaceContract.NeedsServiceElement =
  826. cbNeedsServiceElement.Checked;
  827. if (cbSoap11.Checked)
  828. {
  829. serviceInterfaceContract.Bindings |= InterfaceContract.SoapBindings.Soap11;
  830. }
  831. if (cbSoap12.Checked)
  832. {
  833. serviceInterfaceContract.Bindings |= InterfaceContract.SoapBindings.Soap12;
  834. }
  835. // Use alternative location for imports by default.
  836. serviceInterfaceContract.UseAlternateLocationForImports = true;
  837. // Call the GenerateWSDL method according to the round tripping mode.
  838. if(this.roundtripMode)
  839. {
  840. wsdlLocation = ServiceDescriptionEngine.GenerateWsdl(serviceInterfaceContract,
  841. wsdlLocation, GetXmlCommentForWSDL(), this.wsdlFile);
  842. }
  843. else
  844. {
  845. wsdlLocation = ServiceDescriptionEngine.GenerateWsdl(serviceInterfaceContract,
  846. wsdlLocation, GetXmlCommentForWSDL());
  847. }
  848. this.DialogResult = DialogResult.OK;
  849. alreadyCancelled = true;
  850. this.Close();
  851. }
  852. catch(WsdlGenerationException ex)
  853. {
  854. MessageBox.Show("An error occured while generating WSDL: " + ex.Message, "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
  855. }
  856. catch(Exception generalException)
  857. {
  858. MessageBox.Show("An error occured while generating WSDL: " + generalException.Message, "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
  859. }
  860. }
  861. /// <summary>
  862. /// Performs the actions prior to displaying each page on the wizard control.
  863. /// </summary>
  864. /// <param name="sender">The source of the event.</param>
  865. /// <param name="e">An instance of <see cref="WizardPageDisplayedEventArgs"/> class with event data.</param>
  866. private void wsdlWizardCtrl_BeforePageDisplayed(object sender, WizardPageDisplayedEventArgs e)
  867. {
  868. // Assign the basic meta data values to the instance of InterfaceContract class.
  869. if (e.Page == wizardPageSchemaImports)
  870. {
  871. // 07-23-2005
  872. // BDS: Added this gate to validate the namespace uri.
  873. Uri uri;
  874. try
  875. {
  876. if (tbNamespace.Text.IndexOf(":") > -1 || Path.IsPathRooted(tbNamespace.Text))
  877. {
  878. uri = new Uri(tbNamespace.Text);
  879. }
  880. else
  881. {
  882. uri = new Uri("anyuri:" + tbNamespace.Text);
  883. }
  884. }
  885. catch
  886. {
  887. MessageBox.Show(this,
  888. "Invalid uri for the namespace. Enter a valid uri and try again.",
  889. "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
  890. e.Cancel = true;
  891. return;
  892. }
  893. serviceInterfaceContract.ServiceName = tbServiceName.Text;
  894. serviceInterfaceContract.ServiceNamespace = tbNamespace.Text;
  895. serviceInterfaceContract.SchemaNamespace = schemaNamespace;
  896. serviceInterfaceContract.ServiceDocumentation = tbServiceDoc.Text;
  897. return;
  898. }
  899. if (e.Page == wizardPageOperationsList)
  900. {
  901. // Clear the existing items.
  902. this.messageSchemas.Clear();
  903. this.headerSchemas.Clear();
  904. faultSchemas.Clear();
  905. this.importedSchemaNamespaces.Clear();
  906. this.serviceInterfaceContract.Imports.Clear();
  907. // Add the selected schemas to the ServiceInterfaceContract.Imports collection.
  908. foreach (ListViewItem importItem in importsListView.Items)
  909. {
  910. string schemaNamespace = string.Empty;
  911. string importLocation = importItem.SubItems[1].Text;
  912. ArrayList result;
  913. try
  914. {
  915. // Read the content of the imported files and add them to the local arrays for UI.
  916. result = ServiceDescriptionEngine.GetSchemasFromXsd(importLocation, out schemaNamespace);
  917. }
  918. catch(Exception ex)
  919. {
  920. MessageBox.Show(this, ex.Message,
  921. "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
  922. e.Cancel = true;
  923. return;
  924. }
  925. // Check whether the schema has a valid namespace.
  926. //if (schemaNamespace == null)
  927. //{
  928. // MessageBox.Show(this, "Could not import the file: " +
  929. // importLocation + ". The schema definition does not belong to a valid namespace.",
  930. // "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
  931. // wsdlWizardCtrl.JumpToPage(2);
  932. // return;
  933. //}
  934. //// Check whether the Namespace already exists in the list.
  935. //if (this.importedSchemaNamespaces.IndexOf(schemaNamespace.ToLower()) > -1)
  936. //{
  937. // MessageBox.Show(this, "Could not import the file: " +
  938. // importLocation + ". The Target Namespace already imported.",
  939. // "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
  940. // wsdlWizardCtrl.JumpToPage(2);
  941. // return;
  942. //}
  943. //else
  944. //{
  945. if(schemaNamespace != null)
  946. this.importedSchemaNamespaces.Add(schemaNamespace.ToLower());
  947. //}
  948. messageSchemas.AddRange((SchemaElements)result[1]);
  949. headerSchemas.AddRange((SchemaElements)result[1]);
  950. faultSchemas.AddRange((SchemaElements)result[1]);
  951. SchemaImport si = new SchemaImport(importItem.SubItems[1].Text, schemaNamespace, importItem.SubItems[0].Text);
  952. // Check whether the schema is in the current directory.
  953. if (Directory.GetFiles(this.wsdlLocation, si.SchemaName).Length > 0)
  954. {
  955. si.AlternateLocation = si.SchemaName;
  956. }
  957. else if (si.SchemaLocation.ToLower().StartsWith(this.projectRootDirectory.ToLower()))
  958. {
  959. string schemaDirectory = si.SchemaLocation.Substring(
  960. 0, si.SchemaLocation.LastIndexOf('\\'));
  961. string currentDirectory = wsdlLocation;
  962. // Remove the project root before passing them to the relative path finder.
  963. schemaDirectory = schemaDirectory.Substring(this.projectRootDirectory.Length);
  964. currentDirectory = currentDirectory.Substring(this.projectRootDirectory.Length);
  965. si.AlternateLocation = IOPathHelper.GetRelativePath(schemaDirectory, currentDirectory);
  966. if (si.AlternateLocation.EndsWith("/"))
  967. {
  968. si.AlternateLocation = si.AlternateLocation + si.SchemaName;
  969. }
  970. else
  971. {
  972. si.AlternateLocation = si.AlternateLocation + "/" + si.SchemaName;
  973. }
  974. }
  975. else
  976. {
  977. si.AlternateLocation = si.SchemaLocation;
  978. }
  979. serviceInterfaceContract.Imports.Add(si);
  980. }
  981. // Import the embedded types.
  982. ImportEmbeddedTypes();
  983. // Check for the messages count found in the imported files and alert the user if no messages
  984. // are found.
  985. if (messageSchemas.Count < 1)
  986. {
  987. MessageBox.Show("There are no elements in this XSD to use as operation messages.",
  988. "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  989. e.Cancel = true;
  990. return;
  991. }
  992. return;
  993. }
  994. if (e.Page == wizardPageMessageMapping)
  995. {
  996. try
  997. {
  998. // Setup the dynamic UI controls for the operation - message mapping UI.
  999. SetupOperationsMessagesPanes();
  1000. if (ptvServiceOperations.PaneNodes.Count > 0)
  1001. {
  1002. ptvServiceOperations.SelectedPaneNode = ptvServiceOperations.PaneNodes[0];
  1003. ptvServiceOperations.PaneNodes[0].Expanded = true;
  1004. }
  1005. }
  1006. catch (Exception ex)
  1007. {
  1008. MessageBox.Show(ex.Message);
  1009. }
  1010. return;
  1011. }
  1012. if (e.Page == wizardPageAdditionalOptions)
  1013. {
  1014. cbCodeGenDialog.Checked = this.roundtripMode;
  1015. return;
  1016. }
  1017. if (e.Page == wizardPageAlternativeXSDPaths)
  1018. {
  1019. xsdpathsListView.Items.Clear();
  1020. if (serviceInterfaceContract.Imports.Count > 0)
  1021. {
  1022. foreach (SchemaImport import in serviceInterfaceContract.Imports)
  1023. {
  1024. ListViewItem li = new ListViewItem(import.SchemaName);
  1025. li.SubItems.Add(import.AlternateLocation);
  1026. xsdpathsListView.Items.Add(li);
  1027. }
  1028. }
  1029. else
  1030. {
  1031. wsdlWizardCtrl.AdvancePage();
  1032. }
  1033. return;
  1034. }
  1035. }
  1036. /// <summary>
  1037. /// Handles the SelectedIndexChanged event of the dynamically created combo box.
  1038. /// </summary>
  1039. /// <param name="sender">The source of the event.</param>
  1040. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  1041. /// <remarks>This method changes the selected operation's in/out message parameters to the
  1042. /// newly selected values.</remarks>
  1043. private void DynamicComboBox_SelectedIndexChanged(object sender, EventArgs e)
  1044. {
  1045. ComboBox currentCombo = sender as ComboBox;
  1046. // Check whether the dynamic combo belongs to an inbound message or an outbound message.
  1047. if(currentCombo.Name.StartsWith("inMessageParamsCombo"))
  1048. {
  1049. string tail = currentCombo.Name.Substring(20);
  1050. int index = int.Parse(tail);
  1051. // Select the corresponding operation for the selected message.
  1052. Operation currentOperation = serviceInterfaceContract.OperationsCollection[index];
  1053. // Change the input message of the operation.
  1054. currentOperation.Input.Element = messageSchemas[currentCombo.SelectedIndex];
  1055. }
  1056. else if(currentCombo.Name.StartsWith("outMessageParamsCombo"))
  1057. {
  1058. string tail = currentCombo.Name.Substring(21);
  1059. int index = int.Parse(tail);
  1060. // Select the corresponding operation for the selected message.
  1061. Operation currentOperation = serviceInterfaceContract.OperationsCollection[index];
  1062. // Change the input message of the operation.
  1063. currentOperation.Output.Element = messageSchemas[currentCombo.SelectedIndex];
  1064. }
  1065. // this is a hack to 'convince' the combo box that the Text property has changed - don't ask! ...
  1066. ((ComboBox)sender).Text = "42";
  1067. }
  1068. /// <summary>
  1069. /// Performs the actions on loading the WSDL wizard.
  1070. /// </summary>
  1071. /// <param name="sender">Source of the event.</param>
  1072. /// <param name="e">An instance of <see cref="EventArgs"/> class with the event data.</param>
  1073. /// <remarks>If the round tripping mode is on, this method imports the data from the existing
  1074. /// WSDL file to the UI.</remarks>
  1075. private void WSDLWizard_Load(object sender, EventArgs e)
  1076. {
  1077. ptvServiceOperations.PaneHeaderVisible = true;
  1078. // If the round tripping mode is on then import the data from the existing WSDL to the UI.
  1079. if(this.roundtripMode)
  1080. {
  1081. if(importedContract.IsHttpBinding)
  1082. {
  1083. if(MessageBox.Show(this,
  1084. "This WSDL contains an HTTP binding. It will be converted to a SOAP binding.\nAre you sure you want to perform this action?",
  1085. "WSDL Wizard", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) ==
  1086. DialogResult.Cancel)
  1087. {
  1088. this.DialogResult = DialogResult.Cancel;
  1089. this.Close();
  1090. }
  1091. }
  1092. ImportBasicServiceMetaData();
  1093. if(!ImportSchemaImports())
  1094. {
  1095. this.DialogResult = DialogResult.Retry;
  1096. this.Close();
  1097. return;
  1098. }
  1099. ImportOperations();
  1100. ImportAdditionalOptions();
  1101. ImportEmbeddedTypes();
  1102. }
  1103. }
  1104. /// <summary>
  1105. /// Performs the actions before the summery page is loaded.
  1106. /// </summary>
  1107. /// <param name="sender">Source of the event.</param>
  1108. /// <param name="e">An instance of <see cref="WizardPageSummaryEventArgs"/> with event data.</param>
  1109. private void wsdlWizardCtrl_BeforeSummaryPageDisplayed(object sender, WizardPageSummaryEventArgs e)
  1110. {
  1111. openCodeGenDialog = cbCodeGenDialog.Checked;
  1112. // Assign the modified alternative Xsd paths.
  1113. foreach(ListViewItem li in xsdpathsListView.Items)
  1114. {
  1115. serviceInterfaceContract.Imports[li.Index].AlternateLocation =
  1116. li.SubItems[1].Text;
  1117. }
  1118. }
  1119. /// <summary>
  1120. /// Performs the validation before navigating to another page on the wizard control.
  1121. /// </summary>
  1122. /// <param name="sender">Source of the event.</param>
  1123. /// <param name="e">An instance of <see cref="WizardPageSummaryEventArgs"/> with event data.</param>
  1124. private void wsdlWizardCtrl_ValidatePage(object sender, WizardPageValidateEventArgs e)
  1125. {
  1126. // Validate the basic metadata.
  1127. if(e.Page == wizardPageBasicMetadata)
  1128. {
  1129. if(tbServiceName.Text.Length == 0 || tbNamespace.Text.Length == 0)
  1130. {
  1131. MessageBox.Show("Please enter valid values.", "WSDL Wizard", MessageBoxButtons.OK,
  1132. MessageBoxIcon.Exclamation);
  1133. e.NextPage = 1;
  1134. }
  1135. }
  1136. // Validate the operations list.
  1137. if(e.Page == wizardPageOperationsList)
  1138. {
  1139. if(operationsListView.Items.Count == 0)
  1140. {
  1141. MessageBox.Show("Please specify any operations.", "WSDL Wizard", MessageBoxButtons.OK,
  1142. MessageBoxIcon.Exclamation);
  1143. e.NextPage = 3;
  1144. }
  1145. }
  1146. // Validate the imported schemas list.
  1147. if(e.Page == wizardPageSchemaImports)
  1148. {
  1149. if(messageSchemas.Count == 0 && importsListView.Items.Count == 0)
  1150. {
  1151. MessageBox.Show("Please add at least one XSD file.", "WSDL Wizard", MessageBoxButtons.OK,
  1152. MessageBoxIcon.Exclamation);
  1153. e.NextPage = 2;
  1154. }
  1155. }
  1156. // Validate the message mapping page.
  1157. if (e.Page == wizardPageMessageMapping)
  1158. {
  1159. bool namelessFaultsFound = serviceInterfaceContract.OperationsCollection.OfType<Operation>()
  1160. .SelectMany(operation => operation.Faults)
  1161. .Where(fault => string.IsNullOrEmpty(fault.Name))
  1162. .Any();
  1163. if (namelessFaultsFound)
  1164. {
  1165. MessageBox.Show("Please provide a name for all fault messages.", "WSDL Wizard", MessageBoxButtons.OK,
  1166. MessageBoxIcon.Exclamation);
  1167. e.NextPage = 4;
  1168. return;
  1169. }
  1170. bool duplicateFaultForOperationFound = false;
  1171. foreach (Operation operation in serviceInterfaceContract.OperationsCollection)
  1172. {
  1173. duplicateFaultForOperationFound |= operation.Faults
  1174. .GroupBy(fault => fault.Name)
  1175. .Where(grouping => grouping.Count() > 1)
  1176. .Any();
  1177. }
  1178. if (duplicateFaultForOperationFound)
  1179. {
  1180. MessageBox.Show("Please ensure that all fault messages for an operation have been given a unique name.", "WSDL Wizard", MessageBoxButtons.OK,
  1181. MessageBoxIcon.Exclamation);
  1182. e.NextPage = 4;
  1183. }
  1184. }
  1185. }
  1186. /// <summary>
  1187. /// Performs the actions after displaying a wizard page.
  1188. /// </summary>
  1189. /// <param name="sender">The source of the event.</param>
  1190. /// <param name="e">An instance of <see cref="WizardPageEventArgs"/> with event data.</param>
  1191. private void wsdlWizardCtrl_AfterPageDisplayed(object sender, WizardPageEventArgs e)
  1192. {
  1193. if(e.Page == wizardPageBasicMetadata)
  1194. {
  1195. tbServiceName.Focus();
  1196. return;
  1197. }
  1198. if(e.Page == wizardPageAdditionalOptions)
  1199. {
  1200. if(ptvServiceOperations.PaneNodes.Count > 0)
  1201. ptvServiceOperations.SelectedPaneNode = ptvServiceOperations.PaneNodes[0];
  1202. }
  1203. }
  1204. /// <summary>
  1205. /// Performs the actions upon closing the main wizard form.
  1206. /// </summary>
  1207. /// <param name="sender">The source of the event.</param>
  1208. /// <param name="e">An instance of <see cref="CancelEventArgs"/> with event data.</param>
  1209. /// <remarks>This method shows the confirmation dialog box , if the form is closed using the "Close" button.</remarks>
  1210. private void WsdlWizardForm_Closing(object sender, CancelEventArgs e)
  1211. {
  1212. if(!alreadyCancelled)
  1213. {
  1214. if (MessageBox.Show("Do you really want to quit?",
  1215. "WSDL Wizard", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  1216. {
  1217. e.Cancel = true;
  1218. }
  1219. }
  1220. }
  1221. /// <summary>
  1222. /// Performs the actions after clicking the "llAddImport" link label.
  1223. /// </summary>
  1224. /// <param name="sender">The source of the event.</param>
  1225. /// <param name="e">An instance of <see cref="LinkLabelLinkClickedEventArgs"/> class with event data.</param>
  1226. /// <remarks>This allows the user to select the XSD files using a file open dialog box and add them
  1227. /// to the importsListView control.</remarks>
  1228. private void llAddImport_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
  1229. {
  1230. // Set the default location and the filter for the .xsd files.
  1231. openFileDialog1.InitialDirectory = this.currentFolder;
  1232. openFileDialog1.Filter = "XSD Files(*.xsd)|*.xsd";
  1233. if(openFileDialog1.ShowDialog() == DialogResult.OK)
  1234. {
  1235. // Check whether the current item exists on the importsListView and add it to the list if it's not.
  1236. string fname = string.Empty;
  1237. fname = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
  1238. ListViewItem li = new ListViewItem(fname);
  1239. li.SubItems.Add(openFileDialog1.FileName);
  1240. // Change the location of the XSD if it already exists on the list.
  1241. foreach(ListViewItem eli in importsListView.Items)
  1242. {
  1243. if(eli.Text.ToLower() == li.Text.ToLower())
  1244. {
  1245. eli.SubItems[1].Text = openFileDialog1.FileName;
  1246. return;
  1247. }
  1248. }
  1249. importsListView.Items.Add(li);
  1250. }
  1251. }
  1252. /// <summary>
  1253. /// Performs the actions after clicking the llRemoveImport link label.
  1254. /// </summary>
  1255. /// <param name="sender">The source of the event.</param>
  1256. /// <param name="e">An instance of <see cref="LinkLabelLinkClickedEventArgs"/> with event data.</param>
  1257. /// <remarks>This action removes the items from the importsListView control.</remarks>
  1258. private void llRemoveImport_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
  1259. {
  1260. // Delete the selected items.
  1261. while(importsListView.SelectedItems.Count != 0)
  1262. {
  1263. importsListView.SelectedItems[0].Remove();
  1264. }
  1265. }
  1266. /// <summary>
  1267. /// Displays a tool tip about the list item underneath the mouse pointer.
  1268. /// </summary>
  1269. /// <param name="sender">The source of the event.</param>
  1270. /// <param name="e">An instance of <see cref="MouseEventArgs"/> class with event data.</param>
  1271. private void importsListView_MouseMove(object sender,
  1272. System.Windows.Forms.MouseEventArgs e)
  1273. {
  1274. ListViewItem li = importsListView.GetItemAt(e.X,e.Y);
  1275. if(li == null)
  1276. {
  1277. toolTipPath.Active = false;
  1278. }
  1279. else
  1280. {
  1281. toolTipPath.Active = true;
  1282. toolTipPath.SetToolTip(importsListView,li.SubItems[1].Text);
  1283. }
  1284. }
  1285. #endregion
  1286. #region Private methods.
  1287. private void addFaultMessage_Clicked(object sender, EventArgs e)
  1288. {
  1289. ptvServiceOperations.SuspendLayout();
  1290. PaneNode operationNode = ptvServiceOperations.SelectedPaneNode;
  1291. Operation selectedOperation = serviceInterfaceContract.OperationsCollection
  1292. .Cast<Operation>()
  1293. .FirstOrDefault(operation => operation.Name == (string)operationNode.PropertyPane.Tag);
  1294. if (selectedOperation == null) return;
  1295. string name = "Fault" + (selectedOperation.Faults.Count() + 1);
  1296. Message faultMessage = new Message {Name = name, Element = new SchemaElement()};
  1297. ptvServiceOperations.SelectedPaneNode = AddFaultPropertyPane(operationNode, selectedOperation, faultMessage);
  1298. ptvServiceOperations.ResumeLayout(true);
  1299. }
  1300. private PaneNode AddFaultPropertyPane(PaneNode operationNode, Operation selectedOperation, Message faultMessage)
  1301. {
  1302. selectedOperation.Faults.Add(faultMessage);
  1303. string guid = Guid.NewGuid().ToString();
  1304. PropertyPane propPaneFaultMessage = new PropertyPane();
  1305. propPaneFaultMessage.Name = "propPaneFault" + guid;
  1306. propPaneFaultMessage.Text = "Fault " + faultMessage.Name;
  1307. propPaneFaultMessage.Tag = selectedOperation.Name + "Fault";
  1308. // Setup dynamic GUI controls for the pane - FaultMessage
  1309. Label faultMessageParameterLabel = new Label();
  1310. faultMessageParameterLabel.Location = new Point(6, 5);
  1311. faultMessageParameterLabel.Name = "faultMessageParameterLabel" + guid;
  1312. faultMessageParameterLabel.Size = new Size(55, 33);
  1313. faultMessageParameterLabel.Text = "Message body:";
  1314. faultMessageParameterLabel.TabIndex = 0;
  1315. ComboBox faultMessageParamsCombo = new ComboBox();
  1316. faultMessageParamsCombo.DropDownStyle = ComboBoxStyle.DropDownList;
  1317. faultMessageParamsCombo.Location = new Point(65, 5);
  1318. faultMessageParamsCombo.Name = "faultMessageParamsCombo" + guid;
  1319. faultMessageParamsCombo.Size = new Size(80, 21);
  1320. faultMessageParamsCombo.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
  1321. faultMessageParamsCombo.Tag = selectedOperation;
  1322. faultMessageParamsCombo.TabIndex = 1;
  1323. Label faultMessageNameLabel = new Label();
  1324. faultMessageNameLabel.Location = new Point(6, 48);
  1325. faultMessageNameLabel.Name = "faultMessageNameLabel" + guid;
  1326. faultMessageNameLabel.Text = "Message name:";
  1327. faultMessageNameLabel.AutoSize = true;
  1328. TextBox faultMessageNameTextBox = new TextBox();
  1329. faultMessageNameTextBox.Location = new Point(8, 69);
  1330. faultMessageNameTextBox.Name = "faultMessageNameTextBox" + guid;
  1331. faultMessageNameTextBox.Size = new Size(142, 20);
  1332. faultMessageNameTextBox.Text = faultMessage.Name;
  1333. faultMessageNameTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
  1334. faultMessageNameTextBox.DataBindings.Add("Text", faultMessage, "Name");
  1335. faultMessageNameTextBox.TextChanged += (o, s) => propPaneFaultMessage.Text = "Fault " + faultMessageNameTextBox.Text;
  1336. faultMessageNameTextBox.TabIndex = 2;
  1337. foreach (SchemaElement schemaElement in faultSchemas)
  1338. {
  1339. faultMessageParamsCombo.Items.Add(schemaElement);
  1340. }
  1341. if (faultMessageParamsCombo.Items.Count > 0)
  1342. {
  1343. faultMessageParamsCombo.SelectedIndex = 0;
  1344. }
  1345. faultMessageParamsCombo.DisplayMember = "ElementName";
  1346. if (!string.IsNullOrEmpty(faultMessage.Element.ElementName))
  1347. {
  1348. faultMessageParamsCombo.SelectedItem = faultMessage.Element;
  1349. }
  1350. faultMessageParamsCombo.SelectedIndexChanged += (o, s) =>
  1351. {
  1352. faultMessage.Element = (SchemaElement)faultMessageParamsCombo.SelectedItem;
  1353. };
  1354. LinkLabel faultRemoveLink = new LinkLabel();
  1355. faultRemoveLink.Location = new Point(6, 100);
  1356. faultRemoveLink.Text = "Remove Fault Message";
  1357. faultRemoveLink.AutoSize = true;
  1358. faultRemoveLink.TabIndex = 3;
  1359. Label faultDocLabel = new Label();
  1360. faultDocLabel.Location = new Point(6, 125);
  1361. faultDocLabel.Name = "faultDocLabel" + guid;
  1362. faultDocLabel.Size = new Size(88, 23);
  1363. faultDocLabel.Text = "Documentation:";
  1364. faultDocLabel.TabIndex = 4;
  1365. TextBox faultDocTextBox = new TextBox();
  1366. faultDocTextBox.Location = new Point(8, 144);
  1367. faultDocTextBox.Text = faultMessage.Documentation;
  1368. faultDocTextBox.Multiline = true;
  1369. faultDocTextBox.Name = "faultDocTextBox" + guid;
  1370. faultDocTextBox.Size = new Size(142, 0);
  1371. faultDocTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
  1372. faultDocTextBox.DataBindings.Add("Text", faultMessage, "Documentation");
  1373. faultDocTextBox.TabIndex = 5;
  1374. propPaneFaultMessage.Controls.Add(faultMessageParameterLabel);
  1375. propPaneFaultMessage.Controls.Add(faultMessageParamsCombo);
  1376. propPaneFaultMessage.Controls.Add(faultMessageNameLabel);
  1377. propPaneFaultMessage.Controls.Add(faultMessageNameTextBox);
  1378. propPaneFaultMessage.Controls.Add(faultRemoveLink);
  1379. propPaneFaultMessage.Controls.Add(faultDocTextBox);
  1380. propPaneFaultMessage.Controls.Add(faultDocLabel);
  1381. operationNode.Expanded = true;
  1382. PaneNode faultPaneNode = operationNode.PropertyPane.PaneNodes.Add(propPaneFaultMessage);
  1383. faultRemoveLink.Click += (o, s) =>
  1384. {
  1385. selectedOperation.Faults.Remove(faultMessage);
  1386. operationNode.PaneNodes.Remove(faultPaneNode);
  1387. };
  1388. return faultPaneNode;
  1389. }
  1390. /// <summary>
  1391. /// Prepares the dynamic controls for the operations-message parameters mapping UI.
  1392. /// </summary>
  1393. private void SetupOperationsMessagesPanes()
  1394. {
  1395. int i = 0;
  1396. ((ISupportInitialize)ptvServiceOperations).BeginInit();
  1397. ptvServiceOperations.SuspendLayout();
  1398. // Clear the existing items.
  1399. serviceInterfaceContract.OperationsCollection.Clear();
  1400. ptvServiceOperations.PaneNodes.Clear();
  1401. foreach (ListViewItem lvi in operationsListView.Items)
  1402. {
  1403. bool found = false;
  1404. // Check whether the operation already has a property pane or not.
  1405. foreach (PaneNode proPane in ptvServiceOperations.PaneNodes)
  1406. {
  1407. if (lvi.Text == (string)proPane.PropertyPane.Tag)
  1408. {
  1409. found = true;
  1410. break;
  1411. }
  1412. }
  1413. if (found)
  1414. {
  1415. continue;
  1416. }
  1417. Operation operation = new Operation();
  1418. operation.Name = lvi.Text;
  1419. string mepValue = lvi.SubItems[1].Text;
  1420. if (mepValue == "One-Way")
  1421. operation.Mep = Mep.OneWay;
  1422. else
  1423. operation.Mep = Mep.RequestResponse;
  1424. operation.Documentation = "";
  1425. string opName = operation.Name;
  1426. string opNamePrefix = opName.Substring(0, 1);
  1427. opNamePrefix = opNamePrefix.ToLower(CultureInfo.CurrentCulture);
  1428. opName = opName.Substring(1, opName.Length - 1);
  1429. opName = opNamePrefix + opName;
  1430. Message inMessage = new Message();
  1431. inMessage.Name = opName + "In";
  1432. inMessage.Documentation = "";
  1433. inMessage.Element = messageSchemas[0];
  1434. operation.MessagesCollection.Add(inMessage);
  1435. MessageHeader inHeader = new MessageHeader();
  1436. inHeader.Name = inMessage.Name + "Header";
  1437. inHeader.Message = inMessage.Name + "Header";
  1438. serviceInterfaceContract.OperationsCollection.Add(operation);
  1439. PropertyPane propPaneOp = new PropertyPane();
  1440. propPaneOp.Name = "propPaneOp" + i;
  1441. propPaneOp.Text = "Operation " + operation.Name;
  1442. propPaneOp.Tag = operation.Name;
  1443. // Setup dynamic GUI controls for the pane - Operation
  1444. LinkLabel addFaultMessage = new LinkLabel();
  1445. addFaultMessage.Text = "Add Fault Message";
  1446. addFaultMessage.Location = new Point(6, 5);
  1447. addFaultMessage.Click += addFaultMessage_Clicked;
  1448. propPaneOp.Controls.Add(addFaultMessage);
  1449. ptvServiceOperations.PaneNodes.Add(propPaneOp);
  1450. PropertyPane propPaneInMsg = new PropertyPane();
  1451. propPaneInMsg.Name = "propPaneInMsg" + i;
  1452. propPaneInMsg.Text = "Message " + inMessage.Name;
  1453. propPaneOp.PaneNodes.Add(propPaneInMsg);
  1454. propPaneOp.PaneNode.Expanded = true;
  1455. PropertyPane propPaneOutMsg = null;
  1456. Message outMessage = null;
  1457. MessageHeader outHeader = null;
  1458. if (operation.Mep == Mep.RequestResponse)
  1459. {
  1460. outMessage = new Message();
  1461. outMessage.Name = opName + "Out";
  1462. outMessage.Documentation = "";
  1463. outMessage.Element = messageSchemas[0];
  1464. operation.MessagesCollection.Add(outMessage);
  1465. outHeader = new MessageHeader();
  1466. outHeader.Name = outMessage.Name + "Header";
  1467. outHeader.Message = outMessage.Name + "Header";
  1468. propPaneOutMsg = new PropertyPane();
  1469. propPaneOutMsg.Name = "propPaneOutMsg" + i;
  1470. propPaneOutMsg.Text = "Message " + outMessage.Name;
  1471. propPaneOp.PaneNodes.Add(propPaneOutMsg);
  1472. propPaneOp.PaneNode.Expanded = true;
  1473. }
  1474. // Setup dynamic GUI controls for the pane - Operation
  1475. TextBox opDocTextBox = new TextBox();
  1476. opDocTextBox.Location = new Point(8, 148);
  1477. opDocTextBox.Multiline = true;
  1478. opDocTextBox.Name = "outDocTextBox" + i;
  1479. opDocTextBox.Size = new Size(135, 0);
  1480. opDocTextBox.DataBindings.Add("Text", operation, "Documentation");
  1481. opDocTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Top |
  1482. AnchorStyles.Right | AnchorStyles.Bottom;
  1483. Label opDocLabel = new Label();
  1484. opDocLabel.Location = new Point(8, 128);
  1485. opDocLabel.Name = "outDocLabel" + i;
  1486. opDocLabel.Size = new Size(88, 23);
  1487. opDocLabel.Text = "Documentation:";
  1488. propPaneOp.Controls.Add(opDocTextBox);
  1489. propPaneOp.Controls.Add(opDocLabel);
  1490. // Setup dynamic GUI controls for the pane - InMessage
  1491. TextBox inDocTextBox = new TextBox();
  1492. inDocTextBox.Location = new Point(8, 168);
  1493. inDocTextBox.Multiline = true;
  1494. inDocTextBox.Name = "inDocTextBox" + i;
  1495. inDocTextBox.Size = new Size(135, 0);
  1496. inDocTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
  1497. Label inMessageParameterLabel = new Label();
  1498. inMessageParameterLabel.Location = new Point(6, 5);
  1499. inMessageParameterLabel.Name = "inMessageParameterLabel" + i;
  1500. inMessageParameterLabel.Size = new Size(55, 33);
  1501. inMessageParameterLabel.Text = "Message body:";
  1502. CheckBox inMessageNameCheckBox = new CheckBox();
  1503. inMessageNameCheckBox.Location = new Point(9, 44);
  1504. inMessageNameCheckBox.Name = "inMessageNameCheckBox" + i;
  1505. inMessageNameCheckBox.Text = "Message name (optional)";
  1506. inMessageNameCheckBox.Size = new Size(220, 25);
  1507. TextBox inMessageNameTextBox = new TextBox();
  1508. inMessageNameTextBox.Location = new Point(8, 69);
  1509. inMessageNameTextBox.Name = "inMessageNameTextBox" + i;
  1510. inMessageNameTextBox.Size = new Size(142, 20);
  1511. inMessageNameTextBox.Enabled = false;
  1512. inMessageNameTextBox.Text = inMessage.Name;
  1513. inMessageNameTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
  1514. ComboBox inMessageParamsCombo = new ComboBox();
  1515. inMessageParamsCombo.DropDownStyle = ComboBoxStyle.DropDownList;
  1516. inMessageParamsCombo.Location = new Point(65, 5);
  1517. inMessageParamsCombo.Name = "inMessageParamsCombo" + i;
  1518. inMessageParamsCombo.Size = new Size(80, 21);
  1519. inMessageParamsCombo.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
  1520. // Fill the combo box with the Message values.
  1521. foreach (SchemaElement element in this.messageSchemas)
  1522. {
  1523. inMessageParamsCombo.Items.Add(element.ElementName);
  1524. }
  1525. inMessageParamsCombo.SelectedIndex = 0;
  1526. operation.Input = inMessage;
  1527. // Import the parameters from WSDL file for round tripping.
  1528. string originalOperationName = "";
  1529. if (lvi.Tag != null)
  1530. {
  1531. originalOperationName = lvi.Tag.ToString();
  1532. }
  1533. ImportMessageParameter(operation, false, inMessageParamsCombo,
  1534. inMessageNameCheckBox, inMessageNameTextBox, propPaneInMsg,
  1535. opDocTextBox, inDocTextBox, originalOperationName);
  1536. // Attach the dynamic combo box event handler.
  1537. inMessageParamsCombo.SelectedIndexChanged +=
  1538. new EventHandler(DynamicComboBox_SelectedIndexChanged);
  1539. CheckBox inMessageHeaderCheckBox = new CheckBox();
  1540. inMessageHeaderCheckBox.Location = new Point(9, 95);
  1541. inMessageHeaderCheckBox.Name = "inMessageHeaderCheckBox" + i;
  1542. inMessageHeaderCheckBox.Text = "Message headers (optional)";
  1543. inMessageHeaderCheckBox.Size = new Size(181, 25);
  1544. ComboBox inMessageHeaderCombo = new ComboBox();
  1545. inMessageHeaderCombo.DropDownStyle = ComboBoxStyle.DropDownList;
  1546. inMessageHeaderCombo.Location = new Point(8, 120);
  1547. inMessageHeaderCombo.Enabled = false;
  1548. inMessageHeaderCombo.Name = "inMessageHeaderCombo" + i;
  1549. inMessageHeaderCombo.Size = new Size(100, 21);
  1550. inMessageHeaderCombo.Items.Add("<New...>");
  1551. inMessageHeaderCombo.SelectedIndex = 0;
  1552. inMessageHeaderCombo.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
  1553. // Import headers from WSDL file for round tripping.
  1554. MessagesCollection addedInHeaderMsgs = ImportMessageHeaders(operation, inMessage,
  1555. inMessageHeaderCombo, inMessageHeaderCheckBox, false);
  1556. // Attach the dynamic combo box event handler.
  1557. inMessageHeaderCombo.SelectedIndexChanged +=
  1558. new EventHandler(DynamicComboBox_SelectedIndexChanged);
  1559. LinkLabel inRemoveHeaderLink = new LinkLabel();
  1560. inRemoveHeaderLink.Text = "Remove";
  1561. inRemoveHeaderLink.Location = new Point(193, 95);
  1562. inRemoveHeaderLink.Size = new Size(64, 25);
  1563. inRemoveHeaderLink.TextAlign = ContentAlignment.MiddleRight;
  1564. inRemoveHeaderLink.Visible = (addedInHeaderMsgs != null);
  1565. // inRemoveHeaderLink.Anchor = AnchorStyles.Right;
  1566. // Initialize the dynamic control controllers.
  1567. MessagePaneLabelController mplcIn =
  1568. new MessagePaneLabelController(inMessageNameTextBox, propPaneInMsg);
  1569. MessageNameTextBoxController mntbcIn =
  1570. new MessageNameTextBoxController(inMessageNameTextBox, inMessageNameCheckBox,
  1571. inMessage, propPaneInMsg);
  1572. InHeaderComboBoxController hcbcIn =
  1573. new InHeaderComboBoxController(inMessageHeaderCombo, inMessageHeaderCheckBox,
  1574. inMessageNameTextBox, operation, inMessage, inHeader, this.headerSchemas,
  1575. inRemoveHeaderLink, addedInHeaderMsgs);
  1576. OperationDocumentationTextBoxController odtbc =
  1577. new OperationDocumentationTextBoxController(opDocTextBox, operation);
  1578. MessageDocumentationTextBoxController mdtbc =
  1579. new MessageDocumentationTextBoxController(inDocTextBox, inMessage);
  1580. Label inDocLabel = new Label();
  1581. inDocLabel.Location = new Point(8, 149);
  1582. inDocLabel.Name = "inDocLabel" + i;
  1583. inDocLabel.Size = new Size(88, 23);
  1584. inDocLabel.Text = "Documentation:";
  1585. // Finally add the controls to the container.
  1586. propPaneInMsg.Controls.Add(inDocTextBox);
  1587. propPaneInMsg.Controls.Add(inDocLabel);
  1588. propPaneInMsg.Controls.Add(inMessageParameterLabel);
  1589. propPaneInMsg.Controls.Add(inMessageNameTextBox);
  1590. propPaneInMsg.Controls.Add(inMessageParameterLabel);
  1591. propPaneInMsg.Controls.Add(inMessageParamsCombo);
  1592. propPaneInMsg.Controls.Add(inMessageNameCheckBox);
  1593. propPaneInMsg.Controls.Add(inMessageHeaderCombo);
  1594. propPaneInMsg.Controls.Add(inMessageHeaderCheckBox);
  1595. propPaneInMsg.Controls.Add(inRemoveHeaderLink);
  1596. // Setup dynamic GUI controls for the pane - OutMessage
  1597. if (operation.Mep == Mep.RequestResponse)
  1598. {
  1599. TextBox outDocTextBox = new TextBox();
  1600. outDocTextBox.Location = new Point(8, 165);
  1601. outDocTextBox.Multiline = true;
  1602. outDocTextBox.Name = "outDocTextBox" + i;
  1603. outDocTextBox.Size = new Size(135, 0);
  1604. outDocTextBox.DataBindings.Add("Text", outMessage, "Documentation");
  1605. outDocTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right |
  1606. AnchorStyles.Bottom;
  1607. Label outMessageParameterLabel = new Label();
  1608. outMessageParameterLabel.Location = new Point(6, 5);
  1609. outMessageParameterLabel.Name = "outMessageParameterLabel" + i;
  1610. outMessageParameterLabel.Size = new Size(55, 33);
  1611. outMessageParameterLabel.Text = "Message body:";
  1612. CheckBox outMessageNameCheckBox = new CheckBox();
  1613. outMessageNameCheckBox.Location = new Point(9, 44);
  1614. outMessageNameCheckBox.Name = "outMessageNameCheckBox" + i;
  1615. outMessageNameCheckBox.Text = "Message name (optional)";
  1616. outMessageNameCheckBox.Size = new Size(220, 25);
  1617. TextBox outMessageNameTextBox = new TextBox();
  1618. outMessageNameTextBox.Location = new Point(8, 69);
  1619. outMessageNameTextBox.Name = "outMessageNameTextBox" + i;
  1620. outMessageNameTextBox.Size = new Size(142, 20);
  1621. outMessageNameTextBox.Enabled = false;
  1622. outMessageNameTextBox.Text = outMessage.Name;
  1623. outMessageNameTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Top |
  1624. AnchorStyles.Right;
  1625. ComboBox outMessageParamsCombo = new ComboBox();
  1626. outMessageParamsCombo.DropDownStyle = ComboBoxStyle.DropDownList;
  1627. outMessageParamsCombo.Location = new Point(65, 5);
  1628. outMessageParamsCombo.Name = "outMessageParamsCombo" + i;
  1629. outMessageParamsCombo.Size = new Size(80, 21);
  1630. outMessageParamsCombo.Anchor = AnchorStyles.Left | AnchorStyles.Top |
  1631. AnchorStyles.Right;
  1632. // Fill the combo box with the Message values.
  1633. foreach (SchemaElement element in this.messageSchemas)
  1634. {
  1635. outMessageParamsCombo.Items.Add(element.ElementName);
  1636. }
  1637. outMessageParamsCombo.SelectedIndex = 0;
  1638. operation.Output = outMessage;
  1639. // Import the parameters from an existing WSDL file for round tripping.
  1640. ImportMessageParameter(operation, true, outMessageParamsCombo, outMessageNameCheckBox,
  1641. outMessageNameTextBox, propPaneOutMsg, opDocTextBox, outDocTextBox, originalOperationName);
  1642. // Attach the dynamic combo box event handler.
  1643. outMessageParamsCombo.SelectedIndexChanged +=
  1644. new EventHandler(DynamicComboBox_SelectedIndexChanged);
  1645. CheckBox outMessageHeaderCheckBox = new CheckBox();
  1646. outMessageHeaderCheckBox.Location = new Point(9, 95);
  1647. outMessageHeaderCheckBox.Name = "outMessageHeaderCheckBox" + i;
  1648. outMessageHeaderCheckBox.Text = "Message headers (optional)";
  1649. outMessageHeaderCheckBox.Size = new Size(181, 25);
  1650. ComboBox outMessageHeaderCombo = new ComboBox();
  1651. outMessageHeaderCombo.DropDownStyle = ComboBoxStyle.DropDownList;
  1652. outMessageHeaderCombo.Location = new Point(8, 120);
  1653. outMessageHeaderCombo.Enabled = false;
  1654. outMessageHeaderCombo.Name = "outMessageHeaderCombo" + i;
  1655. outMessageHeaderCombo.Size = new Size(100, 21);
  1656. outMessageHeaderCombo.Items.Add("<New...>");
  1657. outMessageHeaderCombo.SelectedIndex = 0;
  1658. outMessageHeaderCombo.Anchor = AnchorStyles.Left | AnchorStyles.Top |
  1659. AnchorStyles.Right;
  1660. // Import headers from an existing WSDL file for round tripping.
  1661. MessagesCollection addedOutHeaderMsgs = ImportMessageHeaders(operation, outMessage,
  1662. outMessageHeaderCombo, outMessageHeaderCheckBox, true);
  1663. // Attach the dynamic combo box event handler.
  1664. outMessageHeaderCombo.SelectedIndexChanged +=
  1665. new EventHandler(DynamicComboBox_SelectedIndexChanged);
  1666. LinkLabel outRemoveHeaderLink = new LinkLabel();
  1667. outRemoveHeaderLink.Text = "Remove";
  1668. outRemoveHeaderLink.Location = new Point(193, 95);
  1669. outRemoveHeaderLink.Size = new Size(64, 25);
  1670. outRemoveHeaderLink.TextAlign = ContentAlignment.MiddleRight;
  1671. outRemoveHeaderLink.Visible = (addedOutHeaderMsgs != null);
  1672. // outRemoveHeaderLink.Anchor = AnchorStyles.Right;
  1673. // Initialize the dynamic control controllers.
  1674. MessagePaneLabelController mplcOut =
  1675. new MessagePaneLabelController(outMessageNameTextBox, propPaneOutMsg);
  1676. MessageNameTextBoxController mntbcOut =
  1677. new MessageNameTextBoxController(outMessageNameTextBox, outMessageNameCheckBox,
  1678. outMessage, propPaneOutMsg);
  1679. OutHeaderComboBoxController hcbcOut =
  1680. new OutHeaderComboBoxController(outMessageHeaderCombo, outMessageHeaderCheckBox,
  1681. outMessageNameTextBox, operation, outMessage, outHeader, headerSchemas,
  1682. outRemoveHeaderLink, addedOutHeaderMsgs);
  1683. MessageDocumentationTextBoxController outdtbc =
  1684. new MessageDocumentationTextBoxController(outDocTextBox, outMessage);
  1685. Label outDocLabel = new Label();
  1686. outDocLabel.Location = new Point(8, 149);
  1687. outDocLabel.Name = "outDocLabel" + i;
  1688. outDocLabel.Size = new Size(88, 23);
  1689. outDocLabel.Text = "Documentation:";
  1690. // Finally add the generated controls to the container.
  1691. propPaneOutMsg.Controls.Add(outDocTextBox);
  1692. propPaneOutMsg.Controls.Add(outDocLabel);
  1693. propPaneOutMsg.Controls.Add(outMessageParameterLabel);
  1694. propPaneOutMsg.Controls.Add(outMessageNameTextBox);
  1695. propPaneOutMsg.Controls.Add(outMessageParameterLabel);
  1696. propPaneOutMsg.Controls.Add(outMessageParamsCombo);
  1697. propPaneOutMsg.Controls.Add(outMessageNameCheckBox);
  1698. propPaneOutMsg.Controls.Add(outMessageHeaderCombo);
  1699. propPaneOutMsg.Controls.Add(outMessageHeaderCheckBox);
  1700. propPaneOutMsg.Controls.Add(outRemoveHeaderLink);
  1701. }
  1702. ImportFaultMessages(propPaneOp.PaneNode, operation, originalOperationName);
  1703. i++;
  1704. }
  1705. oldOperations = (OperationsCollection)serviceInterfaceContract.OperationsCollection.Clone();
  1706. ((ISupportInitialize)ptvServiceOperations).EndInit();
  1707. ptvServiceOperations.ResumeLayout(false);
  1708. }
  1709. /// <summary>
  1710. /// Reads the XML comment from the resource file. Wizard places this XML comment on the top of the
  1711. /// WSDL file. XML comment is stored in the resource file with "RT_HEADER" key. Once the XML comment is
  1712. /// read, the procedure will replace the substring - @VERSION@ in it with application's current version
  1713. /// number.
  1714. /// </summary>
  1715. /// <returns>The formatted XML comment with the application's current version number.</returns>
  1716. private string GetXmlCommentForWSDL()
  1717. {
  1718. // Read the current application version.
  1719. Version ver = Assembly.GetExecutingAssembly().GetName().Version;
  1720. string version = ver.Major.ToString() + "." + ver.Minor.ToString() + "." +
  1721. ver.Build.ToString() + "." + ver.Revision.ToString();
  1722. // Get the XML comment and replace the @VERSION@ with the current version.
  1723. string comment = ResourceHelper.GetString(
  1724. "Thinktecture.Tools.Web.Services.WsdlWizard.Resources.AssemblyResources",
  1725. System.Reflection.Assembly.GetExecutingAssembly(),
  1726. "RT_HEADER");
  1727. comment = comment.Replace("@VERSION@", version);
  1728. return comment;
  1729. }
  1730. /// <summary>
  1731. /// Updates the current folder, every time the schemaLocation is set.
  1732. /// </summary>
  1733. private void UpdateCurrentFolder(string location)
  1734. {
  1735. int lastBackSlash = location.LastIndexOf("\\");
  1736. if(lastBackSlash > 0)
  1737. {
  1738. this.currentFolder = location.Substring(0, lastBackSlash + 1);
  1739. }
  1740. else
  1741. {
  1742. this.currentFolder = location;
  1743. }
  1744. }
  1745. /// <summary>
  1746. /// Imports the basic metadata to UI controls from an existing WSDL <see cref="InterfaceContract"/>.
  1747. /// </summary>
  1748. private void ImportBasicServiceMetaData()
  1749. {
  1750. if(importedContract != null)
  1751. {
  1752. tbServiceName.Text = importedContract.ServiceName;
  1753. tbNamespace.Text = importedContract.ServiceNamespace;
  1754. tbServiceDoc.Text = importedContract.ServiceDocumentation;
  1755. }
  1756. }
  1757. /// <summary>
  1758. /// Imports the imported schema files to UI from an existing WSDL <see cref="InterfaceContract"/>.
  1759. /// </summary>
  1760. private bool ImportSchemaImports()
  1761. {
  1762. importsListView.Items.Clear();
  1763. foreach(SchemaImport import in importedContract.Imports)
  1764. {
  1765. string fname = string.Empty;
  1766. ListViewItem importItem = new ListViewItem();
  1767. // Check whether the file is a reference to an URI.
  1768. if(import.SchemaLocation.ToLower().StartsWith("http://"))
  1769. {
  1770. // Obtain the file from the web and save it in the project folder. Then map that
  1771. // file name in the WSDL.
  1772. WebRequest req = WebRequest.Create(import.SchemaLocation);
  1773. WebResponse result = null;
  1774. try
  1775. {
  1776. result = req.GetResponse();
  1777. }
  1778. catch
  1779. {
  1780. MessageBox.Show("Could not import the XSD file(s) from the specified URI.",
  1781. "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  1782. return false;
  1783. }
  1784. fname = import.SchemaLocation.Substring(
  1785. import.SchemaLocation.LastIndexOf("/") + 1);
  1786. importItem.Text = fname;
  1787. importItem.SubItems.Add(import.SchemaLocation);
  1788. }
  1789. else if(import.SchemaLocation.LastIndexOf('\\') > -1)
  1790. {
  1791. fname = import.SchemaLocation.Substring(
  1792. import.SchemaLocation.LastIndexOf("\\") + 1);
  1793. importItem.Text = fname;
  1794. importItem.SubItems.Add(import.SchemaLocation);
  1795. }
  1796. else
  1797. {
  1798. string fqName = "";
  1799. fqName = import.SchemaLocation;
  1800. if(fqName.StartsWith("../"))
  1801. {
  1802. fqName = IOPathHelper.GetAbsolutePath(fqName, this.wsdlLocation, this.projectRootDirectory);
  1803. }
  1804. else
  1805. {
  1806. fqName = IOPathHelper.GetAbsolutePath(fqName, this.wsdlLocation, this.projectRootDirectory);
  1807. }
  1808. fname = fqName.Substring(fqName.LastIndexOf("\\") + 1);
  1809. if(File.Exists(fqName))
  1810. {
  1811. importItem.Text = fname;
  1812. importItem.SubItems.Add(fqName);
  1813. }
  1814. else
  1815. {
  1816. MessageBox.Show("Could not locate the XSD file(s) imported to this WSDL",
  1817. "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  1818. return false;
  1819. }
  1820. }
  1821. importsListView.Items.Add(importItem);
  1822. }
  1823. return true;
  1824. }
  1825. /// <summary>
  1826. /// Imports the service operations to UI from an existing WSDL <see cref="InterfaceContract"/>.
  1827. /// </summary>
  1828. private void ImportOperations()
  1829. {
  1830. if(importedContract != null)
  1831. {
  1832. operationsListView.Items.Clear();
  1833. foreach(Operation op in importedContract.OperationsCollection)
  1834. {
  1835. string mep = "Request/Response";
  1836. if(op.Mep == Mep.OneWay)
  1837. mep = "One-Way";
  1838. ListViewItem listViewItem1 =
  1839. new ListViewItem(new string[] {op.Name, mep, "", ""}, -1);
  1840. listViewItem1.Tag = op.Name;
  1841. operationsListView.Items.AddRange(
  1842. new ListViewItem[] {listViewItem1});
  1843. // Check whether the Op name is using the default naming pattern (i.e. OperationX) and
  1844. // increment the counter.
  1845. // TODO: We can use a regular expression here to check this.
  1846. if(op.Name.ToLower().StartsWith("operation"))
  1847. {
  1848. string tail = op.Name.Substring(9);
  1849. try
  1850. {
  1851. int.Parse(tail);
  1852. operationCount++;
  1853. }
  1854. catch(FormatException)
  1855. {
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. private void ImportFaultMessages(PaneNode operationNode, Operation operation, string originalOperationName)
  1862. {
  1863. if(oldOperations.Count > 0)
  1864. {
  1865. ImportFaultMessages(operationNode, operation, originalOperationName, oldOperations);
  1866. return;
  1867. }
  1868. if(importedContract != null)
  1869. {
  1870. ImportFaultMessages(operationNode, operation, originalOperationName, importedContract.OperationsCollection);
  1871. return;
  1872. }
  1873. if(inferOperations.Count > 0)
  1874. {
  1875. ImportFaultMessages(operationNode, operation, originalOperationName, inferOperations);
  1876. return;
  1877. }
  1878. }
  1879. private void ImportFaultMessages(PaneNode operationNode, Operation operation, string originalOperationName, OperationsCollection operations)
  1880. {
  1881. foreach (Operation op in operations)
  1882. {
  1883. if (op.Name == operation.Name || (originalOperationName != string.Empty && op.Name == originalOperationName))
  1884. {
  1885. foreach (Message faultMessage in op.Faults)
  1886. {
  1887. AddFaultPropertyPane(operationNode, operation, faultMessage);
  1888. }
  1889. }
  1890. }
  1891. }
  1892. /// <summary>
  1893. /// Imports the message parameters for a specified operation from an existing WSDL.
  1894. /// <see cref="InterfaceContract"/>.
  1895. /// </summary>
  1896. /// <param name="op">The <see cref="Operation"/> to import the message parameters in to.</param>
  1897. /// <param name="output">Indicates whether the current message is input or output.</param>
  1898. /// <param name="parametersCombo">Reference to the combo box which contains the message parameters.</param>
  1899. /// <param name="chkName">Reference to the check box, which indicates whether the customized message name is selected or not.</param>
  1900. /// <param name="tbName">Reference to the text box which contains the customized message name. </param>
  1901. /// <param name="messageLabel">Reference to the Property Pane which contains the message name.</param>
  1902. /// <param name="opDocumentation">Reference to the text box which contains the <see cref="Operation"/>'s documentation.</param>
  1903. /// <param name="msgDocumentation">Reference to the text box which contains the <see cref="Message"/>'s documentation.</param>
  1904. /// <param name="originalOperationName">String which contains the original name of the operation. User can always change the operation name after infering operations or while round-tripping. This parameter contains the name of the operation before any of those alternations.</param>
  1905. private void ImportMessageParameter(Operation op, bool output, ComboBox parametersCombo,
  1906. CheckBox chkName, TextBox tbName, PropertyPane messageLabel, TextBox opDocumentation,
  1907. TextBox msgDocumentation, string originalOperationName)
  1908. {
  1909. if(oldOperations.Count > 0)
  1910. {
  1911. if(ImportMessageParameter(oldOperations, op, output,
  1912. parametersCombo, chkName, tbName, messageLabel,
  1913. opDocumentation, msgDocumentation, originalOperationName))
  1914. {
  1915. return;
  1916. }
  1917. }
  1918. if(importedContract != null)
  1919. {
  1920. if(ImportMessageParameter(importedContract.OperationsCollection, op, output,
  1921. parametersCombo, chkName, tbName, messageLabel, opDocumentation, msgDocumentation,
  1922. originalOperationName))
  1923. {
  1924. return;
  1925. }
  1926. }
  1927. if(inferOperations.Count > 0)
  1928. {
  1929. if(ImportMessageParameter(inferOperations, op, output,
  1930. parametersCombo, chkName, tbName, messageLabel,
  1931. opDocumentation, msgDocumentation, originalOperationName))
  1932. {
  1933. return;
  1934. }
  1935. }
  1936. }
  1937. /// <summary>
  1938. /// Imports the message parameters for a specified operation from an existing WSDL.
  1939. /// </summary>
  1940. /// <param name="operations">Collection of operations to import the message parameters from.</param>
  1941. /// <param name="op">The <see cref="Operation"/> to import the message parameters in to.</param>
  1942. /// <param name="output">Indicates whether the current message is input or output.</param>
  1943. /// <param name="parametersCombo">Reference to the combo box which contains the message parameters.</param>
  1944. /// <param name="chkName">Reference to the check box, which indicates whether the customized message name is selected or not.</param>
  1945. /// <param name="tbName">Reference to the text box which contains the customized message name. </param>
  1946. /// <param name="messageLabel">Reference to the Property Pane which contains the message name.</param>
  1947. /// <param name="opDocumentation">Reference to the text box which contains the <see cref="Operation"/>'s documentation.</param>
  1948. /// <param name="msgDocumentation">Reference to the text box which contains the <see cref="Message"/>'s documentation.</param>
  1949. /// <returns>A boolean indicating whether any message parameter is imported or not.</returns>
  1950. /// <param name="originalOperationName">String which contains the original name of the operation. User can always change the operation name after infering operations or while round-tripping. This parameter contains the name of the operation before any of those alternations.</param>
  1951. private bool ImportMessageParameter(OperationsCollection operations, Operation op, bool output,
  1952. ComboBox parametersCombo, CheckBox chkName, TextBox tbName, PropertyPane messageLabel,
  1953. TextBox opDocumentation, TextBox msgDocumentation, string originalOperationName)
  1954. {
  1955. foreach(Operation importedOp in operations)
  1956. {
  1957. if(importedOp.Name == op.Name || (originalOperationName != "" && importedOp.Name == originalOperationName))
  1958. {
  1959. // Identify the message from the message collection.
  1960. Message importedMsg = null;
  1961. Message msg = null;
  1962. if(!output)
  1963. {
  1964. importedMsg = importedOp.Input;
  1965. msg = op.Input;
  1966. }
  1967. else
  1968. {
  1969. importedMsg = importedOp.Output;
  1970. msg = op.Output;
  1971. }
  1972. if(importedMsg != null)
  1973. {
  1974. // Set the new message parameters.
  1975. int index = 0;
  1976. foreach(SchemaElement element in messageSchemas)
  1977. {
  1978. if(importedMsg.Element == element)
  1979. {
  1980. msg.Element = element;
  1981. parametersCombo.SelectedIndex = index;
  1982. break;
  1983. }
  1984. index++;
  1985. }
  1986. // Enable the custom name text box and put the custom message name in.
  1987. if(importedOp.Name == op.Name && msg.Name != importedMsg.Name)
  1988. {
  1989. tbName.Enabled = true;
  1990. tbName.Text = importedMsg.Name;
  1991. msg.Name = importedMsg.Name;
  1992. messageLabel.Text = importedMsg.Name;
  1993. chkName.Checked = true;
  1994. }
  1995. // Set the Message documentation.
  1996. msg.Documentation = importedMsg.Documentation;
  1997. msgDocumentation.Text = importedMsg.Documentation;
  1998. }
  1999. // Set the operation documentation.
  2000. op.Documentation = importedOp.Documentation;
  2001. opDocumentation.Text = importedOp.Documentation;
  2002. return true;
  2003. }
  2004. }
  2005. return false;
  2006. }
  2007. /// <summary>
  2008. /// Imports the message headers for a specified message from an existing WSDL.
  2009. /// <see cref="InterfaceContract"/>.
  2010. /// </summary>
  2011. /// <param name="op">Reference to the <see cref="Operation"/>, <see cref="Message"/> msg belongs to.</param>
  2012. /// <param name="msg">Reference to the <see cref="Message"/>, headers belong to.</param>
  2013. /// <param name="headersCombo">Reference to the combo box which contains the headers.</param>
  2014. /// <param name="hasHeaders">Reference to the check box which indicates whether the custom headers are added or not.</param>
  2015. /// <param name="outMessage">Indicates whether the current message is input or output.</param>
  2016. /// <returns>An instance of <see cref="MessagesCollection"/> class with the added header messages.</returns>
  2017. private MessagesCollection ImportMessageHeaders(Operation op, Message msg,
  2018. ComboBox headersCombo, CheckBox hasHeaders, bool outMessage)
  2019. {
  2020. // Read the message headers from the old operations collection if available.
  2021. MessagesCollection addedHeaderMessages = null;
  2022. if(oldOperations.Count > 0)
  2023. {
  2024. addedHeaderMessages =
  2025. ImportMessageHeaders(oldOperations, op, msg, headersCombo,
  2026. hasHeaders, outMessage);
  2027. if(addedHeaderMessages != null)
  2028. {
  2029. return addedHeaderMessages;
  2030. }
  2031. }
  2032. else
  2033. {
  2034. // Read the message headers from the imported contract.
  2035. if(importedContract != null)
  2036. {
  2037. addedHeaderMessages =
  2038. ImportMessageHeaders(importedContract.OperationsCollection, op, msg, headersCombo,
  2039. hasHeaders, outMessage);
  2040. if(addedHeaderMessages != null)
  2041. {
  2042. return addedHeaderMessages;
  2043. }
  2044. }
  2045. }
  2046. return addedHeaderMessages;
  2047. }
  2048. /// <summary>
  2049. /// Imports the message headers for a specified message from an existing WSDL.
  2050. /// <see cref="InterfaceContract"/>.
  2051. /// </summary>
  2052. /// <param name="ops">Reference to the <see cref="OperationsCollection"/> to search for the <see cref="Operation"/>, which <see cref="Message"/> msg belongs to.</param>
  2053. /// <param name="op">Reference to the <see cref="Operation"/>, <see cref="Message"/> msg belongs to.</param>
  2054. /// <param name="msg">Reference to the <see cref="Message"/>, headers belong to.</param>
  2055. /// <param name="headersCombo">Reference to the combo box which contains the headers.</param>
  2056. /// <param name="hasHeaders">Reference to the check box which indicates whether the custom headers are added or not.</param>
  2057. /// <param name="outMessage">Indicates whether the current message is input or output.</param>
  2058. /// <returns>An instance of <see cref="MessagesCollection"/> class with the added header messages.</returns>
  2059. private MessagesCollection ImportMessageHeaders(OperationsCollection ops, Operation op,
  2060. Message msg, ComboBox headersCombo, CheckBox hasHeaders, bool outMessage)
  2061. {
  2062. MessagesCollection addedHeaderMessages = null;
  2063. foreach(Operation importedOp in ops)
  2064. {
  2065. if(importedOp.Name == op.Name)
  2066. {
  2067. Message importedMsg = null;
  2068. if(!outMessage)
  2069. {
  2070. importedMsg = importedOp.Input;
  2071. }
  2072. else
  2073. {
  2074. importedMsg = importedOp.Output;
  2075. }
  2076. // Check for the headers.
  2077. if(importedMsg != null && importedMsg.HeadersCollection.Count > 0)
  2078. {
  2079. addedHeaderMessages = new MessagesCollection();
  2080. hasHeaders.Checked = true; // Enable headers check box.
  2081. headersCombo.Enabled = true; // Enable the headers combo box.
  2082. // Add the headers to current message's headers collection.
  2083. foreach(MessageHeader header in importedMsg.HeadersCollection)
  2084. {
  2085. // Find and add the header message to the operation.
  2086. foreach(Message headerMsg in importedOp.MessagesCollection)
  2087. {
  2088. if(headerMsg.Name == header.Message)
  2089. {
  2090. msg.HeadersCollection.Add(header);
  2091. op.MessagesCollection.Add(headerMsg);
  2092. addedHeaderMessages.Add(headerMsg);
  2093. // Finally add the header details to the combo box.
  2094. headersCombo.Items.Insert(headersCombo.Items.Count - 1,
  2095. headerMsg.Element.ElementName);
  2096. }
  2097. }
  2098. }
  2099. break;
  2100. }
  2101. }
  2102. }
  2103. return addedHeaderMessages;
  2104. }
  2105. /// <summary>
  2106. /// Imports the additional options from an existing WSDL <see cref="InterfaceContract"/>.
  2107. /// </summary>
  2108. private void ImportAdditionalOptions()
  2109. {
  2110. if(importedContract != null)
  2111. {
  2112. this.cbNeedsServiceElement.Checked = importedContract.NeedsServiceElement;
  2113. cbSoap12.Checked = (importedContract.Bindings & InterfaceContract.SoapBindings.Soap12) == InterfaceContract.SoapBindings.Soap12;
  2114. }
  2115. }
  2116. /// <summary>
  2117. /// Imports the embedded types in the WSDL.
  2118. /// </summary>
  2119. private void ImportEmbeddedTypes()
  2120. {
  2121. if(importedContract != null)
  2122. {
  2123. this.messageSchemas.AddRange(importedContract.Types);
  2124. this.headerSchemas.AddRange(importedContract.Types);
  2125. faultSchemas.AddRange(importedContract.Types);
  2126. }
  2127. }
  2128. /// <summary>
  2129. /// Infers the operations according to the message name patterns in the message contracts.
  2130. /// </summary>
  2131. private void InferOperations()
  2132. {
  2133. // Define a hash table with list of request/response patterns.
  2134. Dictionary<string, string> patterns = new Dictionary<string, string>();
  2135. patterns.Add("", "Response");
  2136. patterns.Add("Request", "Response");
  2137. patterns.Add("RequestMessage", "ResponseMessage");
  2138. SchemaElements usedElements = new SchemaElements();
  2139. // Infer two-way operations.
  2140. foreach(SchemaElement melement in messageSchemas)
  2141. {
  2142. foreach(string requestPattern in patterns.Keys)
  2143. {
  2144. string operationName = "";
  2145. if(melement.ElementName.EndsWith(requestPattern))
  2146. {
  2147. string responsePattern = patterns[requestPattern];
  2148. // Create the response element.
  2149. SchemaElement responseElement = new SchemaElement();
  2150. if(requestPattern == "")
  2151. {
  2152. operationName = melement.ElementName;
  2153. responseElement.ElementName = melement.ElementName + responsePattern;
  2154. }
  2155. else
  2156. {
  2157. if(melement.ElementName == requestPattern)
  2158. {
  2159. operationName = melement.ElementName;
  2160. responseElement.ElementName = responsePattern;
  2161. }
  2162. else
  2163. {
  2164. operationName =
  2165. melement.ElementName.Substring(0,
  2166. melement.ElementName.LastIndexOf(requestPattern));
  2167. responseElement.ElementName =
  2168. melement.ElementName.Substring(0,
  2169. melement.ElementName.LastIndexOf(requestPattern)) + responsePattern;
  2170. }
  2171. }
  2172. responseElement.ElementNamespace = melement.ElementNamespace;
  2173. if(messageSchemas.Contains(responseElement))
  2174. {
  2175. // Check whether the operation exists in the imported operations list.
  2176. bool exists = false;
  2177. if(importedContract != null)
  2178. {
  2179. foreach(Operation impOp in importedContract.OperationsCollection)
  2180. {
  2181. if(impOp.Input.Element == melement &&
  2182. (impOp.Output != null && impOp.Output.Element == responseElement))
  2183. {
  2184. exists = true;
  2185. break;
  2186. }
  2187. }
  2188. }
  2189. if(exists)
  2190. {
  2191. break;
  2192. }
  2193. // Add the operation to the list.
  2194. Operation op = new Operation();
  2195. op.Name = operationName;
  2196. op.Documentation = "";
  2197. op.Mep = Mep.RequestResponse;
  2198. string opName = op.Name;
  2199. string opNamePrefix = opName.Substring(0, 1);
  2200. opNamePrefix = opNamePrefix.ToLower(CultureInfo.CurrentCulture);
  2201. opName = op.Name.Substring(1, op.Name.Length - 1);
  2202. opName = opNamePrefix + opName;
  2203. // Add the input message.
  2204. Message input = new Message();
  2205. input.Name = opName + "In";
  2206. input.Element = melement;
  2207. input.Documentation = "";
  2208. op.MessagesCollection.Add(input);
  2209. op.Input = input;
  2210. // Add the output message.
  2211. Message output = new Message();
  2212. output.Name = opName + "Out";
  2213. output.Element = responseElement;
  2214. output.Documentation = "";
  2215. op.MessagesCollection.Add(output);
  2216. op.Output = output;
  2217. // Add the operation to the inferred operations collection.
  2218. inferOperations.Add(op);
  2219. // Add the operation to the list view.
  2220. ListViewItem listViewItem1 =
  2221. new ListViewItem(new string[] {
  2222. op.Name,
  2223. "Request/Response",
  2224. "",
  2225. ""},
  2226. -1);
  2227. listViewItem1.Tag = op.Name;
  2228. operationsListView.Items.AddRange(
  2229. new ListViewItem[] {listViewItem1});
  2230. usedElements.Add(melement);
  2231. usedElements.Add(responseElement);
  2232. // Exit this loop.
  2233. break;
  2234. }
  2235. }
  2236. }
  2237. }
  2238. // Infer one-way operations.
  2239. foreach(SchemaElement melement in messageSchemas)
  2240. {
  2241. foreach(string requestPattern in patterns.Keys)
  2242. {
  2243. string operationName = "";
  2244. if(melement.ElementName.EndsWith(requestPattern))
  2245. {
  2246. if(!usedElements.Contains(melement))
  2247. {
  2248. // Check whether the operation exists in the imported operations list.
  2249. bool exists = false;
  2250. if(importedContract != null)
  2251. {
  2252. foreach(Operation impOp in importedContract.OperationsCollection)
  2253. {
  2254. if(impOp.Input.Element == melement ||
  2255. (impOp.Output != null && impOp.Output.Element == melement))
  2256. {
  2257. exists = true;
  2258. break;
  2259. }
  2260. }
  2261. }
  2262. if(exists)
  2263. {
  2264. break;
  2265. }
  2266. // Compose the operation name.
  2267. if(requestPattern == "")
  2268. {
  2269. operationName = melement.ElementName;
  2270. }
  2271. else
  2272. {
  2273. if(melement.ElementName == requestPattern)
  2274. {
  2275. operationName = melement.ElementName;
  2276. }
  2277. else
  2278. {
  2279. operationName =
  2280. melement.ElementName.Substring(0,
  2281. melement.ElementName.LastIndexOf(requestPattern));
  2282. }
  2283. }
  2284. // Add the operation to the list.
  2285. Operation op = new Operation();
  2286. op.Name = operationName;
  2287. op.Documentation = "";
  2288. op.Mep = Mep.OneWay;
  2289. string opName = op.Name;
  2290. string opNamePrefix = opName.Substring(0, 1);
  2291. opNamePrefix = opNamePrefix.ToLower(CultureInfo.CurrentCulture);
  2292. opName = op.Name.Substring(1, op.Name.Length - 1);
  2293. opName = opNamePrefix + opName;
  2294. // Add the input message.
  2295. Message input = new Message();
  2296. input.Name = opName + "In";
  2297. input.Element = melement;
  2298. input.Documentation = "";
  2299. op.MessagesCollection.Add(input);
  2300. op.Input = input;
  2301. // Add the operation to the inferred operations collection.
  2302. inferOperations.Add(op);
  2303. // Add the operation to the list view.
  2304. ListViewItem listViewItem1 =
  2305. new ListViewItem(new string[] {
  2306. op.Name,
  2307. "One-Way",
  2308. "",
  2309. ""},
  2310. -1);
  2311. listViewItem1.Tag = op.Name;
  2312. operationsListView.Items.AddRange(
  2313. new ListViewItem[] {listViewItem1});
  2314. }
  2315. // Exit this loop.
  2316. break;
  2317. }
  2318. }
  2319. }
  2320. }
  2321. /// <summary>
  2322. /// Removes the inferred operations.
  2323. /// </summary>
  2324. private void RemoveInferedOperations()
  2325. {
  2326. int index = 0;
  2327. while(index != operationsListView.Items.Count)
  2328. {
  2329. bool removed = false;
  2330. ListViewItem li = operationsListView.Items[index];
  2331. foreach(Operation op in inferOperations)
  2332. {
  2333. if(op.Name == li.Text)
  2334. {
  2335. li.Remove();
  2336. removed = true;
  2337. break;
  2338. }
  2339. }
  2340. if(!removed)
  2341. {
  2342. index++;
  2343. }
  2344. }
  2345. inferOperations.Clear();
  2346. }
  2347. #endregion
  2348. /// <summary>
  2349. /// CheckedChanged event handler for the cbInfer checkbox control.
  2350. /// </summary>
  2351. /// <param name="sender">Source of the event.</param>
  2352. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2353. /// <remarks>This checkbox specifies whether to infer the operations or not.</remarks>
  2354. private void cbInfer_CheckedChanged(object sender, System.EventArgs e)
  2355. {
  2356. if(cbInfer.Checked)
  2357. {
  2358. InferOperations();
  2359. }
  2360. else
  2361. {
  2362. RemoveInferedOperations();
  2363. }
  2364. }
  2365. /// <summary>
  2366. /// CheckedChanged event handler for the cbCodeGenDialog checkbox control.
  2367. /// </summary>
  2368. /// <param name="sender">Source of the event.</param>
  2369. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2370. /// <remarks>This checkbox specifies whether the code generation dialog must start right after the wizard or not.
  2371. /// If the user is in the round-tripping mode this checkbox is selected by default and it verifies if the user tries to uncheck it.</remarks>
  2372. private void cbCodeGenDialog_CheckedChanged(object sender, System.EventArgs e)
  2373. {
  2374. if(!cbCodeGenDialog.Checked && this.roundtripMode)
  2375. {
  2376. if(MessageBox.Show(this,
  2377. "You need to regenerate the code to reflect the changes which have been made in the contract. Are you sure you do not want to start code generation immediately after the wizard?",
  2378. "WZDL Wizard",
  2379. MessageBoxButtons.YesNo,
  2380. MessageBoxIcon.Question) == DialogResult.No)
  2381. {
  2382. cbCodeGenDialog.Checked = true;
  2383. }
  2384. }
  2385. }
  2386. protected override void WndProc(ref System.Windows.Forms.Message m)
  2387. {
  2388. const int WM_PAINT = 0xf;
  2389. switch (m.Msg)
  2390. {
  2391. case WM_PAINT:
  2392. importsListView.Columns[1].Width = -2;
  2393. operationsListView.Columns[1].Width = -2;
  2394. xsdpathsListView.Columns[1].Width = -2;
  2395. break;
  2396. }
  2397. base.WndProc(ref m);
  2398. }
  2399. #region MesssagePaneLabelController
  2400. /// <summary>
  2401. /// Represents a custom controller for the dynamically created PropertyPane and Textbox controls.
  2402. /// </summary>
  2403. private class MessagePaneLabelController
  2404. {
  2405. #region Private fields
  2406. private TextBox currentTextBox;
  2407. private PropertyPane currentLabel;
  2408. #endregion
  2409. #region Constructors
  2410. /// <summary>
  2411. /// Initializes a new instance of the MessagePaneLabelController with the specified values.
  2412. /// </summary>
  2413. /// <param name="messageTextBox">Reference to the Textbox to control.</param>
  2414. /// <param name="messageLabel">Reference to the PropertyPane to control.</param>
  2415. public MessagePaneLabelController(TextBox messageTextBox,
  2416. PropertyPane messageLabel)
  2417. {
  2418. currentTextBox = messageTextBox;
  2419. currentLabel = messageLabel;
  2420. // Attach the event handler for the current text box's lost focus event.
  2421. currentTextBox.LostFocus += new EventHandler(TextBox_FocusOver);
  2422. }
  2423. #endregion
  2424. #region Event handlers
  2425. /// <summary>
  2426. /// Performs the actions when the controlled text box changes the focus.
  2427. /// </summary>
  2428. /// <param name="sender">The source of the event.</param>
  2429. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2430. private void TextBox_FocusOver(object sender, EventArgs e)
  2431. {
  2432. currentLabel.Text = currentTextBox.Text;
  2433. PropertyPane propPane = (PropertyPane)currentTextBox.Parent;
  2434. PropertyTree propTree = ((PropertyTree)currentLabel.Parent);
  2435. propTree.SelectedPaneNode = propPane.PaneNode;
  2436. }
  2437. #endregion
  2438. }
  2439. #endregion
  2440. #region MessageNameTextBoxController
  2441. /// <summary>
  2442. /// Represents a custom controller for dynamically created control for the custom message name.
  2443. /// </summary>
  2444. private class MessageNameTextBoxController
  2445. {
  2446. #region Private fields
  2447. private TextBox currentTextBox;
  2448. private CheckBox currentCheckBox;
  2449. private PropertyPane currentMessageLabel;
  2450. private string initialName;
  2451. private Message message;
  2452. #endregion
  2453. #region Constructors
  2454. /// <summary>
  2455. /// Initializes a new instance of MessageNameTextBoxController class with the specified values.
  2456. /// </summary>
  2457. /// <param name="messageNameTextBox">Reference to the text box which contains the message name.</param>
  2458. /// <param name="messageNameCheckBox">Reference to the check box which indicates whether the customized message name is used or not.</param>
  2459. /// <param name="message">Reference to the current <see cref="Message"/>.</param>
  2460. /// <param name="messageLabel">Reference to the tree view node which displays the message name.</param>
  2461. public MessageNameTextBoxController(TextBox messageNameTextBox,
  2462. CheckBox messageNameCheckBox, Message message,
  2463. PropertyPane messageLabel)
  2464. {
  2465. currentTextBox = messageNameTextBox;
  2466. currentCheckBox = messageNameCheckBox;
  2467. currentMessageLabel = messageLabel;
  2468. initialName = currentTextBox.Text;
  2469. this.message = message;
  2470. // Attach the event handlers for the controls.
  2471. currentCheckBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
  2472. currentTextBox.TextChanged += new EventHandler(TextBox_TextChanged);
  2473. }
  2474. #endregion
  2475. #region Event handlers
  2476. /// <summary>
  2477. /// Performs the actions when the check box status is changed.
  2478. /// </summary>
  2479. /// <param name="sender">The source of the event.</param>
  2480. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2481. /// <remarks>If the check box is unchecked this method will reset the message name to the initial name.</remarks>
  2482. private void CheckBox_CheckedChanged(object sender, EventArgs e)
  2483. {
  2484. if(currentTextBox.Enabled == false)
  2485. {
  2486. currentTextBox.Enabled = true;
  2487. }
  2488. else
  2489. {
  2490. // Reset the message name to the initial value.
  2491. currentTextBox.Enabled = false;
  2492. currentTextBox.Text = initialName;
  2493. message.Name = initialName;
  2494. currentMessageLabel.Text = initialName;
  2495. }
  2496. }
  2497. /// <summary>
  2498. /// Performs the actions when the content of the text box changes.
  2499. /// </summary>
  2500. /// <param name="sender">The source of the event.</param>
  2501. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2502. /// <remarks>This method updates the current message's message name when updating the text box.</remarks>
  2503. private void TextBox_TextChanged(object sender, EventArgs e)
  2504. {
  2505. message.Name = currentTextBox.Text;
  2506. }
  2507. #endregion
  2508. }
  2509. #endregion
  2510. #region InHeaderComboBoxController
  2511. /// <summary>
  2512. /// Represents a custom controller for dynamically created controls
  2513. /// to hold header messages for input message.
  2514. /// </summary>
  2515. private class InHeaderComboBoxController
  2516. {
  2517. #region Private fields
  2518. private bool showDialog;
  2519. private ComboBox currentComboBox;
  2520. private CheckBox currentCheckBox;
  2521. private TextBox currentMessageNameTextBox;
  2522. private Operation currentOperation;
  2523. private Message currentMessage;
  2524. private MessageHeader currentHeader;
  2525. private Message headerMessage;
  2526. private SchemaElements headerElements;
  2527. private MessagesCollection headerMessages;
  2528. private LinkLabel currentRemoveButton;
  2529. #endregion
  2530. #region Constructors
  2531. /// <summary>
  2532. /// Initializes a new instance of InHeaderComboBoxController class with specified values.
  2533. /// </summary>
  2534. /// <param name="headerComboBox">Reference to the combo box which contains the headers.</param>
  2535. /// <param name="headerCheckBox">Reference to the check box which indicates whether to use the message header(s) or not.</param>
  2536. /// <param name="messageNameTextBox">Reference to the text box which contains the customized message name.</param>
  2537. /// <param name="operation">Reference to the instance of <see cref="Operation"/> class, <see cref="MessageHeader"/> belongs to.</param>
  2538. /// <param name="message">Reference to the instance of <see cref="Message"/> class, <see cref="MessageHeader"/> belongs to.</param>
  2539. /// <param name="header">Reference to the current <see cref="MessageHeader"/> of the message.</param>
  2540. /// <param name="headerElements">
  2541. /// Reference to an instance of <see cref="SchemaElements"/> class with schema elements for headers.
  2542. /// </param>
  2543. /// <param name="removeButton">Reference to the link label control used to remove headers.</param>
  2544. /// <param name="addedMessages">Reference to an instance of <see cref="MessagesCollection"/> class with <see cref="Message"/> objects added for the header.</param>
  2545. public InHeaderComboBoxController(ComboBox headerComboBox,
  2546. CheckBox headerCheckBox,
  2547. TextBox messageNameTextBox,
  2548. Operation operation,
  2549. Message message,
  2550. MessageHeader header,
  2551. SchemaElements headerElements,
  2552. LinkLabel removeButton,
  2553. MessagesCollection addedMessages)
  2554. {
  2555. currentComboBox = headerComboBox;
  2556. currentCheckBox = headerCheckBox;
  2557. currentMessageNameTextBox = messageNameTextBox;
  2558. currentOperation = operation;
  2559. currentMessage = message;
  2560. currentHeader = header;
  2561. this.headerElements = headerElements;
  2562. this.headerMessages = new MessagesCollection();
  2563. if(addedMessages != null)
  2564. {
  2565. foreach(Message impHeader in addedMessages)
  2566. {
  2567. this.headerMessages.Add(impHeader);
  2568. }
  2569. }
  2570. this.currentRemoveButton = removeButton;
  2571. this.showDialog = true;
  2572. // Attach the event handlers.
  2573. currentCheckBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
  2574. currentComboBox.SelectedIndexChanged +=
  2575. new EventHandler(ComboBox_SelectedIndexChanged);
  2576. currentMessageNameTextBox.LostFocus += new EventHandler(TextBox_FocusOver);
  2577. currentRemoveButton.Click += new EventHandler(this.RemoveLink_Click);
  2578. }
  2579. #endregion
  2580. #region Event handlers
  2581. /// <summary>
  2582. /// Performs the actions when textbox focus changes.
  2583. /// </summary>
  2584. /// <param name="sender">The event source.</param>
  2585. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2586. /// <remarks>When the content of the text box changes, this procedure updates the name of the
  2587. /// <see cref="MessageHeader"/> accordingly.</remarks>
  2588. private void TextBox_FocusOver(object sender, EventArgs e)
  2589. {
  2590. if (headerMessage != null) headerMessage.Name = currentMessageNameTextBox.Text + "Header";
  2591. if (currentHeader != null)
  2592. {
  2593. currentHeader.Message = currentMessageNameTextBox.Text + "Header";
  2594. }
  2595. }
  2596. /// <summary>
  2597. /// Performs the actions when the status of the checkbox control changes.
  2598. /// </summary>
  2599. /// <param name="sender">The event source.</param>
  2600. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2601. /// <remarks>If the check box is checked, this method will enable the combo box which displays the
  2602. /// headers. Then it calls the <see cref="AddNewHeader"/> method to add a new header.
  2603. /// If the check box is unchecked this method will perform the following tasks.
  2604. /// 1. Removes the header messages from the <see cref="Operation"/>.
  2605. /// 2. Clears the HeadersCollection of the current <see cref="Message"/>.
  2606. /// 3. Removes the items from the combo box which displays the headers.
  2607. /// 4. Disables the combo box.
  2608. /// </remarks>
  2609. private void CheckBox_CheckedChanged(object sender, EventArgs e)
  2610. {
  2611. // Code for multiple headers support.
  2612. if(currentCheckBox.Checked)
  2613. {
  2614. currentComboBox.Enabled = true;
  2615. this.AddNewHeader();
  2616. }
  2617. else
  2618. {
  2619. // Remove the Header messages from the operation.
  2620. foreach(Message msg in this.headerMessages)
  2621. {
  2622. this.currentOperation.MessagesCollection.Remove(msg);
  2623. }
  2624. // Clear the headers for the current message.
  2625. this.currentMessage.HeadersCollection.Clear();
  2626. // Clear the headerMessages collection.
  2627. this.headerMessages.Clear();
  2628. // Remove the items on the combo box.
  2629. while(this.currentComboBox.Items.Count != 1)
  2630. {
  2631. this.currentComboBox.Items.RemoveAt(0);
  2632. }
  2633. // Finally disable the combo box.
  2634. showDialog = false;
  2635. currentComboBox.SelectedIndex = currentComboBox.Items.Count - 1;
  2636. currentComboBox.Enabled = false;
  2637. currentRemoveButton.Visible = false;
  2638. }
  2639. }
  2640. /// <summary>
  2641. /// Performs the actions when the selected index of the header messages combo box changes.
  2642. /// </summary>
  2643. /// <param name="sender">The event source.</param>
  2644. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2645. /// <remarks>If the selected item is the last item of the list, the method will call the
  2646. /// <see cref="AddNewHeader"/> method. Otherwise it shows the remove button to remove the
  2647. /// selected header.</remarks>
  2648. private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
  2649. {
  2650. if(currentComboBox.SelectedIndex == currentComboBox.Items.Count - 1)
  2651. {
  2652. currentRemoveButton.Visible = false;
  2653. if(showDialog) AddNewHeader();
  2654. showDialog = true;
  2655. }
  2656. else
  2657. {
  2658. currentRemoveButton.Visible = true;
  2659. }
  2660. }
  2661. /// <summary>
  2662. /// Performs the actions when the remove link label is clicked.
  2663. /// </summary>
  2664. /// <param name="sender">The event source.</param>
  2665. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2666. /// <remarks>This method removes the <see cref="MessageHeader"/> from the <see cref="Message"/>
  2667. /// and <see cref="Message"/> from the <see cref="Operation"/>. </remarks>
  2668. private void RemoveLink_Click(object sender, EventArgs e)
  2669. {
  2670. // Select the message from the added header messages collection.
  2671. Message msg = headerMessages[currentComboBox.SelectedIndex];
  2672. // Remove the message from the Operation.
  2673. currentOperation.MessagesCollection.Remove(msg);
  2674. // Remove the MessageHeader from the currentMessage.
  2675. currentMessage.HeadersCollection.RemoveAt(currentComboBox.SelectedIndex);
  2676. // Remove the message from the header messages collection.
  2677. headerMessages.RemoveAt(currentComboBox.SelectedIndex );
  2678. // Remove the header from the combo box.
  2679. currentComboBox.Items.RemoveAt(currentComboBox.SelectedIndex);
  2680. // Change the current index of the combo box.
  2681. SelectTheLatestHeader();
  2682. }
  2683. #endregion
  2684. #region Private methods
  2685. /// <summary>
  2686. /// Prompts a dialog box to select the new header. Once it is selected this method adds it to
  2687. /// <see cref="Message.HeadersCollection"/>. Also this method creates a new <see cref="Message"/>
  2688. /// for the header and puts it to the <see cref="Operation.MessagesCollection"/>.
  2689. /// </summary>
  2690. private void AddNewHeader()
  2691. {
  2692. SchemaElement newHeaderMessage = new SchemaElement();
  2693. // Display the dialog box.
  2694. SelectHeaderDialog dialog = new SelectHeaderDialog(this.headerElements, ref newHeaderMessage);
  2695. dialog.ShowDialog();
  2696. if(newHeaderMessage.ElementName != null)
  2697. {
  2698. // First check whether the header already exists. And remove it if it does.
  2699. foreach(Message msg in this.headerMessages)
  2700. {
  2701. if(newHeaderMessage.ElementName == msg.Element.ElementName &&
  2702. newHeaderMessage.ElementNamespace == msg.Element.ElementNamespace)
  2703. {
  2704. // Select the last item before returning.
  2705. SelectTheLatestHeader();
  2706. return; // Exit without adding.
  2707. }
  2708. }
  2709. string headerName = "";
  2710. int index = 1;
  2711. while(headerName == "")
  2712. {
  2713. headerName = currentMessage.Name + "Header" + index.ToString();
  2714. // Check whether we already have a header message with the same name.
  2715. foreach(MessageHeader hdr in currentMessage.HeadersCollection)
  2716. {
  2717. if(hdr.Name == headerName)
  2718. {
  2719. headerName = "";
  2720. index++;
  2721. break;
  2722. }
  2723. }
  2724. }
  2725. // Create the header message.
  2726. headerMessage = new Message();
  2727. headerMessage.Name = headerName;
  2728. headerMessage.Documentation = "";
  2729. headerMessage.Element.ElementName = newHeaderMessage.ElementName;
  2730. headerMessage.Element.ElementNamespace = newHeaderMessage.ElementNamespace;
  2731. // Create the header.
  2732. MessageHeader newHeader = new MessageHeader();
  2733. newHeader.Message = headerMessage.Name;
  2734. newHeader.Name = headerMessage.Name;
  2735. // Add header to the current message.
  2736. currentMessage.HeadersCollection.Add(newHeader);
  2737. // Add the new header message to the messages collection.
  2738. currentOperation.MessagesCollection.Add(headerMessage);
  2739. // Added the newly created header message to the header messages collection.
  2740. // Reason: In case we need to remove the header messages we need to distinguish
  2741. // them from the existing messages.
  2742. this.headerMessages.Add(headerMessage);
  2743. // Add the newly added header info to the headers combo box.
  2744. currentComboBox.Items.Insert
  2745. (currentComboBox.Items.Count - 1, headerMessage.Element.ElementName);
  2746. // Set the last selected header message as the default header.
  2747. currentComboBox.SelectedIndex = currentComboBox.Items.Count - 2;
  2748. }
  2749. }
  2750. /// <summary>
  2751. /// Sets the last item on the headers combo box as the default/selected item.
  2752. /// </summary>
  2753. private void SelectTheLatestHeader()
  2754. {
  2755. if(currentComboBox.Items.Count >= 2)
  2756. {
  2757. currentComboBox.SelectedIndex = currentComboBox.Items.Count - 2;
  2758. }
  2759. else
  2760. {
  2761. showDialog = false;
  2762. currentComboBox.SelectedIndex = currentComboBox.Items.Count - 1;
  2763. }
  2764. }
  2765. #endregion
  2766. }
  2767. #endregion
  2768. #region OutHeaderComboBoxController
  2769. /// <summary>
  2770. /// Represents a custom controller for dynamically created controls
  2771. /// to hold header messages for output message.
  2772. /// </summary>
  2773. private class OutHeaderComboBoxController
  2774. {
  2775. #region Private fields
  2776. private bool showDialog;
  2777. private ComboBox currentComboBox;
  2778. private CheckBox currentCheckBox;
  2779. private TextBox currentMessageNameTextBox;
  2780. private Operation currentOperation;
  2781. private Message currentMessage;
  2782. private MessageHeader currentHeader;
  2783. private Message headerMessage;
  2784. private SchemaElements headerElements;
  2785. private MessagesCollection headerMessages;
  2786. private LinkLabel currentRemoveButton;
  2787. #endregion
  2788. #region Constructors
  2789. /// <summary>
  2790. /// Initializes a new instance of OutHeaderComboBoxController class with specified values.
  2791. /// </summary>
  2792. /// <param name="headerComboBox">Reference to the combo box which contains the headers.</param>
  2793. /// <param name="headerCheckBox">Reference to the check box which indicates whether to use the message header(s) or not.</param>
  2794. /// <param name="messageNameTextBox">Reference to the text box which contains the customized message name.</param>
  2795. /// <param name="operation">Reference to the instance of <see cref="Operation"/> class, <see cref="MessageHeader"/> belongs to.</param>
  2796. /// <param name="message">Reference to the instance of <see cref="Message"/> class, <see cref="MessageHeader"/> belongs to.</param>
  2797. /// <param name="header">Reference to the current <see cref="MessageHeader"/> of the message.</param>
  2798. /// <param name="headerElements">Reference to an instance of <see cref="SchemaElements"/> class with schema elements for headers.</param>
  2799. /// <param name="removeButton">Reference to the link label control used to remove headers.</param>
  2800. /// <param name="addedMessages">Reference to an instance of <see cref="MessagesCollection"/> class with <see cref="Message"/> objects added for the header.</param>
  2801. public OutHeaderComboBoxController(ComboBox headerComboBox,
  2802. CheckBox headerCheckBox,
  2803. TextBox messageNameTextBox,
  2804. Operation operation,
  2805. Message message,
  2806. MessageHeader header,
  2807. SchemaElements headerElements,
  2808. LinkLabel removeButton,
  2809. MessagesCollection addedMessages)
  2810. {
  2811. currentComboBox = headerComboBox;
  2812. currentCheckBox = headerCheckBox;
  2813. currentMessageNameTextBox = messageNameTextBox;
  2814. currentOperation = operation;
  2815. currentMessage = message;
  2816. currentHeader = header;
  2817. this.headerElements = headerElements;
  2818. this.headerMessages = new MessagesCollection();
  2819. if(addedMessages != null)
  2820. {
  2821. foreach(Message impHeader in addedMessages)
  2822. {
  2823. this.headerMessages.Add(impHeader);
  2824. }
  2825. }
  2826. this.currentRemoveButton = removeButton;
  2827. this.showDialog = true;
  2828. // Attach the event handlers.
  2829. currentCheckBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
  2830. currentComboBox.SelectedIndexChanged +=
  2831. new EventHandler(ComboBox_SelectedIndexChanged);
  2832. currentMessageNameTextBox.LostFocus += new EventHandler(TextBox_FocusOver);
  2833. currentRemoveButton.Click += new EventHandler(this.RemoveLink_Click);
  2834. }
  2835. #endregion
  2836. #region Event handlers
  2837. /// <summary>
  2838. /// Performs the actions when text box focus changes.
  2839. /// </summary>
  2840. /// <param name="sender">The event source.</param>
  2841. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2842. /// <remarks>When the content of the text box changes, this procedure adjusts the name of the
  2843. /// header message accordingly.</remarks>
  2844. private void TextBox_FocusOver(object sender, EventArgs e)
  2845. {
  2846. if (headerMessage != null) headerMessage.Name = currentMessageNameTextBox.Text + "Header";
  2847. if (currentHeader != null)
  2848. {
  2849. currentHeader.Message = currentMessageNameTextBox.Text + "Header";
  2850. }
  2851. }
  2852. /// <summary>
  2853. /// Performs the actions when the status of the check box control changes.
  2854. /// </summary>
  2855. /// <param name="sender">The event source.</param>
  2856. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2857. /// <remarks>If the check box is checked, this method will enable the combo box which displays the
  2858. /// headers. Then it calls the <see cref="AddNewHeader"/> method to add a new header.
  2859. /// If the check box is unchecked this method will perform the following tasks.
  2860. /// 1. Removes the header messages from the <see cref="Operation"/>.
  2861. /// 2. Clears the HeadersCollection of the current <see cref="Message"/>.
  2862. /// 3. Removes the items from the combo box which displays the headers.
  2863. /// 4. Disables the combo box.
  2864. /// </remarks>
  2865. private void CheckBox_CheckedChanged(object sender, EventArgs e)
  2866. {
  2867. if(currentCheckBox.Checked)
  2868. {
  2869. currentComboBox.Enabled = true;
  2870. this.AddNewHeader();
  2871. }
  2872. else
  2873. {
  2874. // Remove the Header messages from the operation
  2875. foreach(Message msg in this.headerMessages)
  2876. {
  2877. this.currentOperation.MessagesCollection.Remove(msg);
  2878. }
  2879. // Clear the headers for the current message.
  2880. this.currentMessage.HeadersCollection.Clear();
  2881. // Clear the header messages collection.
  2882. this.headerMessages.Clear();
  2883. // Remove the items on the combo box.
  2884. while(this.currentComboBox.Items.Count != 1)
  2885. {
  2886. this.currentComboBox.Items.RemoveAt(0);
  2887. }
  2888. // Finally disable the combo box.
  2889. showDialog = false;
  2890. currentComboBox.SelectedIndex = currentComboBox.Items.Count - 1;
  2891. currentComboBox.Enabled = false;
  2892. currentRemoveButton.Visible = false;
  2893. }
  2894. }
  2895. /// <summary>
  2896. /// Performs the actions when the selected index of the header messages combo box changes.
  2897. /// </summary>
  2898. /// <param name="sender">The event source.</param>
  2899. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2900. /// <remarks>If the selected item is the last item of the list, the method will call the
  2901. /// <see cref="AddNewHeader"/> method. Otherwise it shows the remove button to remove the
  2902. /// selected header.</remarks>
  2903. private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
  2904. {
  2905. if(currentComboBox.SelectedIndex == currentComboBox.Items.Count - 1)
  2906. {
  2907. currentRemoveButton.Visible = false;
  2908. if(showDialog) AddNewHeader();
  2909. showDialog = true;
  2910. }
  2911. else
  2912. {
  2913. currentRemoveButton.Visible = true;
  2914. }
  2915. }
  2916. /// <summary>
  2917. /// Performs the actions when the remove link label is clicked.
  2918. /// </summary>
  2919. /// <param name="sender">The event source.</param>
  2920. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  2921. /// <remarks>This method removes the <see cref="MessageHeader"/> from the <see cref="Message"/>
  2922. /// and <see cref="Message"/> from the <see cref="Operation"/>. </remarks>
  2923. private void RemoveLink_Click(object sender, EventArgs e)
  2924. {
  2925. // Remove the header message.
  2926. Message msg = headerMessages[currentComboBox.SelectedIndex];
  2927. currentOperation.MessagesCollection.Remove(msg);
  2928. currentMessage.HeadersCollection.RemoveAt(currentComboBox.SelectedIndex);
  2929. headerMessages.RemoveAt(currentComboBox.SelectedIndex);
  2930. currentComboBox.Items.RemoveAt(currentComboBox.SelectedIndex);
  2931. // Change the current index of the combo box.
  2932. SelectTheLatestHeader();
  2933. }
  2934. #endregion
  2935. #region Private methods
  2936. /// <summary>
  2937. /// Prompts a dialog box to select the new header. Once it is selected this method adds it to
  2938. /// <see cref="Message.HeadersCollection"/>. Also this method creates a new <see cref="Message"/>
  2939. /// for the header and puts it to the <see cref="Operation.MessagesCollection"/>.
  2940. /// </summary>
  2941. private void AddNewHeader()
  2942. {
  2943. SchemaElement newHeaderMessage = new SchemaElement();
  2944. SelectHeaderDialog dialog = new SelectHeaderDialog(this.headerElements, ref newHeaderMessage);
  2945. dialog.ShowDialog();
  2946. if(newHeaderMessage.ElementName != null)
  2947. {
  2948. // First check whether the header already exists. And remove it if it does.
  2949. foreach(Message msg in this.headerMessages)
  2950. {
  2951. if(newHeaderMessage.ElementName == msg.Element.ElementName &&
  2952. newHeaderMessage.ElementNamespace == msg.Element.ElementNamespace)
  2953. {
  2954. // Set the last item before returning.
  2955. SelectTheLatestHeader();
  2956. return; // Exit without adding.
  2957. }
  2958. }
  2959. string headerName = "";
  2960. int index = 1;
  2961. while(headerName == "")
  2962. {
  2963. headerName = currentMessage.Name + "Header" + index.ToString();
  2964. foreach(MessageHeader hdr in currentMessage.HeadersCollection)
  2965. {
  2966. if(hdr.Name == headerName)
  2967. {
  2968. headerName = "";
  2969. index++;
  2970. break;
  2971. }
  2972. }
  2973. }
  2974. // Create the header message.
  2975. headerMessage = new Message();
  2976. headerMessage.Name = headerName; // currentMessage.Name + "Header" + headerNo;
  2977. headerMessage.Documentation = "";
  2978. headerMessage.Element.ElementName = newHeaderMessage.ElementName;
  2979. headerMessage.Element.ElementNamespace = newHeaderMessage.ElementNamespace;
  2980. // Create the header.
  2981. MessageHeader newHeader = new MessageHeader();
  2982. newHeader.Message = headerMessage.Name;
  2983. newHeader.Name = headerMessage.Name;
  2984. // Add header to the current message.
  2985. currentMessage.HeadersCollection.Add(newHeader);
  2986. // Add the new header message to the messages collection.
  2987. currentOperation.MessagesCollection.Add(headerMessage);
  2988. // Added the newly created header message to the header messages collection.
  2989. // Reason: In case we need to remove the header messages we need to distinguish
  2990. // them from the existing messages.
  2991. this.headerMessages.Add(headerMessage);
  2992. // Add the newly added header info to the headers combo box.
  2993. currentComboBox.Items.Insert(currentComboBox.Items.Count - 1,
  2994. headerMessage.Element.ElementName);
  2995. // Set the last selected header message as the default header.
  2996. currentComboBox.SelectedIndex = currentComboBox.Items.Count - 2;
  2997. }
  2998. }
  2999. /// <summary>
  3000. /// Sets the last item on the headers combo box as the default/selected item.
  3001. /// </summary>
  3002. private void SelectTheLatestHeader()
  3003. {
  3004. if(currentComboBox.Items.Count >= 2)
  3005. {
  3006. currentComboBox.SelectedIndex = currentComboBox.Items.Count - 2;
  3007. }
  3008. else
  3009. {
  3010. showDialog = false;
  3011. currentComboBox.SelectedIndex = currentComboBox.Items.Count - 1;
  3012. }
  3013. }
  3014. #endregion
  3015. }
  3016. #endregion
  3017. #region MessageDocumentationTextBoxController
  3018. /// <summary>
  3019. /// Represents a custom controller to handle the dynamically created text box which contains the <see cref="Message"/> documentation.
  3020. /// </summary>
  3021. private class MessageDocumentationTextBoxController
  3022. {
  3023. #region Private fields
  3024. private TextBox currentTextBox;
  3025. private Message message;
  3026. #endregion
  3027. #region Constructors
  3028. /// <summary>
  3029. /// Initializes a new instance of MessageDocumentationTextBoxController class with specified values.
  3030. /// </summary>
  3031. /// <param name="documentationTextBox">Reference to the text box control which contains the documentation.</param>
  3032. /// <param name="message">Reference to an instance of <see cref="Message"/> class which belongs the documentation.</param>
  3033. public MessageDocumentationTextBoxController(TextBox documentationTextBox, Message message)
  3034. {
  3035. this.currentTextBox = documentationTextBox;
  3036. this.message = message;
  3037. // Attach the event handlers.
  3038. currentTextBox.TextChanged += new EventHandler(TextBox_TextChanged);
  3039. }
  3040. #endregion
  3041. #region Event handlers
  3042. /// <summary>
  3043. /// Performs the actions when the text box content changes.
  3044. /// </summary>
  3045. /// <param name="sender">The event source.</param>
  3046. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  3047. /// <remarks>This method updates the <see cref="Message"/> object's documentation property.</remarks>
  3048. private void TextBox_TextChanged(object sender, EventArgs e)
  3049. {
  3050. this.message.Documentation = currentTextBox.Text;
  3051. }
  3052. #endregion
  3053. }
  3054. #endregion
  3055. #region OperationDocumentationTextBoxController
  3056. /// <summary>
  3057. /// Represents a custom controller to handle the dynamically created text box which contains the <see cref="Operation"/> documentation.
  3058. /// </summary>
  3059. private class OperationDocumentationTextBoxController
  3060. {
  3061. #region Private fields
  3062. private TextBox currentTextBox;
  3063. private Operation operation;
  3064. #endregion
  3065. #region Constructors
  3066. /// <summary>
  3067. /// Initializes a new instance of OperationDocumentationTextBoxController class with specified values.
  3068. /// </summary>
  3069. /// <param name="documentationTextBox">Reference to the text box control which contains the documentation.</param>
  3070. /// <param name="operation">Reference to an instance of <see cref="Operation"/> class which belongs the documentation.</param>
  3071. public OperationDocumentationTextBoxController(TextBox documentationTextBox, Operation operation)
  3072. {
  3073. this.currentTextBox = documentationTextBox;
  3074. this.operation = operation;
  3075. // Attach the event handlers.
  3076. currentTextBox.TextChanged += new EventHandler(TextBox_TextChanged);
  3077. }
  3078. #endregion
  3079. #region Event handlers
  3080. /// <summary>
  3081. /// Performs the actions when the text box content changes.
  3082. /// </summary>
  3083. /// <param name="sender">The event source.</param>
  3084. /// <param name="e">An instance of <see cref="EventArgs"/> class with event data.</param>
  3085. /// <remarks>This method updates the <see cref="Operation"/> object's documentation property.</remarks>
  3086. private void TextBox_TextChanged(object sender, EventArgs e)
  3087. {
  3088. this.operation.Documentation = currentTextBox.Text;
  3089. }
  3090. #endregion
  3091. }
  3092. #endregion
  3093. }
  3094. }