Represents the contents of Schema Element in a XML document.
Example #1
0
        /// <summary>
        /// Initializes a new instance of SelectHeaderDialog class.
        /// </summary>
        /// <param name="headerSchemas">Reference to an instance of <see cref="SchemaElements"/> class.</param>
        /// <param name="selectedHeader">Reference to an instance of <see cref="SchemaElement"/> class.</param>
        /// <remarks>The headerSchemas parameter contains the header schemas available for the wizard.
        /// This collection is used to fill the cbHeaderMessage combo box later. selectedHeader parameter is
        /// used to return the selected header value from the dialog box to the caller.
        /// </remarks>
        public SelectHeaderDialog(SchemaElements headerSchemas, 
			ref SchemaElement selectedHeader)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.headerSchemas = headerSchemas;
            this.selectedHeader = selectedHeader;

            closingByForce = true;
        }
Example #2
0
        /// <summary>
        /// Infers the operations according to the message name patterns in the message contracts.
        /// </summary>
        private void InferOperations()
        {
            // Define a hash table with list of request/response patterns.
            Dictionary<string, string> patterns = new Dictionary<string, string>();
            patterns.Add("", "Response");
            patterns.Add("Request", "Response");
            patterns.Add("RequestMessage", "ResponseMessage");

            SchemaElements usedElements = new SchemaElements();

            // Infer two-way operations.
            foreach(SchemaElement melement in messageSchemas)
            {
                foreach(string requestPattern in patterns.Keys)
                {
                    string operationName = "";
                    if(melement.ElementName.EndsWith(requestPattern))
                    {
                        string responsePattern = patterns[requestPattern];

                        // Create the response element.
                        SchemaElement responseElement = new SchemaElement();
                        if(requestPattern == "")
                        {
                            operationName = melement.ElementName;
                            responseElement.ElementName = melement.ElementName + responsePattern;
                        }
                        else
                        {
                            if(melement.ElementName == requestPattern)
                            {
                                operationName = melement.ElementName;
                                responseElement.ElementName = responsePattern;
                            }
                            else
                            {
                                operationName =
                                    melement.ElementName.Substring(0,
                                    melement.ElementName.LastIndexOf(requestPattern));
                                responseElement.ElementName =
                                    melement.ElementName.Substring(0,
                                    melement.ElementName.LastIndexOf(requestPattern)) + responsePattern;
                            }
                        }
                        responseElement.ElementNamespace = melement.ElementNamespace;

                        if(messageSchemas.Contains(responseElement))
                        {
                            // Check whether the operation exists in the imported operations list.
                            bool exists = false;
                            if(importedContract != null)
                            {
                                foreach(Operation impOp in importedContract.OperationsCollection)
                                {
                                    if(impOp.Input.Element == melement &&
                                        (impOp.Output != null && impOp.Output.Element == responseElement))
                                    {
                                        exists = true;
                                        break;
                                    }
                                }
                            }

                            if(exists)
                            {
                                break;
                            }

                            // Add the operation to the list.
                            Operation op = new Operation();
                            op.Name = operationName;
                            op.Documentation = "";
                            op.Mep = Mep.RequestResponse;

                            string opName = op.Name;
                            string opNamePrefix = opName.Substring(0, 1);
                            opNamePrefix = opNamePrefix.ToLower(CultureInfo.CurrentCulture);
                            opName = op.Name.Substring(1, op.Name.Length - 1);
                            opName = opNamePrefix + opName;

                            // Add the input message.
                            Message input = new Message();
                            input.Name = opName + "In";
                            input.Element = melement;
                            input.Documentation = "";
                            op.MessagesCollection.Add(input);
                            op.Input = input;

                            // Add the output message.
                            Message output = new Message();
                            output.Name = opName + "Out";
                            output.Element = responseElement;
                            output.Documentation = "";
                            op.MessagesCollection.Add(output);
                            op.Output = output;

                            // Add the operation to the inferred operations collection.
                            inferOperations.Add(op);

                            // Add the operation to the list view.
                            ListViewItem listViewItem1 =
                                new ListViewItem(new string[] {
                                op.Name,
                                "Request/Response",
                                "",
                                ""},
                                -1);

                            listViewItem1.Tag = op.Name;
                            operationsListView.Items.AddRange(
                                new ListViewItem[] {listViewItem1});

                            usedElements.Add(melement);
                            usedElements.Add(responseElement);
                            // Exit this loop.
                            break;
                        }
                    }
                }
            }

            // Infer one-way operations.
            foreach(SchemaElement melement in messageSchemas)
            {
                foreach(string requestPattern in patterns.Keys)
                {
                    string operationName = "";
                    if(melement.ElementName.EndsWith(requestPattern))
                    {
                        if(!usedElements.Contains(melement))
                        {
                            // Check whether the operation exists in the imported operations list.
                            bool exists = false;
                            if(importedContract != null)
                            {
                                foreach(Operation impOp in importedContract.OperationsCollection)
                                {
                                    if(impOp.Input.Element == melement  ||
                                        (impOp.Output != null && impOp.Output.Element == melement))
                                    {
                                        exists = true;
                                        break;
                                    }
                                }
                            }

                            if(exists)
                            {
                                break;
                            }

                            // Compose the operation name.
                            if(requestPattern == "")
                            {
                                operationName = melement.ElementName;
                            }
                            else
                            {
                                if(melement.ElementName == requestPattern)
                                {
                                    operationName = melement.ElementName;
                                }
                                else
                                {
                                    operationName =
                                        melement.ElementName.Substring(0,
                                        melement.ElementName.LastIndexOf(requestPattern));
                                }
                            }

                            // Add the operation to the list.
                            Operation op = new Operation();
                            op.Name = operationName;
                            op.Documentation = "";
                            op.Mep = Mep.OneWay;

                            string opName = op.Name;
                            string opNamePrefix = opName.Substring(0, 1);
                            opNamePrefix = opNamePrefix.ToLower(CultureInfo.CurrentCulture);
                            opName = op.Name.Substring(1, op.Name.Length - 1);
                            opName = opNamePrefix + opName;

                            // Add the input message.
                            Message input = new Message();
                            input.Name = opName + "In";
                            input.Element = melement;
                            input.Documentation = "";
                            op.MessagesCollection.Add(input);
                            op.Input = input;

                            // Add the operation to the inferred operations collection.
                            inferOperations.Add(op);

                            // Add the operation to the list view.
                            ListViewItem listViewItem1 =
                                new ListViewItem(new string[] {
                                    op.Name,
                                    "One-Way",
                                    "",
                                    ""},
                                -1);

                            listViewItem1.Tag = op.Name;
                            operationsListView.Items.AddRange(
                                new ListViewItem[] {listViewItem1});
                        }
                        // Exit this loop.
                        break;
                    }
                }
            }
        }
