コード例 #1
0
ファイル: Generator.cs プロジェクト: Mart-Bogdan/hwsproxygen
        public static string MakeParameter(Parameter p)
        {
            string result        = "";
            string parameterName = LowerFirstChar(p.Name);

            if (p.HWSType is HWSPrimitiveType)
            {
                HWSPrimitiveType primType = p.HWSType as HWSPrimitiveType;
                if (primType.Type.Equals(typeof(char)))
                {
                    result = "(primitiveToStr (ord " + parameterName + "))";
                }
                else if (primType.Type.Equals(typeof(bool)))
                {
                    result = "(lowerFirstChar (primitiveToStr " + parameterName + "))";
                }
                else
                {
                    result = "(primitiveToStr " + parameterName + ")";
                }
            }
            else if (p.HWSType is HWSEnumType)
            {
                result = "(show " + parameterName + ")";
            }
            else if (p.HWSType is HWSDataTypeType)
            {
                result = "(toXml " + parameterName + ")";
            }
            else if (p.HWSType is HWSListType)
            {
                HWSListType listType = p.HWSType as HWSListType;
                if (listType.Parameter.HWSType is HWSPrimitiveType)
                {
                    result = "(buildPrimitiveXmlList " + parameterName + " \"" + listType.Parameter.Name + "\")";
                }
                else
                {
                    result = "(buildComplexXmlList " + parameterName + " \"" + listType.Parameter.Name + "\")";
                }
            }
            else
            {
                throw new TypeNotSupportedException(p.HWSType.ToString());
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Converte uma string em formato wsdl em um tipo basico da linguagem
        /// ex: "s:string" -> string
        /// </summary>
        /// <param name="stringType">tipo em formato string</param>
        /// <returns>tipo convertido</returns>
        private HWSType ConvertType(string stringType)
        {
            HWSType result = null;

            stringType = stringType.Substring(stringType.IndexOf(":") + 1);

            switch (stringType)
            {
            case "int":
                result = new HWSPrimitiveType(typeof(int));
                break;

            case "double":
                result = new HWSPrimitiveType(typeof(double));
                break;

            case "long":
                result = new HWSPrimitiveType(typeof(long));
                break;

            case "string":
                result = new HWSPrimitiveType(typeof(string));
                break;

            case "char":
                result = new HWSPrimitiveType(typeof(char));
                break;

            case "float":
                result = new HWSPrimitiveType(typeof(float));
                break;

            case "void":
                result = new HWSPrimitiveType(typeof(void));
                break;

            case "boolean":
                result = new HWSPrimitiveType(typeof(bool));
                break;

            case "base64Binary":                     //TODO: interpret this value correctly
                result = new HWSPrimitiveType(typeof(string));
                break;

            default:
                bool found = false;
                foreach (Enumeration en in this.enumerations)
                {
                    if (stringType.Equals(en.Name))
                    {
                        result = new HWSEnumType(stringType);
                        found  = true;
                        break;
                    }
                }

                foreach (DataType data in this.dataTypes)
                {
                    if (stringType.Equals(data.Name))
                    {
                        bool hasParameters = data.Parameters.Count > 0;
                        result = new HWSDataTypeType(stringType, hasParameters);
                        found  = true;
                        break;
                    }
                }

                foreach (HWSListType listType in this.listTypes)
                {
                    if (stringType.Equals(listType.Name))
                    {
                        result = listType;
                        found  = true;
                        break;
                    }
                }

                if (!found)
                {
                    throw new TypeNotSupportedException(stringType);
                }
                break;
            }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Monta as funcoes do servico
        /// </summary>
        /// <param name="servDesc">descricao do servico</param>
        private void MountFunctions(ServiceDescription servDesc)
        {
            string  funName    = "";
            HWSType returnType = null;

            foreach (PortType port in servDesc.PortTypes)
            {
                foreach (Operation op in port.Operations)
                {
                    ArrayList parameters = new ArrayList();
                    funName = op.Name;

                    //mensagem que descreve as entradas da operacao
                    Message msgIn = servDesc.Messages[op.Messages.Input.Message.Name];

                    foreach (MessagePart part in msgIn.Parts)
                    {
                        //se for um element (padrao VS), o tipo da funcao
                        //esta' definido junto aos complex types
                        if (part.Element != null && !part.Element.IsEmpty)
                        {
                            //busca entre as definicoes dos types
                            foreach (XmlSchema s in servDesc.Types.Schemas)
                            {
                                for (int i = 0; i < s.Items.Count; ++i)
                                {
                                    if (s.Items[i].GetType().Equals(typeof(XmlSchemaElement)))
                                    {
                                        XmlSchemaElement e = (XmlSchemaElement)s.Items[i];

                                        if (e.Name.Equals(part.Element.Name))
                                        {
                                            XmlSchemaSequence seq = (XmlSchemaSequence)((XmlSchemaComplexType)e.SchemaType).Particle;

                                            if (seq != null)
                                            {
                                                foreach (XmlSchemaElement param in seq.Items)
                                                {
                                                    Parameter p = new Parameter();
                                                    p.Name    = param.Name;
                                                    p.HWSType = ConvertType(param.SchemaTypeName.Name);
                                                    parameters.Add(p);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //para os tipos definidos diretamente na mensagem
                        else
                        {
                            Parameter p = new Parameter();
                            p.Name    = part.Name;
                            p.HWSType = ConvertType(part.Type.Name);
                            parameters.Add(p);
                        }
                    }

                    //mensagem que descreve o retorno da operacao
                    Message msgOut = servDesc.Messages[op.Messages.Output.Message.Name];

                    foreach (MessagePart part in msgOut.Parts)
                    {
                        //se for um element (padrao VS), o tipo da funcao
                        //esta' definido junto aos complex types
                        if (part.Element != null && !part.Element.IsEmpty)
                        {
                            //busca entre as definicoes dos types
                            foreach (XmlSchema s in servDesc.Types.Schemas)
                            {
                                for (int i = 0; i < s.Items.Count; ++i)
                                {
                                    if (s.Items[i].GetType().Equals(typeof(XmlSchemaElement)))
                                    {
                                        XmlSchemaElement e = (XmlSchemaElement)s.Items[i];

                                        if (e.Name.Equals(part.Element.Name))
                                        {
                                            XmlSchemaComplexType seq         = (XmlSchemaComplexType)e.SchemaType;
                                            XmlSchemaSequence    seqParticle = null;
                                            if (seq != null)
                                            {
                                                seqParticle = (XmlSchemaSequence)seq.Particle;
                                            }


                                            if (seqParticle != null)
                                            {
                                                //sempre havera' apenas 1 elemento, afinal, e' o tipo de retorno
                                                foreach (XmlSchemaElement param in seqParticle.Items)
                                                {
                                                    returnType = ConvertType(param.SchemaTypeName.Name);
                                                }
                                            }
                                            else
                                            {
                                                returnType = new HWSPrimitiveType(typeof(void));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //para os tipos definidos diretamente na mensagem
                        else
                        {
                            returnType = ConvertType(part.Type.Name);
                        }
                    }

                    Function function = new Function(funName, returnType, null, parameters);

                    if (SetSoapActionInFunction(servDesc, function))
                    {
                        this.functions.Add(function);
                    }
                }
            }
        }