Exemple #1
0
        // Beállítja a megfelelő referenciákat
        private void Linking()
        {
            foreach (StoreItem coll in store)
            {
                XElement def = coll.definition;

                switch (coll.objectType)
                {
                    case StoreItemType.service:
                        {
                            Wr("Processing: (" + coll.objectType + ")" + coll.name);
                            Endpoint ep = (Endpoint)coll.objRef;

                            // binding beállítása:
                            string bindingName = (string)def.Element(wsdlNS + "port").Attribute("binding");
                            StoreItem bindingObject = SearchObject(StoreItemType.binding, bindingName, def);
                            ep.Binding = (Binding)bindingObject.objRef;
                            Wr("   -add binding: " + ep.Binding.Name);

                            // interface beállítása
                            string interfaceName = (string)bindingObject.definition.Attribute("type");
                            StoreItem interfaceObject = SearchObject(StoreItemType.portType, interfaceName, bindingObject.definition);
                            ep.Interface = (Interface)interfaceObject.objRef;
                            Wr("   -add interface: " + ep.Interface.Name);

                            // Address beállítása
                            string location = "";
                            try
                            {
                                location = (string)def.Element(wsdlNS + "port").Element(soapNS + "address").Attribute("location");
                            }
                            catch (Exception) { }

                            try
                            {
                                location = (string)def.Element(wsdlNS + "port").Element(soap12NS + "address").Attribute("location");
                            }
                            catch (Exception) { }
                            EndpointAddress epa = new EndpointAddress(location);
                            ep.Address = epa;
                            Wr("   -add address: " + ep.Address.Uri);
                            ep.Namespace = nsDictionary[coll.ownNS];
                        }
                        break;
                    case StoreItemType.binding:
                        {
                            Wr("Processing: (" + coll.objectType + ")" + coll.name);
                            Binding bi = (Binding)coll.objRef;

                            // interface beállítása
                            //string interfaceName = (string)def.Attribute("type");
                            //StoreItem interfaceObject = SearchObject(StoreItemType.portType, interfaceName, def);
                            //bi.Interface = (Interface)interfaceObject.objRef;
                            //Wr("   -add interface: " + interfaceName);

                            string transport = "";
                            SoapEncodingBindingElement sebe = new SoapEncodingBindingElement();
                            try
                            {
                                transport = (string)def.Element(soapNS + "binding").Attribute("transport");
                                sebe.Version = SoapVersion.Soap11;
                            }
                            catch (Exception) { }

                            try
                            {
                                transport = (string)def.Element(soap12NS + "binding").Attribute("transport");
                                sebe.Version = SoapVersion.Soap12;
                            }
                            catch (Exception) { }
                            HttpTransportBindingElement htbe = new HttpTransportBindingElement();

                            bi.Encoding = sebe;

                            Wr("   -set SOAP version: " + sebe.Version.ToString());
                            bi.Transport = htbe;
                            bi.Namespace = nsDictionary[coll.ownNS];

                        }
                        break;
                    case StoreItemType.portType:
                        {
                            Wr("Processing: (" + coll.objectType + ")" + coll.name);
                            Interface ifa = (Interface)coll.objRef;

                            var operations = from c in def.Descendants(wsdlNS + "operation")
                                             select c;

                            foreach (XElement operation in operations)
                            {

                                string operationName = (string)operation.Attribute("name");
                                Operation op = new Operation()
                                {
                                    Name = operationName
                                };
                                Wr("   -add operation: " + op.Name);

                                XElement input = operation.Element(wsdlNS + "input");
                                if (input == null)
                                {
                                    Wr("     -no inputs");
                                }
                                else
                                {

                                    string inputName = (string)input.Attribute("name");
                                    string messageName = (string)input.Attribute("message");
                                    StoreItem messageObject = SearchObject(StoreItemType.message, messageName, def);

                                    var operationInputs = from c in messageObject.definition.Descendants(wsdlNS + "part")
                                                          select c;
                                    Wr("     -inputs:");

                                    foreach (XElement operationInput in operationInputs)
                                    {
                                        string inputMsgPartName = (string)operationInput.Attribute("name");
                                        string typeName = (string)operationInput.Attribute("type");
                                        string elementName = (string)operationInput.Attribute("element");

                                        if (typeName != null)
                                        {
                                            SoaMetaModel.Type type = SearchType(typeName, def);
                                            OperationParameter opParam = new OperationParameter()
                                            {
                                                Name = inputMsgPartName,
                                                Type = type,
                                                Operation = op
                                            };
                                            op.Parameters.Add(opParam);
                                            Wr("       -add parameter: (" + type.Name + ")" + opParam.Name);
                                        }
                                        else if (elementName != null)
                                        {
                                            StoreItem element = TrySearchObject(StoreItemType.unNamedElementType, elementName, def);
                                            if (operationInputs.Count<XElement>() == 1 &&
                                                elementName.Split(char.Parse(":")).GetValue(1).Equals(operationName))
                                            {
                                                // Ekkor a formázási stílus Document/wrapped
                                                StoreItem concrateType;
                                                if (element == null)
                                                {
                                                    concrateType = TrySearchObject(StoreItemType.structType, elementName, def);
                                                    if (concrateType == null)
                                                    {
                                                        concrateType = SearchObject(StoreItemType.arrayType, elementName, def);
                                                    }

                                                    var elementsInReferencedType = from c in concrateType.definition.Descendants(xsdNS + "element")
                                                                                   select c;
                                                    foreach (XElement elementInReferencedType in elementsInReferencedType)
                                                    {
                                                        string elementInReferencedTypeName = (string)elementInReferencedType.Attribute("name");
                                                        string elementInReferencedTypeType = (string)elementInReferencedType.Attribute("type");

                                                        SoaMetaModel.Type type = SearchType(elementInReferencedTypeType, elementInReferencedType);
                                                        OperationParameter opParam = new OperationParameter()
                                                        {
                                                            Name = elementInReferencedTypeName,
                                                            Type = type,
                                                            Operation = op
                                                        };
                                                        op.Parameters.Add(opParam);
                                                        Wr("       -add parameter: (" + type.Name + ")" + opParam.Name);

                                                    }
                                                }
                                                else
                                                {
                                                    string referencedTypeName = (string)element.definition.Attribute("type");

                                                    SoaMetaModel.Type type = SearchType(referencedTypeName, element.definition);
                                                    OperationParameter opParam = new OperationParameter()
                                                    {
                                                        Name = inputMsgPartName,
                                                        Type = type,
                                                        Operation = op
                                                    };
                                                    op.Parameters.Add(opParam);
                                                    Wr("       -add parameter: (" + type.Name + ")" + opParam.Name);
                                                }

                                            }
                                            else
                                            {
                                                SoaMetaModel.Type type;
                                                if (element == null)
                                                {
                                                    type = SearchType(elementName, def);
                                                }
                                                else
                                                {
                                                    string referencedTypeName = (string)element.definition.Attribute("type");
                                                    type = SearchType(referencedTypeName, element.definition);
                                                }

                                                OperationParameter opParam = new OperationParameter()
                                                {
                                                    Name = inputMsgPartName,
                                                    Type = type,
                                                    Operation = op
                                                };
                                                op.Parameters.Add(opParam);
                                                Wr("       -add parameter: (" + type.Name + ")" + opParam.Name);
                                            }
                                        }
                                        else
                                        {
                                            // TODO
                                        }
                                    }
                                }

                                XElement output = operation.Element(wsdlNS + "output");
                                if (output == null)
                                {
                                    Wr("     -no output");
                                }
                                else
                                {
                                    string outputName = (string)output.Attribute("name");
                                    string messageName = (string)output.Attribute("message");
                                    StoreItem messageObject = SearchObject(StoreItemType.message, messageName, def);

                                    XElement operationOutput = messageObject.definition.Element(wsdlNS + "part");

                                    string typeName = (string)operationOutput.Attribute("type");
                                    string elementName = (string)operationOutput.Attribute("element");

                                    SoaMetaModel.Type type = null;

                                    if (typeName != null)
                                    {
                                        type = SearchType(typeName, def);
                                    }
                                    else if (elementName != null)
                                    {
                                        StoreItem element = TrySearchObject(StoreItemType.unNamedElementType, elementName, def);
                                        if (element == null)
                                        {
                                            type = SearchType(elementName, def);
                                        }
                                        else
                                        {
                                            string referencedTypeName = (string)element.definition.Attribute("type");
                                            type = SearchType(referencedTypeName, element.definition);
                                        }
                                    }
                                    else
                                    {
                                        //TODO
                                    }
                                    op.ReturnType = type;

                                    Wr("     -return type: " + type.Name);
                                }

                                var faults = from c in operation.Descendants(wsdlNS + "fault")
                                             select c;

                                if (faults.Count<XElement>() == 0)
                                {
                                    Wr("     -no faults");
                                }
                                else
                                {
                                    Wr("     -faults:");

                                    foreach (XElement fault in faults)
                                    {
                                        string faultName = (string)fault.Attribute("name");
                                        string messageName = (string)fault.Attribute("message");
                                        StoreItem messageObject = SearchObject(StoreItemType.message, messageName, def);

                                        var operationFaults = from c in messageObject.definition.Descendants(wsdlNS + "part")
                                                              select c;

                                        foreach (XElement operationFault in operationFaults)
                                        {

                                            string FaultMsgPartName = (string)operationFault.Attribute("name");
                                            string typeName = (string)operationFault.Attribute("type");
                                            string elementName = (string)operationFault.Attribute("element");

                                            SoaMetaModel.Type type = null;

                                            if (typeName != null)
                                            {
                                                type = SearchType(typeName, def);
                                            }
                                            else if (elementName != null)
                                            {
                                                StoreItem element = TrySearchObject(StoreItemType.unNamedElementType, elementName, def);
                                                if (element == null)
                                                {
                                                    type = SearchType(elementName, def);
                                                }
                                                else
                                                {
                                                    string referencedTypeName = (string)element.definition.Attribute("type");
                                                    type = SearchType(referencedTypeName, element.definition);
                                                }
                                            }
                                            else
                                            {
                                                //TODO
                                            }

                                            op.Exceptions.Add((ExceptionType)type);

                                            Wr("       -add exception: " + type.Name);
                                        }
                                    }
                                }
                                ifa.Operations.Add(op);
                            }
                            ifa.Namespace = nsDictionary[coll.ownNS];
                        }
                        break;
                    case StoreItemType.enumType:
                        {
                            Wr("Processing: (" + coll.objectType + ")" + coll.name);
                            EnumType et = (EnumType)coll.objRef;

                            var enumValues = from c in def.Descendants(xsdNS + "enumeration")
                                             select c;

                            foreach (XElement enumValue in enumValues)
                            {
                                string value = (string)enumValue.Attribute("value");
                                EnumValue ev = new EnumValue()
                                {
                                    Enum = et,
                                    Name = value
                                };
                                Wr("   -add enumValue: " + ev.Name);

                            }
                            et.Namespace = nsDictionary[coll.ownNS];
                        }
                        break;
                    case StoreItemType.exceptionType:
                        {
                            Wr("Processing: (" + coll.objectType + ")" + coll.name);
                            ExceptionType ex = (ExceptionType)coll.objRef;

                            try
                            {
                                string extensionBase = (string)def.Element(xsdNS + "complexContent").Element(xsdNS + "extension").Attribute("base");
                                SoaMetaModel.Type extType = SearchType(extensionBase, def);
                                ex.SuperType = (ExceptionType)extType;
                                Wr("   -set extension: " + ex.SuperType.Name);
                            }
                            catch (Exception) { Wr("   -no extension"); }

                            var elements = from c in def.Descendants(xsdNS + "element")
                                           select c;

                            foreach (XElement element in elements)
                            {
                                string elementName = (string)element.Attribute("name");
                                string elementType = (string)element.Attribute("type");
                                SoaMetaModel.Type type = SearchType(elementType, def);

                                ExceptionField sf = new ExceptionField()
                                {
                                    Name = elementName,
                                    Exception = ex,
                                    Type = type,
                                };
                                ex.Fields.Add(sf);
                            }
                            ex.Namespace = nsDictionary[coll.ownNS];
                        }
                        break;
                    case StoreItemType.structType:
                        {
                            Wr("Processing: (" + coll.objectType + ")" + coll.name);
                            StructType st = (StructType)coll.objRef;

                            try
                            {
                                string extensionBase = (string)def.Element(xsdNS + "complexContent").Element(xsdNS + "extension").Attribute("base");
                                SoaMetaModel.Type extType = SearchType(extensionBase, def);
                                st.SuperType = (StructType)extType;
                                Wr("   -set extension: " + st.SuperType.Name);
                            }
                            catch (Exception) { Wr("   -no extension"); }

                            var elements = from c in def.Descendants(xsdNS + "element")
                                           select c;

                            foreach (XElement element in elements)
                            {
                                string elementName = (string)element.Attribute("name");
                                string elementType = (string)element.Attribute("type");
                                SoaMetaModel.Type type = SearchType(elementType, def);

                                StructField sf = new StructField()
                                {
                                    Name = elementName,
                                    Struct = st,
                                    Type = type
                                };
                                st.Fields.Add(sf);
                            }
                            st.Namespace = nsDictionary[coll.ownNS];

                        }
                        break;
                    case StoreItemType.arrayType:
                        {
                            Wr("Processing: (" + coll.objectType + ")" + coll.name);
                            ArrayType at = (ArrayType)coll.objRef;

                            try
                            {
                                string typeName = (string)def.Element(xsdNS + "sequence").Element(xsdNS + "element").Attribute("type");
                                SoaMetaModel.Type type = SearchType(typeName, def);
                                at.ItemType = type;
                                Wr("   -set array type: " + at.ItemType.Name);
                            }
                            catch (Exception) { Wr("   -no array type"); }
                            at.Namespace = nsDictionary[coll.ownNS];
                        }
                        break;
                    default: //throw new Exception();
                        break;
                }
                coll.isReady = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// Processes encoding element node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_Encoding(dynamic node)
        {
            EncodingBindingElement encodingBindingElement = null;

            // Type
            if (node.Name == AttributeHelpers.GetTypeName(typeof(SoapEncodingBindingElement)))
            {
                encodingBindingElement = new SoapEncodingBindingElement();
            }
            else
            {
                encodingBindingElement = new EncodingBindingElement();
            }

            // Map source location and node to object
            encodingBindingElement.AddMetaInfo(new SourceLocationInfo(node, context));
            context.AddObject(node, encodingBindingElement);

            // Name
            encodingBindingElement.Name = node.Name;

            // Binding
            encodingBindingElement.Binding = (Binding)NameContext.Current.Scope;

            // Properties (optional)
            if (node.Properties != null)
            {
                // Enter scope
                using (new NameContextScope(encodingBindingElement))
                {
                    foreach (dynamic property in node.Properties)
                    {
                        this.Process_BindingProperty(property);
                    }
                }
            }
        }