Permalink
Browse files

Fixed Logging configuration (reads from Web.Config)

Added NHibernate assemblies
Added persistence facility and installer
Added Class diagram for entity model
Added POCO classes for the domain model
Slightly modified the Index view to show number of current events
  • Loading branch information...
HEskandari committed Dec 26, 2010
1 parent fb7e35a commit 196e60dca2d695f3ce8df8a3b3c6f31cbbb8aaac
Showing with 55,211 additions and 15 deletions.
  1. +2 −0 ToBeSeen.sln
  2. BIN ToBeSeen.suo
  3. BIN lib/NHiberante/Antlr3.Runtime.dll
  4. BIN lib/NHiberante/Castle.Core.dll
  5. +4,927 −0 lib/NHiberante/Castle.Core.xml
  6. +5,621 −0 lib/NHiberante/FluentNHibernate.XML
  7. BIN lib/NHiberante/FluentNHibernate.dll
  8. BIN lib/NHiberante/FluentNHibernate.pdb
  9. BIN lib/NHiberante/Iesi.Collections.dll
  10. BIN lib/NHiberante/Iesi.Collections.pdb
  11. +1,903 −0 lib/NHiberante/Iesi.Collections.xml
  12. BIN lib/NHiberante/NHibernate.ByteCode.Castle.dll
  13. BIN lib/NHiberante/NHibernate.ByteCode.Castle.pdb
  14. +40 −0 lib/NHiberante/NHibernate.ByteCode.Castle.xml
  15. BIN lib/NHiberante/NHibernate.dll
  16. BIN lib/NHiberante/NHibernate.pdb
  17. +42,365 −0 lib/NHiberante/NHibernate.xml
  18. BIN lib/NHiberante/Remotion.Data.Linq.dll
  19. +3 −0 src/ToBeSeen/Controllers/AccountController.cs
  20. +11 −6 src/ToBeSeen/Controllers/HomeController.cs
  21. +13 −0 src/ToBeSeen/Domain/EntityBase.cs
  22. +37 −0 src/ToBeSeen/Domain/Events.cs
  23. +28 −0 src/ToBeSeen/Domain/Persistence.cd
  24. +33 −0 src/ToBeSeen/Domain/UserInfo.cs
  25. +1 −2 src/ToBeSeen/Installers/LoggerInstaller.cs
  26. +17 −0 src/ToBeSeen/Installers/PersistenceInstaller.cs
  27. +9 −0 src/ToBeSeen/Plumbing/DoNotMapAttribute.cs
  28. +16 −0 src/ToBeSeen/Plumbing/ISessionFactoryProvider.cs
  29. +72 −0 src/ToBeSeen/Plumbing/PersistenceFacility.cs
  30. +63 −0 src/ToBeSeen/Plumbing/SessionFactoryProvider.cs
  31. +15 −0 src/ToBeSeen/ToBeSeen.csproj
  32. +1 −3 src/ToBeSeen/Views/Home/Index.cshtml
  33. +1 −1 src/ToBeSeen/Views/Shared/_Layout.cshtml
  34. +33 −3 src/ToBeSeen/Web.config
