예제 #1
0
        private void InferRequestResponseOperations()
        {
            // Infer two-way operations.
            foreach (SchemaElement melement in MessageSchemas)
            {
                foreach (string pattern in operationNamePatterns.Keys)
                {
                    string operationName = "";
                    if (melement.ElementName.EndsWith(pattern))
                    {
                        string responsePattern = operationNamePatterns[pattern].ToString();

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

                        if (MessageSchemas.Contains(responseElement))
                        {
                            // Check whether the operation exists in the imported operations list.
                            bool exists = false;
                            foreach (Operation impOp in this.Operations)
                            {
                                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.
                            this.twoWayOperations.Add(op);
                            this.Operations.Add(op);

                            // Exit this loop.
                            break;
                        }
                    }
                }
            }
        }