Exemplo n.º 1
0
        public static void CreateSpecificModuleBody(ProxyModel model, string outputPath, StreamWriter writer, StringBuilder sbuilder)
        {
            string completePath = outputPath + @"\" + model.Name + ".hs";

            foreach (Enumeration en in model.Enumerations)
            {
                sbuilder.Append(MakeEnumeration(model, en));
                sbuilder.Append("\n");
                sbuilder.Append("\n");
            }

            foreach (DataType dt in model.DataTypes)
            {
                sbuilder.Append(MakeDataTypes(model, dt));
                sbuilder.Append("\n");
                sbuilder.Append("\n");
            }

            foreach (Function function in model.Functions)
            {
                sbuilder.Append(MakeFunction(model, function));
                sbuilder.Append("\n");
            }

            writer.Write(sbuilder.ToString());
            writer.Close();
            Console.WriteLine("File {0} generated", completePath);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: hsproxygen [web service uri] [output dir]");
            }
            else
            {
                string wsdlUri   = args[0];
                string outputDir = args[1];

                Stream        wsdlStream = RetrieveWsdlXml(wsdlUri);
                XmlTextReader reader     = new XmlTextReader(wsdlStream);
                if (ServiceDescription.CanRead(reader))
                {
                    ServiceDescription desc = ServiceDescription.Read(reader);

                    if (wsdlUri.IndexOf("?WSDL") > 0)
                    {
                        desc.RetrievalUrl = wsdlUri.Substring(0, wsdlUri.IndexOf("?WSDL"));
                    }

                    ProxyModel proxyModel = new ProxyModel(desc);
                    Generator.CreateSpecificModule(proxyModel, outputDir);
                }

                wsdlStream.Close();
            }
        }