View
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToBeSeen", "src\ToBeSeen\ToBeSeen.csproj", "{E2DBF26A-3ACC-483E-88AC-8468FA4BDA0A}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{460941E5-954B-4A04-8F1E-A7C117AA5F5E}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.
View

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -12,6 +12,7 @@
namespace ToBeSeen.Controllers
{
+ [HandleError]
public class AccountController : Controller
{
@@ -42,6 +43,8 @@ public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
+ Logger.InfoFormat("Trying to log-on User {0} into the system.", model.UserName);
+
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
@@ -1,16 +1,21 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.Mvc;
+using System.Web.Mvc;
+using NHibernate;
namespace ToBeSeen.Controllers
{
public class HomeController : Controller
{
+ private readonly ISession session;
+
+ public HomeController(ISession session)
+ {
+ this.session = session;
+ }
+
public ActionResult Index()
{
- ViewModel.Message = "Welcome to ASP.NET MVC!";
+ ViewModel.Message = "Welcome to ToBeSeen WebSite!";
+ ViewModel.EventCount = session.QueryOver<Event>().RowCount();
return View();
}
@@ -0,0 +1,13 @@
+namespace ToBeSeen
+{
+ /// <summary>
+ /// Layer supertype for all entity classes
+ /// </summary>
+ public abstract class EntityBase
+ {
+ public virtual int Id
+ {
+ get; private set;
+ }
+ }
+}
@@ -0,0 +1,37 @@
+using System;
+
+namespace ToBeSeen
+{
+ public class Event : EntityBase
+ {
+ public virtual string Title
+ {
+ get;
+ set;
+ }
+
+ public virtual string Where
+ {
+ get;
+ set;
+ }
+
+ public virtual DateTime When
+ {
+ get;
+ set;
+ }
+
+ public virtual string Description
+ {
+ get;
+ set;
+ }
+
+ public virtual UserInfo GeneratedBy
+ {
+ get;
+ set;
+ }
+ }
+}
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ClassDiagram MajorVersion="1" MinorVersion="1">
+ <Class Name="ToBeSeen.Event">
+ <Position X="2" Y="2.5" Width="1.5" />
+ <TypeIdentifier>
+ <HashCode>AAAAAAAAACAgAEAAAAAAAAACAAEAAAAAAAAAAAAAAAA=</HashCode>
+ <FileName>Domain\Events.cs</FileName>
+ </TypeIdentifier>
+ <ShowAsAssociation>
+ <Property Name="GeneratedBy" />
+ </ShowAsAssociation>
+ </Class>
+ <Class Name="ToBeSeen.EntityBase">
+ <Position X="3.75" Y="0.5" Width="1.5" />
+ <TypeIdentifier>
+ <HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
+ <FileName>Domain\EntityBase.cs</FileName>
+ </TypeIdentifier>
+ </Class>
+ <Class Name="ToBeSeen.UserInfo">
+ <Position X="5.5" Y="2.5" Width="1.5" />
+ <TypeIdentifier>
+ <HashCode>AAAAAAAAACAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
+ <FileName>Domain\UserInfo.cs</FileName>
+ </TypeIdentifier>
+ </Class>
+ <Font Name="Segoe UI" Size="9" />
+</ClassDiagram>
@@ -0,0 +1,33 @@
+using System;
+using System.Web;
+using System.Web.Services;
+using System.Web.Services.Protocols;
+using System.ComponentModel;
+
+namespace ToBeSeen
+{
+ public class UserInfo : EntityBase
+ {
+ public virtual int Username
+ {
+ get
+ {
+ throw new System.NotImplementedException();
+ }
+ set
+ {
+ }
+ }
+
+ public virtual int Email
+ {
+ get
+ {
+ throw new System.NotImplementedException();
+ }
+ set
+ {
+ }
+ }
+ }
+}
@@ -1,4 +1,3 @@
-using System;
using Castle.Facilities.Logging;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
@@ -10,7 +9,7 @@ public class LoggerInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
- container.AddFacility("logging", new LoggingFacility(LoggerImplementation.Log4net));
+ container.AddFacility<LoggingFacility>(f => f.LogUsing(LoggerImplementation.Log4net).WithAppConfig());
}
}
}
@@ -0,0 +1,17 @@
+using Castle.Facilities.Startable;
+using Castle.MicroKernel.Registration;
+using Castle.MicroKernel.SubSystems.Configuration;
+using Castle.Windsor;
+using ToBeSeen.Plumbing;
+
+namespace ToBeSeen.Installers
+{
+ public class PersistenceInstaller : IWindsorInstaller
+ {
+ public void Install(IWindsorContainer container, IConfigurationStore store)
+ {
+ container.AddFacility<StartableFacility>(f => f.DeferredStart());
+ container.AddFacility<PersistenceFacility>();
+ }
+ }
+}
@@ -0,0 +1,9 @@
+using System;
+
+namespace ToBeSeen.Plumbing
+{
+ [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
+ public class DoNotMapAttribute : Attribute
+ {
+ }
+}
@@ -0,0 +1,16 @@
+using Castle.Core;
+using NHibernate;
+
+namespace ToBeSeen.Plumbing
+{
+ /// <summary>
+ /// Provides access to session factory
+ /// </summary>
+ public interface ISessionFactoryProvider : IStartable
+ {
+ /// <summary>
+ /// Returns an instance of SessionFactory
+ /// </summary>
+ ISessionFactory SessionFactory { get; }
+ }
+}
@@ -0,0 +1,72 @@
+using System;
+using Castle.Core.Internal;
+using Castle.MicroKernel.Facilities;
+using Castle.MicroKernel.Registration;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Cfg;
+using FluentNHibernate.Cfg.Db;
+using NHibernate;
+using NHibernate.ByteCode.Castle;
+using NHibernate.Cfg;
+using NHibernate.Tool.hbm2ddl;
+
+namespace ToBeSeen.Plumbing
+{
+ public class PersistenceFacility : AbstractFacility
+ {
+ protected override void Init()
+ {
+ var config = Fluently.Configure()
+ .Database(SetupDatabase)
+ .Mappings(m => m.AutoMappings.Add(CreateMappingModel()))
+ .ExposeConfiguration(ConfigurePersistence)
+ .BuildConfiguration();
+
+ Kernel.Register(Component.For<Configuration>()
+ .Instance(config));
+
+ Kernel.Register(Component.For<ISessionFactoryProvider>()
+ .ImplementedBy<SessionFactoryProvider>());
+
+ Kernel.Register(Component.For<ISessionFactory>()
+ .UsingFactoryMethod(() => Kernel.Resolve<ISessionFactoryProvider>().SessionFactory));
+
+ Kernel.Register(Component.For<ISession>()
+ .UsingFactoryMethod(() => Kernel.Resolve<ISessionFactoryProvider>().SessionFactory.OpenSession()));
+ }
+
+ protected virtual AutoPersistenceModel CreateMappingModel()
+ {
+ var m = AutoMap.Assembly(typeof(EntityBase).Assembly)
+ .Where(IsDomainEntity)
+ .OverrideAll(ShouldIgnoreProperty)
+ .IgnoreBase<EntityBase>();
+
+ return m;
+ }
+
+ protected virtual IPersistenceConfigurer SetupDatabase()
+ {
+ return MsSqlConfiguration.MsSql2008
+ .UseOuterJoin()
+ .ProxyFactoryFactory(typeof(ProxyFactoryFactory))
+ .ConnectionString(x => x.FromConnectionStringWithKey("ApplicationServices"))
+ .ShowSql();
+ }
+
+ protected virtual void ConfigurePersistence(Configuration config)
+ {
+ SchemaMetadataUpdater.QuoteTableAndColumns(config);
+ }
+
+ protected virtual void ShouldIgnoreProperty(IPropertyIgnorer property)
+ {
+ property.IgnoreProperties(p => p.MemberInfo.HasAttribute<DoNotMapAttribute>());
+ }
+
+ public virtual bool IsDomainEntity(Type t)
+ {
+ return typeof(EntityBase).IsAssignableFrom(t);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 196e60d

Please sign in to comment.