# HG changeset patch # User nelopauselli # Date 1305651745 10800 # Node ID 963b71ea6028ba8794079d80859567c2155889a8 # Parent c40b97bbed01ab9ffb511bdf6339777115ab6c71 Repositorios con NH diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Domain/Evento.cs --- a/Agendas/trunk/src/Agendas.Domain/Evento.cs Tue May 17 01:55:19 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Evento.cs Tue May 17 14:02:25 2011 -0300 @@ -24,18 +24,18 @@ return evento; } - private Evento() + protected Evento() { _enlaces = new List(); _tracks = new List(); } - public string Titulo { get; private set; } - public DateTime? Fecha { get; private set; } - public string Sintesis { get; private set; } + public virtual string Titulo { get; private set; } + public virtual DateTime? Fecha { get; private set; } + public virtual string Sintesis { get; private set; } private Ponente _ponente; - public Ponente Ponente + public virtual Ponente Ponente { get { return _ponente; } private set @@ -48,17 +48,17 @@ } } - public IEnumerable Enlaces + public virtual IEnumerable Enlaces { get { return _enlaces; } } - public IEnumerable Tracks + public virtual IEnumerable Tracks { get { return _tracks; } } - public void Actualizar(Ponente ponente, DateTime? fecha) + public virtual void Actualizar(Ponente ponente, DateTime? fecha) { Ponente = ponente; Fecha = fecha; @@ -66,27 +66,27 @@ AddTracks(new Track(Accion.Modificar)); } - public void CambiarTitulo(string titulo) + public virtual void CambiarTitulo(string titulo) { Titulo = titulo; AddTracks(new Track(Accion.CambiarTitulo)); } - public void Publicar(Ponente ponente, DateTime? fecha) + public virtual void Publicar(Ponente ponente, DateTime? fecha) { Ponente = ponente; Fecha = fecha; AddTracks(new Track(Accion.Publicar)); } - public void Realizado(DateTime fecha, string sintesis, IList enlaces) + public virtual void Realizado(DateTime fecha, string sintesis, IList enlaces) { Fecha = fecha; Sintesis = sintesis; _enlaces = enlaces; } - public void Realizado(string sintesis) + public virtual void Realizado(string sintesis) { Sintesis = sintesis; AddTracks(new Track(Accion.Realizar)); diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Domain/Identificable.cs --- a/Agendas/trunk/src/Agendas.Domain/Identificable.cs Tue May 17 01:55:19 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Identificable.cs Tue May 17 14:02:25 2011 -0300 @@ -4,6 +4,6 @@ { public class Identificable { - public Guid Id { get; private set; } + public virtual Guid Id { get; private set; } } } \ No newline at end of file diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Domain/Ponente.cs --- a/Agendas/trunk/src/Agendas.Domain/Ponente.cs Tue May 17 01:55:19 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Ponente.cs Tue May 17 14:02:25 2011 -0300 @@ -7,6 +7,11 @@ { private readonly IList _eventos; + protected Ponente() + { + //ctor para NHibernate + } + public Ponente(string nombre, string mail, string twitter, string blog) : this(nombre) { @@ -21,26 +26,26 @@ _eventos = new List(); } - public string Nombre { get; private set; } + public virtual string Nombre { get; private set; } - public string Mail { get; private set; } + public virtual string Mail { get; private set; } - public string Twitter { get; private set; } + public virtual string Twitter { get; private set; } - public string Blog { get; private set; } + public virtual string Blog { get; private set; } - public IEnumerable Eventos + public virtual IEnumerable Eventos { get { return _eventos; } } - public void AddEvento(Evento evento) + public virtual void AddEvento(Evento evento) { if (!_eventos.Contains(evento)) _eventos.Add(evento); } - public void RemoveEvento(Evento evento) + public virtual void RemoveEvento(Evento evento) { if (_eventos.Contains(evento)) _eventos.Remove(evento); diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Domain/Track.cs --- a/Agendas/trunk/src/Agendas.Domain/Track.cs Tue May 17 01:55:19 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Track.cs Tue May 17 14:02:25 2011 -0300 @@ -2,14 +2,19 @@ { public class Track { + protected Track() + { + //ctor para NHibernate + } + public Track(Accion accion) { Usuario = IdentityContext.GetUserName(); Accion = accion; } - public Accion Accion { get; private set; } - protected string Usuario { get; private set; } + public virtual Accion Accion { get; private set; } + protected virtual string Usuario { get; private set; } } public enum Accion diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Repositories.NHibernate/Agendas.Repositories.NHibernate.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/Agendas.Repositories.NHibernate.csproj Tue May 17 14:02:25 2011 -0300 @@ -0,0 +1,78 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {0973DF44-3B90-4D2A-B579-C64C93B6C853} + Library + Properties + AltNetHispano.Agendas.Repositories.NHibernate + AltNetHispano.Agendas.Repositories.NHibernate + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\ConfOrm.1.0.1.5\lib\Net35\ConfOrm.dll + + + ..\packages\ConfOrm.1.0.1.5\lib\Net35\ConfOrm.Shop.dll + + + ..\packages\Iesi.Collections.3.1.0.4000\lib\Net35\Iesi.Collections.dll + + + ..\packages\NHibernate.3.1.0.4000\lib\Net35\NHibernate.dll + + + + + + + + + + + + + + + + + + + {A14907DF-02E4-4FA7-BE27-4292AF50AA22} + Agendas.Domain + + + + + + + + \ No newline at end of file diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Repositories.NHibernate/EventoRepository.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/EventoRepository.cs Tue May 17 14:02:25 2011 -0300 @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using AltNetHispano.Agendas.Domain; +using AltNetHispano.Agendas.Domain.Repositories; +using NHibernate; + +namespace AltNetHispano.Agendas.Repositories.NHibernate +{ + public class EventoRepository : RepositoryBase, IEventoRepository + { + public EventoRepository(ISessionFactory sessionFactory) : base(sessionFactory) + { + } + + public void Delete(Evento evento) + { + Session.Delete(evento); + } + + public Evento Get(Guid vanId) + { + return Session.Get(vanId); + } + + public IList GetEventosConFecha() + { + return Session.QueryOver().Where(e => e.Fecha != null).List(); + } + + public IList GetEventosSinFecha() + { + return Session.QueryOver().Where(e => e.Fecha == null).List(); + } + + public Evento GetPropuestaByTitulo(string titulo) + { + return Session.QueryOver().Where(e => e.Titulo==titulo).SingleOrDefault(); + } + + public void Update(Evento evento) + { + //No es necesario implementarlo + } + } +} diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Repositories.NHibernate/NhHelper.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/NhHelper.cs Tue May 17 14:02:25 2011 -0300 @@ -0,0 +1,46 @@ +using AltNetHispano.Agendas.Domain; +using ConfOrm; +using ConfOrm.NH; +using NHibernate; +using NHibernate.Cfg; + +namespace AltNetHispano.Agendas.Repositories.NHibernate +{ + public static class NhHelper + { + private static ISessionFactory _sessionfactory; + private static Configuration _cfg; + + public static Configuration GetConfiguration() + { + if (_cfg == null) + { + var orm = new ObjectRelationalMapper(); + orm.TablePerClass(); + orm.TablePerClass(); + + orm.Cascade(Cascade.None); + orm.Cascade(Cascade.None); + + var mapper = new Mapper(orm); + + var mapping = mapper.CompileMappingFor(typeof(Evento).Assembly.GetTypes()); + + _cfg = new Configuration(); + _cfg.Configure(); + _cfg.AddDeserializedMapping(mapping, null); + } + return _cfg; + } + + public static ISessionFactory GetSessionFactory() + { + if (_sessionfactory == null) + { + var cfg = GetConfiguration(); + _sessionfactory=cfg.BuildSessionFactory(); + } + return _sessionfactory; + } + } +} \ No newline at end of file diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Repositories.NHibernate/PonenteRepository.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/PonenteRepository.cs Tue May 17 14:02:25 2011 -0300 @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using AltNetHispano.Agendas.Domain; +using AltNetHispano.Agendas.Domain.Repositories; +using NHibernate; + +namespace AltNetHispano.Agendas.Repositories.NHibernate +{ + public class PonenteRepository : RepositoryBase, IPonenteRepository + { + public PonenteRepository(ISessionFactory sessionFactory) : base(sessionFactory) + { + } + + public IList GetAll() + { + return Session.QueryOver().List(); + } + + public Ponente GetByNombre(string ponenteNombre) + { + return Session.QueryOver().Where(p => p.Nombre == ponenteNombre).SingleOrDefault(); + } + } +} \ No newline at end of file diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Repositories.NHibernate/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/Properties/AssemblyInfo.cs Tue May 17 14:02:25 2011 -0300 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Agendas.Repositories.NHibernate")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Agendas.Repositories.NHibernate")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("193668d1-ff19-408b-ba46-091f60a2f349")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Repositories.NHibernate/RepositoryBase.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/RepositoryBase.cs Tue May 17 14:02:25 2011 -0300 @@ -0,0 +1,21 @@ +using NHibernate; + +namespace AltNetHispano.Agendas.Repositories.NHibernate +{ + public class RepositoryBase + { + private readonly ISessionFactory _sessionFactory; + + public RepositoryBase(ISessionFactory sessionFactory) + { + _sessionFactory = sessionFactory; + } + + protected ISession Session { get { return _sessionFactory.GetCurrentSession(); } } + + public void Save(T obj) + { + Session.Save(obj); + } + } +} \ No newline at end of file diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Repositories.NHibernate/packages.config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/packages.config Tue May 17 14:02:25 2011 -0300 @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff -r c40b97bbed01 -r 963b71ea6028 Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj --- a/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Tue May 17 01:55:19 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Tue May 17 14:02:25 2011 -0300 @@ -31,9 +31,27 @@ 4 + + ..\packages\Castle.Core.2.5.2\lib\NET35\Castle.Core.dll + + + ..\packages\ConfOrm.1.0.1.5\lib\Net35\ConfOrm.dll + + + ..\packages\ConfOrm.1.0.1.5\lib\Net35\ConfOrm.Shop.dll + + + ..\packages\Iesi.Collections.3.1.0.4000\lib\Net35\Iesi.Collections.dll + ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll + + ..\packages\NHibernate.3.1.0.4000\lib\Net35\NHibernate.dll + + + ..\packages\NHibernate.Castle.3.1.0.4000\lib\Net35\NHibernate.ByteCode.Castle.dll + ..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll @@ -53,6 +71,7 @@ + @@ -74,10 +93,20 @@ {28C5EBFB-EE69-4765-A880-D4DE0BC89F48} Agendas.Repositories.Memory + + {0973DF44-3B90-4D2A-B579-C64C93B6C853} + Agendas.Repositories.NHibernate + + + + + Always + +