/// <summary>
        /// Performs the actions prior to displaying each page on the wizard control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An instance of <see cref="WizardPageDisplayedEventArgs"/> class with event data.</param>
        private void wsdlWizardCtrl_BeforePageDisplayed(object sender, WizardPageDisplayedEventArgs e)
        {
            // Assign the basic meta data values to the instance of InterfaceContract class.
            if (e.Page == wizardPageSchemaImports)
            {
                bool isValid = InterfaceContract.ValidateUri(tbNamespace.Text);
                if (!isValid)
                {
                    DisplayError("Invalid uri for the namespace. Enter a valid uri and try again.");
                    e.Cancel = true;
                    return;
                }

                serviceInterfaceContract.InitializeServiceInfo(tbServiceName.Text, tbNamespace.Text, schemaNamespace, tbServiceDoc.Text);


                return;
            }

            if (e.Page == wizardPageOperationsList)
            {
                try
                {
                    //Load the dropdown for the operation types
                    LoadOperationsListViewWithMEP();
                    AddSchemasToContract();
                }
                catch (Exception ex)
                {
                    DisplayError(ex.Message);
                    e.Cancel = true;
                    return;

                }
            }

            if (e.Page == wizardPageMessageMapping)
            {
                try
                {
                    //Update the list of operations prior to setting up the panes
                    UpdateOperations();
                    // Setup the dynamic UI controls for the operation - message mapping UI.
                    SetupOperationsMessagesPanes();

                    if (ptvServiceOperations.PaneNodes.Count > 0)
                    {
                        ptvServiceOperations.SelectedPaneNode = ptvServiceOperations.PaneNodes[0];
                        ptvServiceOperations.PaneNodes[0].Expanded = true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                return;
            }

            if (e.Page == wizardPageAdditionalOptions)
            {
                cbCodeGenDialog.Checked = this.roundtripMode;
                return;
            }

            if (e.Page == wizardPageAlternativeXSDPaths)
            {
                xsdpathsListView.Items.Clear();
                if (serviceInterfaceContract.Imports.Count > 0)
                {
                    foreach (SchemaImport import in serviceInterfaceContract.Imports)
                    {
                        ListViewItem li = new ListViewItem(import.SchemaName);
                        li.SubItems.Add(import.AlternateLocation);
                        xsdpathsListView.Items.Add(li);
                    }
                }
                else
                {
                    wsdlWizardCtrl.AdvancePage();
                }
                return;
            }
        }
Пример #2
0
        /// <summary>
        /// Performs the actions prior to displaying each page on the wizard control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An instance of <see cref="WizardPageDisplayedEventArgs"/> class with event data.</param>
        private void wsdlWizardCtrl_BeforePageDisplayed(object sender, WizardPageDisplayedEventArgs e)
        {
            // Assign the basic meta data values to the instance of InterfaceContract class.
            if (e.Page == wizardPageSchemaImports)
            {
                // 07-23-2005
                // BDS: Added this gate to validate the namespace uri.
                Uri uri;
                try
                {
                    if (tbNamespace.Text.IndexOf(":") > -1 || Path.IsPathRooted(tbNamespace.Text))
                    {
                        uri = new Uri(tbNamespace.Text);
                    }
                    else
                    {
                        uri = new Uri("anyuri:" + tbNamespace.Text);
                    }
                }
                catch
                {
                    MessageBox.Show(this,
                        "Invalid uri for the namespace. Enter a valid uri and try again.",
                        "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                    return;
                }

                serviceInterfaceContract.ServiceName = tbServiceName.Text;
                serviceInterfaceContract.ServiceNamespace = tbNamespace.Text;
                serviceInterfaceContract.SchemaNamespace = schemaNamespace;
                serviceInterfaceContract.ServiceDocumentation = tbServiceDoc.Text;

                return;
            }

            if (e.Page == wizardPageOperationsList)
            {
                // Clear the existing items.
                this.messageSchemas.Clear();
                this.headerSchemas.Clear();
                faultSchemas.Clear();
                this.importedSchemaNamespaces.Clear();
                this.serviceInterfaceContract.Imports.Clear();

                // Add the selected schemas to the ServiceInterfaceContract.Imports collection.
                foreach (ListViewItem importItem in importsListView.Items)
                {
                    string schemaNamespace = string.Empty;
                    string importLocation = importItem.SubItems[1].Text;
                    ArrayList result;
                    try
                    {
                        // Read the content of the imported files and add them to the local arrays for UI.
                         result = ServiceDescriptionEngine.GetSchemasFromXsd(importLocation, out schemaNamespace);
                    }
                    catch(Exception ex)
                    {
                        MessageBox.Show(this, ex.Message,
                       "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        e.Cancel = true;
                        return;
                    }

                    // Check whether the schema has a valid namespace.
                    //if (schemaNamespace == null)
                    //{
                    //    MessageBox.Show(this, "Could not import the file: " +
                    //        importLocation + ". The schema definition does not belong to a valid namespace.",
                    //        "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //    wsdlWizardCtrl.JumpToPage(2);
                    //    return;
                    //}

                    //// Check whether the Namespace already exists in the list.
                    //if (this.importedSchemaNamespaces.IndexOf(schemaNamespace.ToLower()) > -1)
                    //{
                    //    MessageBox.Show(this, "Could not import the file: " +
                    //        importLocation + ". The Target Namespace already imported.",
                    //        "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //    wsdlWizardCtrl.JumpToPage(2);
                    //    return;
                    //}
                    //else
                    //{
                        if(schemaNamespace != null)
                            this.importedSchemaNamespaces.Add(schemaNamespace.ToLower());
                    //}

                    messageSchemas.AddRange((SchemaElements)result[1]);
                    headerSchemas.AddRange((SchemaElements)result[1]);
                    faultSchemas.AddRange((SchemaElements)result[1]);

                    SchemaImport si = new SchemaImport(importItem.SubItems[1].Text, schemaNamespace, importItem.SubItems[0].Text);

                    // Check whether the schema is in the current directory.
                    if (Directory.GetFiles(this.wsdlLocation, si.SchemaName).Length > 0)
                    {
                        si.AlternateLocation = si.SchemaName;
                    }
                    else if (si.SchemaLocation.ToLower().StartsWith(this.projectRootDirectory.ToLower()))
                    {
                        string schemaDirectory = si.SchemaLocation.Substring(
                            0, si.SchemaLocation.LastIndexOf('\\'));
                        string currentDirectory = wsdlLocation;
                        // Remove the project root before passing them to the relative path finder.
                        schemaDirectory = schemaDirectory.Substring(this.projectRootDirectory.Length);
                        currentDirectory = currentDirectory.Substring(this.projectRootDirectory.Length);

                        si.AlternateLocation = IOPathHelper.GetRelativePath(schemaDirectory, currentDirectory);
                        if (si.AlternateLocation.EndsWith("/"))
                        {
                            si.AlternateLocation = si.AlternateLocation + si.SchemaName;
                        }
                        else
                        {
                            si.AlternateLocation = si.AlternateLocation + "/" + si.SchemaName;
                        }
                    }
                    else
                    {
                        si.AlternateLocation = si.SchemaLocation;
                    }
                    serviceInterfaceContract.Imports.Add(si);
                }

                // Import the embedded types.
                ImportEmbeddedTypes();

                // Check for the messages count found in the imported files and alert the user if no messages
                // are found.
                if (messageSchemas.Count < 1)
                {
                    MessageBox.Show("There are no elements in this XSD to use as operation messages.",
                        "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.Cancel = true;
                    return;
                }

                return;
            }

            if (e.Page == wizardPageMessageMapping)
            {
                try
                {
                    // Setup the dynamic UI controls for the operation - message mapping UI.
                    SetupOperationsMessagesPanes();

                    if (ptvServiceOperations.PaneNodes.Count > 0)
                    {
                        ptvServiceOperations.SelectedPaneNode = ptvServiceOperations.PaneNodes[0];
                        ptvServiceOperations.PaneNodes[0].Expanded = true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                return;
            }

            if (e.Page == wizardPageAdditionalOptions)
            {
                cbCodeGenDialog.Checked = this.roundtripMode;
                return;
            }

            if (e.Page == wizardPageAlternativeXSDPaths)
            {
                xsdpathsListView.Items.Clear();
                if (serviceInterfaceContract.Imports.Count > 0)
                {
                    foreach (SchemaImport import in serviceInterfaceContract.Imports)
                    {
                        ListViewItem li = new ListViewItem(import.SchemaName);
                        li.SubItems.Add(import.AlternateLocation);
                        xsdpathsListView.Items.Add(li);
                    }
                }
                else
                {
                    wsdlWizardCtrl.AdvancePage();
                }
                return;
            }
        }