/// <summary>
 /// Gera os arquivos ORM (TO/DAL/BLL)
 /// </summary>
 public static void Create(Configuration parammeter, ITemplateText dictionaryTemplates)
 {
     foreach (var objetoOrm in parammeter.ObjetosMapeaveis)
     {
         GeraClassesOrm(objetoOrm, parammeter, dictionaryTemplates);
     }
 }
        public void Create(Configuration parametro, string nomeProvider)
        {
            CreateLinqFiles(parametro, nomeProvider);
            CreateBusinessFiles(parametro.DestinationPath, parametro.NameSpace);
            CreatePocoFiles(parametro.DestinationPath);
            CreateInterfaceFiles(parametro.DestinationPath, parametro.NameSpace);

        }
        private static void GeraClassesOrm(DatabaseObjectInfo objectDatabase, Configuration configuration, ITemplateText dictionaryTemplates)
        {
            var gerador = new FileFactory(dictionaryTemplates) { Log = Log };
            var nomeArquivo = FileFactory.RetornaNomeClasseAjustado(objectDatabase.Name);

            var arquivo = gerador.GeneratePocoFiles(nomeArquivo,objectDatabase, configuration);
            var arquivoBLL = gerador.GenerateBusinessFiles(nomeArquivo, objectDatabase, configuration);
            var arquivoDAL = gerador.GenerateDataAccesFiles(nomeArquivo, objectDatabase, configuration);

            File.WriteAllText(string.Format("{0}\\TO\\{1}TO.cs", configuration.DestinationPath, nomeArquivo), arquivo);
            File.WriteAllText(string.Format("{0}\\BLL\\{1}BLL.cs", configuration.DestinationPath, nomeArquivo), arquivoBLL);
            File.WriteAllText(string.Format("{0}\\DAL\\{1}DAL.cs", configuration.DestinationPath, nomeArquivo), arquivoDAL);
        }
        private static void CriaPropriedades(List<ColumnInfo> colunas, StringBuilder retorno, IEnumerable<ForeignKey> listaFk, Configuration parametros)
        {
            colunas = colunas.OrderByDescending(c => c.IsPrimaryKey).ToList();

            foreach (var coluna in colunas)
            {
                var colunaRequirida = false;

                if (parametros.MapLinq)
                {
                    if (coluna.IsPrimaryKey || coluna.IsNullability == false)
                    {
                        retorno.AppendFormat("[Required, DisplayName(\"{0}\")]{1}", coluna.ColumnName, Environment.NewLine);
                        colunaRequirida = !coluna.IsNullability;
                    }

                    if (coluna.Type.ToLower().Contains("char") || coluna.Type.ToLower() == "string")
                    {
                        switch (colunaRequirida)
                        {
                            case true:
                                retorno.AppendFormat("[StringLength({0})]{1}", coluna.Size, Environment.NewLine);
                                break;
                            default:
                                retorno.AppendFormat("[StringLength({0}), DisplayName(\"{1}\")]{2}", coluna.Size, coluna.ColumnName, Environment.NewLine);
                                break;
                        }
                    }
                    //valida se o campo possui validação personalizada
                    if (!string.IsNullOrEmpty(coluna.RegularExpression))
                    {
                        retorno.AppendLine(string.Format("[RegularExpression(@\"{0}\")]", coluna.RegularExpression));
                    }
                    retorno.Append(RetornaMapColumn(coluna)).Append(Environment.NewLine);
                }

                if (parametros.MapWcf)
                {
                    retorno.AppendFormat("[DataMember]{0}", Environment.NewLine);
                }

                retorno.Append(string.Format("public {0}{1} {2} {{ get; set; }}", coluna.Type, CheckIsNullable(coluna.Type, coluna.IsNullability), StringHelper.RemoveInvalidCharacters(coluna.ColumnName)) + Environment.NewLine + Environment.NewLine);
            }

            CriaAssociacoes(retorno, listaFk);

            retorno.Append("}" + Environment.NewLine);
            retorno.Append("}" + Environment.NewLine);
        }
        public static void Create(Configuration parametros, string provider)
        {

            var guidProjInterface = Guid.NewGuid().ToString().ToUpper();
            var guidProjTO = Guid.NewGuid().ToString().ToUpper().ToUpper();
            var guidProjDal = Guid.NewGuid().ToString().ToUpper().ToUpper();
            var guidProjBll = Guid.NewGuid().ToString().ToUpper().ToUpper();
            var guidProjWcf = Guid.NewGuid().ToString().ToUpper().ToUpper();


            var arquivosInterface = (from DatabaseObjectInfo t in parametros.ObjetosMapeaveis select string.Format("<Compile Include=\"IPersistence{0}.cs\" />", FileFactory.RetornaNomeClasseAjustado(t.Name).Replace(" ", ""))).ToList();
            var arquivosTO = (from DatabaseObjectInfo t in parametros.ObjetosMapeaveis select string.Format("<Compile Include=\"{0}TO.cs\" />", FileFactory.RetornaNomeClasseAjustado(t.Name))).ToList();
            var arquivosDal = (from DatabaseObjectInfo t in parametros.ObjetosMapeaveis select string.Format("<Compile Include=\"{0}DAL.cs\" />", FileFactory.RetornaNomeClasseAjustado(t.Name))).ToList();
            var arquivosBll = (from DatabaseObjectInfo t in parametros.ObjetosMapeaveis select string.Format("<Compile Include=\"{0}BLL.cs\" />", FileFactory.RetornaNomeClasseAjustado(t.Name))).ToList();

            var sbLog4Net = new StringBuilder();

            sbLog4Net.AppendLine("<Reference Include=\"log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=AMD64\">");
            sbLog4Net.AppendLine("<SpecificVersion>False</SpecificVersion>");
            sbLog4Net.AppendLine("<HintPath>..\\log4net.dll</HintPath>");
            sbLog4Net.AppendLine("</Reference>");

            var templateAssembly = AssinaProjeto(parametros);

            GeraProjetoInterface(parametros, guidProjInterface, arquivosInterface, templateAssembly);
            GeraProjetoTo(parametros, guidProjTO, guidProjInterface, arquivosTO, templateAssembly);
            GeraProjetoDal(parametros, provider, guidProjDal, guidProjInterface, guidProjTO, arquivosDal, sbLog4Net, templateAssembly);
            GeraProjetoBll(parametros, guidProjBll, guidProjInterface, guidProjTO, guidProjDal, arquivosBll, sbLog4Net, templateAssembly);
            
            if (parametros.MapWcf)
            {
                GeraProjetoWcf(parametros, guidProjWcf);
            }
            else
            {
                guidProjWcf = null;
            }
            
            GeraSoluction(parametros, guidProjTO, guidProjDal, guidProjInterface, guidProjBll, guidProjWcf);

            Directory.Move(string.Format("{0}\\TO", parametros.DestinationPath), string.Format("{0}\\{1}TO", parametros.DestinationPath, parametros.NameSpace.Replace(".", "")));
            Directory.Move(string.Format("{0}\\DAL", parametros.DestinationPath), string.Format("{0}\\{1}DAL", parametros.DestinationPath, parametros.NameSpace.Replace(".", "")));
            Directory.Move(string.Format("{0}\\BLL", parametros.DestinationPath), string.Format("{0}\\{1}BLL", parametros.DestinationPath, parametros.NameSpace.Replace(".", "")));
            Directory.Move(string.Format("{0}\\Interfaces", parametros.DestinationPath), string.Format("{0}\\{1}Interfaces", parametros.DestinationPath, parametros.NameSpace.Replace(".", "")));

        }