Exemplo n.º 3
0
        private static String MakeFunctionBody(ProxyModel model, Function function)
        {
            StringBuilder sbuilder = new StringBuilder();

            // adiciona o nome da função
            sbuilder.Append(LowerFirstChar(function.Name));

            // adiciona os parâmetros
            for (int i = 0; i < function.ParametersCount(); i++)
            {
                Parameter p = function[i];
                sbuilder.Append(" ");
                sbuilder.Append(LowerFirstChar(p.Name));
            }

            // adiciona a palavra "do"
            sbuilder.Append(" = do ");
            sbuilder.Append(IdentLevel(1));
            sbuilder.Append("strResult <- invokeWS uriStr name action namespace parameters response");

            // adiciona a parte referente ao retorno na função
            sbuilder.Append(MakeFunctionResult(function));


            // monta a cláusula where
            sbuilder.Append(MakeWhereClause(model, function));

            // monta a resposta
            sbuilder.Append(IdentLevel(2));
            sbuilder.Append("response = ");
            sbuilder.Append("\"" + function.Name + "Result" + "\"");

            return(sbuilder.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Escreve o cabeçalho do módulo. Exportando as funções, as enumerações o os
        /// DataTypes
        /// </summary>
        /// <param name="model"> </param>
        private static string MakeExportList(ProxyModel model)
        {
            StringBuilder sbuilder = new StringBuilder();

            // se algum dos conjuntos  não for vazio, coloca o "("  inicial
            // da lista de exportação e concatena os objetos exportados
            if (model.Enumerations.Count > 0 || model.Functions.Count > 0 ||
                model.DataTypes.Count > 0)
            {
                sbuilder.Append(" (");

                // adiciona as enumeracoes.
                if (model.Enumerations.Count > 0)
                {
                    for (int i = 0; i < model.Enumerations.Count; i++)
                    {
                        Enumeration enumeration = (Enumeration)model.Enumerations[i];
                        sbuilder.Append(IdentLevel(1));
                        sbuilder.Append(model.Name + ".");
                        sbuilder.Append(enumeration.Name);
                        sbuilder.Append("(..),");
                    }
                }
                // adiciona os dataTypes
                if (model.DataTypes.Count > 0)
                {
                    for (int j = 0; j < model.DataTypes.Count; j++)
                    {
                        DataType dataType = (DataType)model.DataTypes[j];
                        sbuilder.Append(IdentLevel(1));
                        sbuilder.Append(model.Name + ".");
                        sbuilder.Append(dataType.Name);
                        sbuilder.Append("(..),");
                    }
                }


                // adiciona as funções
                if (model.Functions.Count > 0)
                {
                    for (int i = 0; i < model.Functions.Count; i++)
                    {
                        Function function = (Function)model.Functions[i];
                        sbuilder.Append(IdentLevel(1));
                        sbuilder.Append(model.Name + ".");
                        sbuilder.Append(LowerFirstChar(function.Name));
                        sbuilder.Append(",");
                    }
                }

                // remove a última vírgula. que se encontra na ultima posicao da string
                sbuilder.Remove(sbuilder.Length - 1, 1);
                sbuilder.Append("\n");
                sbuilder.Append(")");
            }

            return(sbuilder.ToString());
        }
Exemplo n.º 5
0
        private static String MakeFunction(ProxyModel model, Function function)
        {
            StringBuilder sbuilder = new StringBuilder();

            sbuilder.Append(MakeFunctionHeader(function));
            sbuilder.Append("\n");
            sbuilder.Append(MakeFunctionBody(model, function));
            sbuilder.Append("\n");

            return(sbuilder.ToString());
        }
Exemplo n.º 6
0
        private static String MakeEnumeration(ProxyModel model, Enumeration en)
        {
            string result = "";

            result += "data " + en.Name;
            result += IdentLevel(1);
            result += "= " + en.EnumMembers[0];
            for (int i = 1; i < en.EnumMembers.Count; i++)
            {
                result += IdentLevel(1);
                result += "| " + en.EnumMembers[i];
            }
            result += IdentLevel(1);
            result += "deriving(Read, Show)";

            return(result);
        }
Exemplo n.º 7
0
        private static String MakeDataTypes(ProxyModel model, DataType dt)
        {
            string result = "";

            result += "data " + dt.Name + " = " + dt.Name;
            if (dt.Parameters.Count > 0)
            {
                result += " {";
                result += MakeDataTypeParameter((Parameter)dt.Parameters[0]);
                for (int i = 1; i < dt.Parameters.Count; i++)
                {
                    result += ",";
                    result += MakeDataTypeParameter((Parameter)dt.Parameters[i]);
                }
                result += "\n";
                result += "}";
            }
            result += " deriving (Show)";
            result += "\n\n";
            result += MakeDataTypeXmlSerializableInstance(dt);
            return(result);
        }
Exemplo n.º 8
0
        private static String MakeWhereClause(ProxyModel model, Function function)
        {
            StringBuilder sbuilder = new StringBuilder();

            sbuilder.Append(IdentLevel(1));
            sbuilder.Append("where");
            sbuilder.Append(IdentLevel(2));
            sbuilder.Append("uriStr = ");
            sbuilder.Append("\"" + model.Uri + "\"");
            sbuilder.Append(IdentLevel(2));
            sbuilder.Append("name = ");
            sbuilder.Append("\"" + function.Name + "\"");
            sbuilder.Append(IdentLevel(2));
            sbuilder.Append("action = ");
            sbuilder.Append("\"" + function.SoapAction + "\"");
            sbuilder.Append(IdentLevel(2));
            sbuilder.Append("namespace = ");
            sbuilder.Append("\"" + model.NameSpace + "\"");
            sbuilder.Append(MakeParameterClause(function));

            return(sbuilder.ToString());
        }
Exemplo n.º 9
0
        public static void CreateSpecificModule(ProxyModel model, string outputPath)
        {
            moduleName = model.Name;
            string        completePath = outputPath + @"\" + moduleName + ".hs";
            StreamWriter  writer       = new StreamWriter(completePath);
            StringBuilder sbuilder     = new StringBuilder();

            sbuilder.Append("module " + model.Name);
            sbuilder.Append(MakeExportList(model));
            sbuilder.Append(" where");
            sbuilder.Append("\n");
            sbuilder.Append("\n");
            sbuilder.Append("import Char");
            sbuilder.Append("\n");
            sbuilder.Append("import SoapHttpClientProtocol");
            sbuilder.Append("\n");
            sbuilder.Append("\n");
            CreateSpecificModuleBody(model, outputPath, writer, sbuilder);
            GenerateSupportFile(outputPath, "SoapHttpClientProtocol.hs");
            GenerateSupportFile(outputPath, "MD5.lhs");
            GenerateSupportFile(outputPath, "Zord64_HARD.lhs");
            GenerateSupportFile(outputPath, "Base64.hs");
        }