Example #3
0
            /// <summary>
            /// Prompts a dialog box to select the new header. Once it is selected this method adds it to 
            /// <see cref="Message.HeadersCollection"/>. Also this method creates a new <see cref="Message"/>
            /// for the header and puts it to the <see cref="Operation.MessagesCollection"/>.
            /// </summary>
            private void AddNewHeader()
            {
                SchemaElement newHeaderMessage = new SchemaElement();
                SelectHeaderDialog dialog = new SelectHeaderDialog(this.headerElements, ref newHeaderMessage);
                dialog.ShowDialog();

                if(newHeaderMessage.ElementName != null)
                {
                    // First check whether the header already exists. And remove it if it does.
                    foreach(Message msg in this.headerMessages)
                    {
                        if(newHeaderMessage.ElementName == msg.Element.ElementName &&
                            newHeaderMessage.ElementNamespace == msg.Element.ElementNamespace)
                        {
                            // Set the last item before returning.
                            SelectTheLatestHeader();

                            return; // Exit without adding.
                        }
                    }

                    string headerName = "";
                    int index = 1;
                    while(headerName == "")
                    {
                        headerName = currentMessage.Name + "Header" + index.ToString();
                        foreach(MessageHeader  hdr in currentMessage.HeadersCollection)
                        {
                            if(hdr.Name == headerName)
                            {
                                headerName = "";
                                index++;
                                break;
                            }
                        }
                    }

                    // Create the header message.
                    headerMessage = new Message();
                    headerMessage.Name = headerName; // currentMessage.Name + "Header" + headerNo;
                    headerMessage.Documentation = "";
                    headerMessage.Element.ElementName = newHeaderMessage.ElementName;
                    headerMessage.Element.ElementNamespace = newHeaderMessage.ElementNamespace;

                    // Create the header.
                    MessageHeader newHeader = new MessageHeader();
                    newHeader.Message = headerMessage.Name;
                    newHeader.Name = headerMessage.Name;

                    // Add header to the current message.
                    currentMessage.HeadersCollection.Add(newHeader);

                    // Add the new header message to the messages collection.
                    currentOperation.MessagesCollection.Add(headerMessage);

                    // Added the newly created header message to the header messages collection.
                    // Reason: In case we need to remove the header messages we need to distinguish
                    // them from the existing messages.
                    this.headerMessages.Add(headerMessage);

                    // Add the newly added header info to the headers combo box.
                    currentComboBox.Items.Insert(currentComboBox.Items.Count - 1,
                        headerMessage.Element.ElementName);

                    // Set the last selected header message as the default header.
                    currentComboBox.SelectedIndex = currentComboBox.Items.Count - 2;
                }
            }
		/// <summary>
		/// Checks whether a given schema element exists in the collection.
		/// </summary>
		/// <param name="value">Reference to an instance of SchemaElement class to find.</param>
		/// <returns>A value indicating whether the schema element is found in the collection or not.</returns>
		public bool Contains(SchemaElement value)
		{
			foreach(SchemaElement e in this.InnerList)
			{
				if(e.ElementName.ToLower() == value.ElementName.ToLower() && 
					e.ElementNamespace.ToLower() == value.ElementNamespace.ToLower())
				{
					return true;
				}
			}

			return false;
		}
		/// <summary>
		/// Adds the specified <see cref="SchemaElement"/> to the end of the SchemaElements collection. 
		/// </summary>
		/// <param name="value">The <see cref="SchemaElement"/> to add to the collection.</param>
		/// <returns>The zero-based index where the value parameter has been added.</returns>
		public int Add(SchemaElement value)
		{
			return this.InnerList.Add(value);
		}
		/// <summary>
		/// Initializes a new instance of the Message class.
		/// </summary>
		public Message()
		{
			element = new SchemaElement();
		}
Example #7
0
 /// <summary>
 /// Adds the specified <see cref="SchemaElement"/> to the end of the SchemaElements collection.
 /// </summary>
 /// <param name="value">The <see cref="SchemaElement"/> to add to the collection.</param>
 /// <returns>The zero-based index where the value parameter has been added.</returns>
 public int Add(SchemaElement value)
 {
     return(this.InnerList.Add(value));
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the Message class.
 /// </summary>
 public Message()
 {
     element = new SchemaElement();
 }