Created
February 5, 2013 23:12
-
-
Save diegocaxito/4718599 to your computer and use it in GitHub Desktop.
Exemplo de Console Application em .Net para gerar dados a partir do NHibernate e integrar ao pipeline de Automação de Build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MeuProjeto.Infra.NHibernateConfig; | |
using MeuProjeto.IoC; | |
using NHibernate.Cfg; | |
using NHibernate.Tool.hbm2ddl; | |
namespace MeuProjeto.GeracaoDados.Configuracao | |
{ | |
public class BancoDados | |
{ | |
public static void GerarBancoDados() | |
{ | |
var sessao = StructureMapBootstrapper.Resolve<ISessionBuilder>(); | |
sessao.GetFluentConfiguration().ExposeConfiguration(BuildSchema).BuildConfiguration(); | |
sessao.CreateSession(); | |
} | |
private static void BuildSchema(Configuration config) | |
{ | |
var createScript = true; | |
var exportFile = true; | |
new SchemaExport(config).Create(createScript, exportFile); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MeuProjeto.GeracaoDados.Configuracao; | |
using MeuProjeto.GeracaoDados.Dados; | |
using MeuProjeto.Infra.NHibernateConfig; | |
using MeuProjeto.IoC; | |
namespace MeuProjeto.GeracaoDados | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
SetupCusomConnectionIoC.IniciarStructureMap<ConexaoDeploy>(); | |
BancoDados.GerarBancoDados(); | |
PopularDados(); | |
Console.WriteLine("Banco de dados Criado com Sucesso!!"); | |
} | |
public static void PopularDados() | |
{ | |
var unit = StructureMapBootstrapper.Resolve<IUnitOfWork>(); | |
unit.Begin(); | |
new GeradorDadosCliente().GerarDados(); | |
new GeradorDadosPedido().GerarDados(); | |
new GeradorMensagensCustomizadas().GerarDados(); | |
try | |
{ | |
unit.Commit(); | |
} | |
catch { | |
unit.RollBack(); | |
throw; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment