/// <summary>
        /// Initializes a new instance of the <see cref="ApplicationSessionManager"/> class.
        /// </summary>
        /// <param name="dataBaseConnectivity"><see cref="DataBaseConnectivity" /> to be used for getting the <see cref="SessionFactoryElement" /></param>
        public ApplicationSessionManager(DataBaseConnectivity dataBaseConnectivity)
        {
            try
            {
                Check.Require(!string.IsNullOrEmpty(dataBaseConnectivity.ToString()),
                    "DataBaseConnectivity should not be null nor empty");

                this.sessionFactoryElement = this.GetSessionFactoryElementFromName(dataBaseConnectivity);

                Check.Require(!string.IsNullOrEmpty(this.sessionFactoryElement.Name) && !string.IsNullOrEmpty(this.sessionFactoryElement.FactoryConfigPath),
                    "SessionFactoryElement's Name and FactoryConfigPath should not be null nor empty");

                this.Session = NHibernateSessionManager.Instance.GetSessionFrom(this.sessionFactoryElement.FactoryConfigPath);
            }
            catch (HibernateException hex)
            {
                Logger.Error("Error at ApplicationSessionManager - HibernateException", hex);
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error("Error at ApplicationSessionManager - Exception", ex);
                throw;
            }
        }
Exemplo n.º 2
0
 public void Remove(SessionFactoryElement sessionFactory)
 {
     if (BaseIndexOf(sessionFactory) >= 0)
     {
         BaseRemove(sessionFactory.Name);
     }
 }
        /// <summary>
        /// Method to get the <see cref="SessionFactoryElement" /> object based on the <see cref="DataBaseConnectivity" />.
        /// </summary>
        /// <param name="dataBaseConnectivity"><see cref="DataBaseConnectivity" /> to be used for getting the <see cref="SessionFactoryElement" /></param>
        /// <returns>Returns <see cref="SessionFactoryElement" /></returns>
        private SessionFactoryElement GetSessionFactoryElementFromName(DataBaseConnectivity dataBaseConnectivity)
        {
            Check.Require(!string.IsNullOrEmpty(dataBaseConnectivity.ToString()),
                "DataBaseConnectivity should not be null nor empty");

            SessionFactoryElement sessionFactoryElement = null;

            try
            {

                using (SessionFactoryManager sfm = new SessionFactoryManager())
                {
                    sessionFactoryElement = sfm.GetSessionFactoryElementFromName(dataBaseConnectivity);
                }

                Check.Require(sessionFactoryElement != null,
                    "SessionFactoryElement should not be null.");
            }
            catch (Exception ex)
            {
                Logger.Error("Error at GetSessionFactoryElementFromName method", ex);
                throw;
            }

            return sessionFactoryElement;
        }
        private ISessionFactory GetSessionFactoryFor(string sessionFactoryName)
        {
            if (string.IsNullOrEmpty(sessionFactoryName))
            {
                throw new ArgumentNullException("sessionFactoryName", "sessionFactoryName may not be null nor empty");
            }

            ISessionFactory sessionFactory = (ISessionFactory)sessionFactories[sessionFactoryName];

            if (sessionFactory != null)
            {
                return(sessionFactory);
            }

            //Uso esclusivo delle risorse - Concorrenza
            lock (sessionFactories)
            {
                sessionFactory = (ISessionFactory)sessionFactories[sessionFactoryName];
                if (sessionFactory == null)
                {
                    OpenSessionInViewSection openSessionInViewSection = (OpenSessionInViewSection)ConfigurationManager.GetSection("nhibernateSettings");

                    if (openSessionInViewSection == null)
                    {
                        throw new Exception("Impossibile trovare la sezione nhibernateSettings nel ConfigurationManager.");
                    }

                    SessionFactoryElement factoryElement = openSessionInViewSection.SessionFactories[sessionFactoryName];

                    if (factoryElement == null)
                    {
                        throw new Exception("The SessionFactory with name " + sessionFactoryName +
                                            " Element was not found with ConfigurationManager.");
                    }

                    INHibernateConfiguration configurator;

                    try
                    {
                        configurator = (INHibernateConfiguration)Activator.CreateInstance(Type.GetType(factoryElement.Configurator));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Errore in creazione Configurator. Verificare riferimento a VecompSoftware.DocSuiteWeb.Data.dll", ex);
                    }


                    Configuration configuration = configurator.GetConfigurationFor(factoryElement);
#if DEBUG
                    configuration.SetProperty("generate_statistics", "true");
#endif
                    sessionFactory = configuration.BuildSessionFactory();

                    if (sessionFactory == null)
                    {
                        throw new InvalidOperationException("configuration.BuildSessionFactory() returned null.");
                    }

                    sessionFactories.Add(sessionFactoryName, sessionFactory);
                    sessionConfigurations.Add(sessionFactoryName, configuration);
                }
            }
            return(sessionFactory);
        }
Exemplo n.º 5
0
 public int IndexOf(SessionFactoryElement sessionFactory)
 {
     return BaseIndexOf(sessionFactory);
 }
Exemplo n.º 6
0
 public void Add(SessionFactoryElement sessionFactory)
 {
     BaseAdd(sessionFactory);
 }