//.################################################
//# Copyright © 2006-2010 Evolving Software Ltd   #
//# Author: Vijay Patel                           #
//################################################'

using TestApplicationDomainModel;

using Evolving.TrueView.Domain.Configuration;
using Evolving.TrueView.Persistence;
using Evolving.TrueView.Persistence.NH;
using TestApplicationDomainModel.Objects;

namespace TestApplication
{

    public class Configuration : AssemblyConfiguration<Category>
    {

        public Configuration()
        {
            // If we want to handle aother assemblies with this Configuration, we can associate them here.
            // The configured PersistenceProvider will handle class from the associated assemblies:
            this.AssociatedAssemblies.Add(typeof(TestApplicationDomainModel.Objects.PocoObject).Assembly);

            this.UseFilePersistence();
            //this.UseNhibernatePersistence();
        }

        private void UseFilePersistence()
        {
            var config = new FilePersistenceConfiguration();
            config.ConfigSettings = @"C:\Temp\myData.dat";

            this.ConfigurePersistence(config);
        }

        private void UseNhibernatePersistence()
        {
            var config = new NHibernatePersistenceConfiguration();
            
            // Use this if Nhibernate can't start:
            var fallbackConfig = new FilePersistenceConfiguration();
            fallbackConfig.ConfigSettings = @"C:\Temp\myData.dat";
            config.FallbackConfiguration = fallbackConfig;

            //-----

            var nhConfig = new NHibernate.Cfg.Configuration();
            nhConfig.AddAssembly(this.GetType().Assembly);
            nhConfig.Properties["dialect"] = "NHibernate.Dialect.MsSql2005Dialect";
            nhConfig.Properties["proxyfactory.factory_class"] = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";
            nhConfig.Properties["connection.driver_class"] = "NHibernate.Driver.SqlClientDriver";
            nhConfig.Properties["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
            nhConfig.Properties["connection.connection_string"] = @"Data Source=localhost\SQLEXPRESS;Database=MySampleDatabase;Integrated Security=true;";
            nhConfig.Properties["hibernate.query.substitutions"] = "true 1, false 0";
            nhConfig.Properties["hibernate.batch_size"] = "100";
            nhConfig.Properties["show_sql"] = "true";
            config.ConfigSettings = nhConfig;

            //-----

            this.ConfigurePersistence(config);
        }

    }

}
