예제 #1
0
        public void AddSchemasToContract(NameValueCollection schemasAndLocations, string workingFolder, string projectRootFolder)
        {
            //TODO:(SB): Will need to have a way to add header and message schemas separately
            string    schemaNamespace          = String.Empty;
            ArrayList importedSchemaNamespaces = new ArrayList();


            // Add the selected schemas to the ServiceInterfaceContract.Imports collection.
            foreach (string key in schemasAndLocations.Keys)
            {
                string    schemaName     = key;
                string    schemaLocation = schemasAndLocations[key];
                ArrayList result;
                // Read the content of the imported files and add them to the local arrays for UI.
                result = SchemaUtility.GetSchemasFromXsd(schemaLocation, out schemaNamespace);

                if (schemaNamespace != null)
                {
                    importedSchemaNamespaces.Add(schemaNamespace.ToLower());
                }
                MessageSchemas.AddRange((List <SchemaElement>)result[1]);
                HeaderSchemas.AddRange((List <SchemaElement>)result[1]);

                SchemaImport si = new SchemaImport(schemaLocation, schemaName, schemaNamespace, workingFolder, projectRootFolder);

                this.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)
            {
                throw new Exception("There are no elements in this XSD to use as operation messages.");
            }
        }
예제 #2
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;
                        }
                    }
                }
            }
        }