예제 #6
0
        public static void WriteFile(Configuration parametros)
        {
            if (!parametros.GerarAppConfig) return;

            var sbAppConfig = new StringBuilder();

            sbAppConfig.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
            sbAppConfig.AppendLine("<configuration>");
            sbAppConfig.AppendLine("<connectionStrings>");
            sbAppConfig.AppendLine(string.Format("<add name=\"STRING_CONNECTION\" connectionString=\"Data Source = {0}; Initial Catalog = {2}; " +
                                                 "Persist Security Info = True; User ID = {1}; Password = {3}; " +
                                                 "\" providerName=\"System.Data.SqlClient\" />", parametros.User.ServerAddress, 
                                                 parametros.User.UserName, parametros.User.DatabaseName, parametros.User.Password));
            sbAppConfig.AppendLine("</connectionStrings>");
            sbAppConfig.AppendLine("</configuration>");

            File.WriteAllText(string.Format("{0}\\app.config", parametros.DestinationPath), sbAppConfig.ToString());
        }
        private static void GeraSoluction(Configuration parametros, string guidProjTO, string guidProjDAL, string guidProjInterface, string guidProjBLL, string guidProjWcf)
        {
            var trocasSolution = new Hashtable
            {
                {"[guid]", Guid.NewGuid().ToString().ToUpper().ToUpper()},
                {"[namespace]", parametros.NameSpace},
                {"[guidTO]", guidProjTO},
                {"[guidDAL]", guidProjDAL},
                {"[guidInterface]", guidProjInterface},
                {"[guidBLL]", guidProjBLL}
            };

            var projSolution = FileFactory.RetornaTextoBase("noituloS");

            if (parametros.MapWcf)
            {
                projSolution = projSolution.Replace("[guidWcf]", string.Format("Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{0}Wcf\", \"{0}Wcf\\{0}Wcf.csproj\", \"{{53034ACE-081D-4CDA-8075-D3B158C7DAF9}}\"{1}EndProject", parametros.NameSpace, Environment.NewLine));
                projSolution = projSolution.Replace("[guidGlobalWcf]", string.Format("{{{0}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU{1}{{{0}}}.Debug|Any CPU.Build.0 = Debug|Any CPU{1}{{{0}}}.Release|Any CPU.ActiveCfg = Release|Any CPU{1}{{{0}}}.Release|Any CPU.Build.0 = Release|Any CPU", guidProjWcf, Environment.NewLine));
            }
            else
            {
                projSolution = projSolution.Replace("[guidWcf]", "");
                projSolution = projSolution.Replace("[guidGlobalWcf]", "");
            }

            switch (parametros.VersaoFramework)
            {
                case "v2.0":
                    projSolution = projSolution.Replace("2010", "2008");
                    projSolution = projSolution.Replace("11.00", "10.00");
                    break;
                case "v4.5":
                    projSolution = projSolution.Replace("2010", "2012");
                    projSolution = projSolution.Replace("11.00", "12.00");
                    break;
            }

            projSolution = trocasSolution.Cast<DictionaryEntry>().Aggregate(projSolution, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));

            File.WriteAllText(string.Format("{0}\\{1}.sln", parametros.DestinationPath, parametros.NameSpace), projSolution);
        }
        private static void CreateLinqFiles(Configuration parametro, string nomeProvider)
        {

            // ReSharper disable ResourceItemNotResolved
            var dbExpressions = _template.GelValue("DbExpressions").Value;
            var dbExpressionVisitor = _template.GelValue("DbExpressionVisitor").Value;
            var expressionVisitor = _template.GelValue("ExpressionVisitor").Value;
            var queryExecutor = _template.GelValue("QueryExecutor").Value;
            var queryLanguage = _template.GelValue("QueryLanguage").Value;
            var queryMapping = _template.GelValue("QueryMapping").Value;
            var queryTypeSystem = _template.GelValue("QueryTypeSystem").Value;
            var sqlFormatter = _template.GelValue("SqlFormatter").Value;

            var isSqlFormatter = _template.GelValue("ISqlFormatter").Value ?? "";
            var provider = _template.GelValue(nomeProvider).Value;


            var funcoesCrud = parametro.TiposObjetosAcaoBanco.Aggregate(_template.GelValue("FuncoesCrud").Value, (current, param) => current.Replace(param.Key, param.Value)).Replace("{namespace}", parametro.NameSpace);

            var sqlLanguage = _template.GelValue("SqlLanguage").Value;

            var crudBase = parametro.TiposObjetosAcaoBanco.Aggregate(_template.GelValue("CrudBase").Value, (current, param) => current.Replace(param.Key, param.Value));
            var singleton = parametro.TiposObjetosAcaoBanco.Aggregate(_template.GelValue("Singleton").Value, (current, param) => current.Replace(param.Key, param.Value));

            var eTipoConsulta = _template.GelValue("ETipoConsulta").Value;
            var cmdMap = parametro.TiposObjetosAcaoBanco.Aggregate(_template.GelValue("CmdMap").Value, (current, param) => current.Replace(param.Key, param.Value));
            var transaction = parametro.TiposObjetosAcaoBanco.Aggregate(_template.GelValue("Transaction").Value, (current, param) => current.Replace(param.Key, param.Value));

            var fastInvoke = _template.GelValue("FastInvoke").Value;
            var mapExtension = _template.GelValue("MapExtension").Value;
            var cachingMannager = _template.GelValue("CachingMannager").Value;
            var eCacheAcao = _template.GelValue("ECacheAcao").Value;
            var cacheChangedEventArgs = _template.GelValue("CacheChangedEventArgs").Value;
            var cacheChangedEventHandler = _template.GelValue("CacheChangedEventHandler").Value;
            var cachingProvider = _template.GelValue("ICachingProvider").Value;


            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\TSqlORM\\DbExpressions.cs", parametro.DestinationPath), dbExpressions);
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\TSqlORM\\DbExpressionVisitor.cs", parametro.DestinationPath), dbExpressionVisitor);
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\TSqlORM\\ExpressionVisitor.cs", parametro.DestinationPath), expressionVisitor);
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\TSqlORM\\QueryExecutor.cs", parametro.DestinationPath), queryExecutor);
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\TSqlORM\\QueryLanguage.cs", parametro.DestinationPath), queryLanguage);
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\TSqlORM\\QueryMapping.cs", parametro.DestinationPath), queryMapping);
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\TSqlORM\\QueryTypeSystem.cs", parametro.DestinationPath), queryTypeSystem);
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\TSqlORM\\SqlFormatter.cs", parametro.DestinationPath), sqlFormatter);

            File.WriteAllText(string.Format("{0}\\DAL\\ORM\\FastInvoke.cs", parametro.DestinationPath), fastInvoke);
            File.WriteAllText(string.Format("{0}\\DAL\\ORM\\MapExtension.cs", parametro.DestinationPath), mapExtension);
            File.WriteAllText(string.Format("{0}\\DAL\\ORM\\Caching\\CachingMannager.cs", parametro.DestinationPath), cachingMannager);
            File.WriteAllText(string.Format("{0}\\DAL\\ORM\\Caching\\Enuns\\ECacheAcao.cs", parametro.DestinationPath), eCacheAcao);
            File.WriteAllText(string.Format("{0}\\DAL\\ORM\\Caching\\Events\\CacheChangedEventArgs.cs", parametro.DestinationPath), cacheChangedEventArgs);
            File.WriteAllText(string.Format("{0}\\DAL\\ORM\\Caching\\Events\\CacheChangedEventHandler.cs", parametro.DestinationPath), cacheChangedEventHandler);
            File.WriteAllText(string.Format("{0}\\DAL\\ORM\\Caching\\Interfaces\\ICachingProvider.cs", parametro.DestinationPath), cachingProvider);



            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\Factories\\ISqlFormatter.cs", parametro.DestinationPath), isSqlFormatter.Replace("TesteDAL", string.Format("{0}DAL", parametro.NameSpace)));
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\Factories\\{1}.cs", parametro.DestinationPath, nomeProvider), provider.Replace("TesteDAL", string.Format("{0}DAL", parametro.NameSpace)));

            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\FuncoesCrud.cs", parametro.DestinationPath), funcoesCrud.Replace("TesteDAL", string.Format("{0}DAL", parametro.NameSpace)));
            File.WriteAllText(string.Format("{0}\\DAL\\DataDrain\\SqlLanguage.cs", parametro.DestinationPath), sqlLanguage.Replace("TesteDAL", string.Format("{0}DAL", parametro.NameSpace)));

            File.WriteAllText(string.Format("{0}\\DAL\\Apoio\\Base\\CrudBase.cs", parametro.DestinationPath), crudBase.Replace("TesteDAL", string.Format("{0}DAL", parametro.NameSpace)).Replace("{namespace}", parametro.NameSpace));
            File.WriteAllText(string.Format("{0}\\DAL\\Apoio\\Conexao\\Singleton.cs", parametro.DestinationPath), singleton.Replace("TesteDAL", string.Format("{0}DAL", parametro.NameSpace)));
            File.WriteAllText(string.Format("{0}\\DAL\\Apoio\\Enumeradores\\ETipoConsulta.cs", parametro.DestinationPath), eTipoConsulta.Replace("TesteDAL", string.Format("{0}DAL", parametro.NameSpace)));
            File.WriteAllText(string.Format("{0}\\DAL\\Apoio\\CommandMap\\CmdMap.cs", parametro.DestinationPath), cmdMap);
            File.WriteAllText(string.Format("{0}\\DAL\\Apoio\\CommandMap\\Transaction.cs", parametro.DestinationPath), transaction);

        }
        public void CreateProjectFiles(Configuration parametros, ITemplateText dictionaryTemplates)
        {
            var returnCreateDirectory = OrmDirectory.Create(parametros.DestinationPath);

            if (returnCreateDirectory.Key)
            {
                new OrmBasicFiles(dictionaryTemplates).Create(parametros, "MySqlFormatter");
                OrmObjectFiles.Create(parametros, dictionaryTemplates);
                OrmProjectFiles.Create(parametros, "MySqlFormatter");
                AppConfig.WriteFile(parametros);
            }
            else
            {
                throw new SecurityException(returnCreateDirectory.Value);
            }
        }
        private static string AssinaProjeto(Configuration parametros)
        {
            var templateAssembly = FileFactory.RetornaTextoBase("ofnIylbmessA");
            var tmpAssInfo = string.Empty;

            if (parametros.AssinarProjeto)
            {
                if (string.IsNullOrEmpty(parametros.CaminhoStrongName))
                {
                    var nomeSnkFile = string.Format("{0}.snk", parametros.NameSpace);

                    GerarKey(string.Format("{0}\\{1}", parametros.DestinationPath, nomeSnkFile));
                    tmpAssInfo = string.Format("[assembly: AssemblyKeyFile({0}\"{1}{2}\")]", "@", "..\\", nomeSnkFile);
                }
                else
                {
                    tmpAssInfo = string.Format("[assembly: AssemblyKeyFile({0}\"{1}\")]", "@", parametros.CaminhoStrongName);
                }
            }

            templateAssembly = templateAssembly.Replace("{sing}", tmpAssInfo);
            return templateAssembly;
        }
        public string GeneratePocoFiles(string tableName, DatabaseObjectInfo objectDatabase, Configuration configuration)
        {
            var retorno = new StringBuilder();

            CriaCabecario(tableName, configuration.NameSpace, retorno, configuration);

            CriaPropriedades(objectDatabase.Columns, retorno, objectDatabase.ForeignKeys, configuration);

            return retorno.ToString();
        }
        private static void GeraProjetoInterface(Configuration parametros, string guidProjInterface, List<string> arquivosInterface, string templateAssembly)
        {
            var trocasInterface = new Hashtable
            {
                {"[guid]", guidProjInterface},
                {"[namespace]", parametros.NameSpace},
                {"[arquivos]", string.Join("\n", arquivosInterface.ToArray())}
            };

            var projInterface = FileFactory.RetornaTextoBase("secafretnIetalpmeT");
            projInterface = trocasInterface.Cast<DictionaryEntry>().Aggregate(projInterface, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
            projInterface = projInterface.Replace("[versao]", parametros.VersaoFramework);

            var assemblyInterface = templateAssembly.Replace("[log]", "");
            assemblyInterface = assemblyInterface.Replace("[namespace]", parametros.NameSpace);
            assemblyInterface = assemblyInterface.Replace("[guid]", guidProjInterface);

            File.WriteAllText(string.Format("{0}\\Interfaces\\{1}Interfaces.csproj", parametros.DestinationPath, parametros.NameSpace), projInterface);
            File.WriteAllText(string.Format("{0}\\Interfaces\\Properties\\AssemblyInfo.cs", parametros.DestinationPath), assemblyInterface);
        }
        private static void GeraProjetoDal(Configuration parametros, string provider, string guidProjDAL, string guidProjInterface, string guidProjTO, List<string> arquivosDAL, StringBuilder sbLog4Net, string templateAssembly)
        {
            var trocasDAL = new Hashtable
            {
                {"[guid]", guidProjDAL},
                {"[namespace]", parametros.NameSpace},
                {"[guidInterface]", guidProjInterface},
                {"[guidTO]", guidProjTO},
                {"[provider]", string.Format("<Compile Include=\"DataDrain\\Factories\\{0}.cs\" />", provider)},
                {"[arquivos]", string.Join("\n", arquivosDAL.ToArray())},
            };

            var projDAL = FileFactory.RetornaTextoBase("SSLADetalpmet").Replace("[log]", "");

            projDAL = trocasDAL.Cast<DictionaryEntry>().Aggregate(projDAL, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
            projDAL = projDAL.Replace("[versao]", parametros.VersaoFramework);


            var assemblyDAL = templateAssembly.Replace("[camada]", "DAL").Replace("[log]", "");
            
            assemblyDAL = assemblyDAL.Replace("[namespace]", parametros.NameSpace);
            assemblyDAL = assemblyDAL.Replace("[guid]", guidProjDAL);


            File.WriteAllText(string.Format("{0}\\DAL\\{1}DAL.csproj", parametros.DestinationPath, parametros.NameSpace), projDAL);
            File.WriteAllText(string.Format("{0}\\DAL\\Properties\\AssemblyInfo.cs", parametros.DestinationPath), assemblyDAL);
        }
        private static void GeraProjetoBll(Configuration parametros, string guidProjBLL, string guidProjInterface, string guidProjTO, string guidProjDAL, List<string> arquivosBLL, StringBuilder sbLog4Net, string templateAssembly)
        {
            var trocasBLL = new Hashtable
            {
                {"[guid]", guidProjBLL},
                {"[namespace]", parametros.NameSpace},
                {"[guidInterface]", guidProjInterface},
                {"[guidTO]", guidProjTO},
                {"[guidDAL]", guidProjDAL},
                {"[arquivos]", string.Join("\n", arquivosBLL.ToArray())},
            };

            var projBLL = FileFactory.RetornaTextoBase("LLBetalpmet").Replace("[log]", "");
            projBLL = trocasBLL.Cast<DictionaryEntry>().Aggregate(projBLL, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
            projBLL = projBLL.Replace("[versao]", parametros.VersaoFramework);

            var assemblyBLL = templateAssembly.Replace("[camada]", "bll").Replace("[log]", "");
            assemblyBLL = assemblyBLL.Replace("[namespace]", parametros.NameSpace);
            assemblyBLL = assemblyBLL.Replace("[guid]", guidProjBLL);


            File.WriteAllText(string.Format("{0}\\BLL\\{1}BLL.csproj", parametros.DestinationPath, parametros.NameSpace), projBLL);
            File.WriteAllText(string.Format("{0}\\BLL\\Properties\\AssemblyInfo.cs", parametros.DestinationPath), assemblyBLL);
        }
        public string GenerateDataAccesFiles(string nomeTabela, DatabaseObjectInfo objectDatabase, Configuration configuration)
        {

            string textoBase;
            switch (objectDatabase.DatabaseObjectType)
            {
                case EDatabaseObjectType.Tabela:
                    textoBase = RetornaTextoBase("padraoDALNativo");
                    break;
                case EDatabaseObjectType.Query:
                case EDatabaseObjectType.Procedure:
                    textoBase = RetornaTextoBase("padraoDALProc");
                    textoBase = textoBase.Replace("{parametros}", string.Join(", ", objectDatabase.StoredProcedureParameters.Select(p => string.Format("{0} {1}", p.ParameterDotNetType, p.ParameterName))));

                    var sbParametros = new StringBuilder();

                    foreach (var parametro in objectDatabase.StoredProcedureParameters)
                    {
                        sbParametros.AppendLine(string.Format("cmd.Parameters.AddWithValue(\"{0}\", {0});", parametro.ParameterName));
                    }

                    textoBase = textoBase.Replace("{carregaParametros}", sbParametros.ToString());
                    textoBase = textoBase.Replace("{query}", objectDatabase.DatabaseObjectType == EDatabaseObjectType.Procedure ? nomeTabela : objectDatabase.QuerySql);
                    textoBase = textoBase.Replace("{proc}", objectDatabase.DatabaseObjectType == EDatabaseObjectType.Procedure ? "cmd.CommandType = CommandType.StoredProcedure;" : "");

                    break;
                case EDatabaseObjectType.View:
                    textoBase = RetornaTextoBase("padraoDALNativo");
                    textoBase = Regex.Replace(textoBase, "#region .: Persistencia :.(.|\n)*?#endregion", string.Empty);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("tipoObjeto");
            }
            textoBase = Log ? textoBase.Replace("[log]", "Log.Error(ex.Message, ex);").Replace("[logHeader]", string.Format("private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof({0}DAL));", nomeTabela)) : textoBase.Replace("[log]", "").Replace("[logHeader]", "");

            return textoBase.Replace("{namespace}", configuration.NameSpace).Replace("{classe}", (nomeTabela));

        }
        public string GenerateBusinessFiles(string nomeTabela, DatabaseObjectInfo objectDatabase, Configuration configuration)
        {

            string textoBase;
            switch (objectDatabase.DatabaseObjectType)
            {
                case EDatabaseObjectType.Tabela:
                    textoBase = RetornaTextoBase("padraoBLLNativo");
                    break;
                case EDatabaseObjectType.Query:
                case EDatabaseObjectType.Procedure:
                    textoBase = RetornaTextoBase("padraoBLLProc");
                    textoBase = textoBase.Replace("{parametros}", string.Join(", ", objectDatabase.StoredProcedureParameters.Select(p => string.Format("{0} {1}", p.ParameterDotNetType, p.ParameterName))));
                    textoBase = textoBase.Replace("{parametros2}", string.Join(", ", objectDatabase.StoredProcedureParameters.Select(p => p.ParameterName)));
                    break;
                case EDatabaseObjectType.View:
                    textoBase = RetornaTextoBase("padraoBLLNativo");
                    textoBase = Regex.Replace(textoBase, "#region .: CRUD :.(.|\n)*?#endregion", string.Empty);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("tipoObjeto");
            }
            textoBase = Log ? textoBase.Replace("[log]", "Log.Error(ex.Message, ex);").Replace("[logHeader]", string.Format("private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof({0}BLL));", nomeTabela)) : textoBase.Replace("[log]", "").Replace("[logHeader]", "");

            return textoBase.Replace("{namespace}", configuration.NameSpace).Replace("{classe}", (nomeTabela));

        }
        private static void GeraProjetoWcf(Configuration parametros, string guidProjWcf)
        {
            var servicos = new List<string>();
            var servicosCode = new List<string>();
            var servicosInterface = new List<string>();

            Directory.CreateDirectory(string.Format("{0}\\{1}Wcf\\", parametros.DestinationPath, parametros.NameSpace));
            Directory.CreateDirectory(string.Format("{0}\\{1}Wcf\\Interface", parametros.DestinationPath, parametros.NameSpace));
            Directory.CreateDirectory(string.Format("{0}\\{1}Wcf\\Properties", parametros.DestinationPath, parametros.NameSpace));

            var assemblyInfoWcf = FileFactory.RetornaTextoBase("AssemblyInfoWcf").Replace("{namespace}", parametros.NameSpace).Replace("{guid}", Guid.NewGuid().ToString("D"));
            File.WriteAllText(string.Format("{0}\\{1}Wcf\\Properties\\AssemblyInfo.cs", parametros.DestinationPath, parametros.NameSpace), assemblyInfoWcf);

            foreach (var classe in parametros.ObjetosMapeaveis)
            {
                File.WriteAllText(string.Format("{0}\\{1}Wcf\\{2}.cs", parametros.DestinationPath, parametros.NameSpace, classe.Name), string.Format("<%@ ServiceHost Language=\"C#\" Debug=\"true\" Service=\"CorpWcf.Aceite\" CodeBehind=\"{0}.svc.cs\" %>", classe.Name));

                var corpoServico = FileFactory.RetornaTextoBase("corpoServico").Replace("{namespace}", parametros.NameSpace).Replace("{classe}", classe.Name);
                File.WriteAllText(string.Format("{0}\\{1}Wcf\\{2}.svc.cs", parametros.DestinationPath, parametros.NameSpace, classe.Name), corpoServico);

                var corpoInterfaceServico = FileFactory.RetornaTextoBase("corpoInterfaceServico").Replace("{namespace}", parametros.NameSpace).Replace("{classe}", classe.Name); ;
                File.WriteAllText(string.Format("{0}\\{1}Wcf\\Interface\\I{2}.cs", parametros.DestinationPath, parametros.NameSpace, classe.Name), corpoInterfaceServico);

                servicos.Add(string.Format("<Content Include=\"{0}.svc\" />", classe.Name));
                servicosCode.Add(string.Format("<Compile Include=\"{0}.svc.cs\">{1}<DependentUpon>{0}.svc</DependentUpon>{1}</Compile>", classe.Name, Environment.NewLine));
                servicosInterface.Add(string.Format("<Compile Include=\"Interface\\I{0}.cs\" />", classe.Name));
            }

            var corpoProjetoWcf = FileFactory.RetornaTextoBase("corpoProjetoWcf").Replace("{namespace}", parametros.NameSpace)
                .Replace("{servicos}", string.Join("\n", servicos))
                .Replace("{servicosCode}", string.Join("\n", servicosCode))
                .Replace("[guid]", guidProjWcf)
                .Replace("{servicosInterface}", string.Join("\n", servicosInterface));

            File.WriteAllText(string.Format("{0}\\{1}Wcf\\{2}Wcf.csproj", parametros.DestinationPath, parametros.NameSpace, parametros.NameSpace), corpoProjetoWcf);

            var corpoWebConfig = FileFactory.RetornaTextoBase("corpoWebConfig");
            File.WriteAllText(string.Format("{0}\\{1}Wcf\\Web.config", parametros.DestinationPath, parametros.NameSpace), corpoWebConfig);

        }
        private static void CriaCabecario(string nomeTabela, string strNamespace, StringBuilder retorno, Configuration parametros)
        {
            retorno.AppendFormat("using System;{0}", Environment.NewLine);

            if (parametros.MapLinq)
            {
                retorno.AppendFormat("using System.ComponentModel;{0}", Environment.NewLine);
                retorno.AppendFormat("using System.ComponentModel.DataAnnotations;{0}", Environment.NewLine);
                retorno.AppendFormat("using System.Data.Linq.Mapping;{0}", Environment.NewLine);
            }
            if (parametros.MapWcf)
            {
                retorno.AppendFormat("using System.Runtime.Serialization;{0}", Environment.NewLine);
            }

            retorno.AppendLine();
            retorno.AppendFormat("{0}{1}", string.Format("namespace {0}TO", strNamespace), Environment.NewLine);
            retorno.AppendFormat("{{{0}", Environment.NewLine);

            if (parametros.MapLinq)
            {
                retorno.AppendFormat("{0}{1}", string.Format("[Table(Name = \"{0}\")]", nomeTabela), Environment.NewLine);
            }
            if (parametros.MapWcf)
            {
                retorno.AppendFormat("{0}{1}", "[DataContract]", Environment.NewLine);
            }

            retorno.AppendFormat("{0}{1}", string.Format("public class {0}TO", RetornaNomeClasseAjustado(nomeTabela)), Environment.NewLine);
            retorno.AppendFormat("{{{0}{0}", Environment.NewLine);
        }