/// <summary>
        /// Method to get the <see cref="SessionFactoryElement" /> based on the <see cref="DataBaseConnectivity" />.
        /// </summary>
        /// <param name="dataBaseConnectivity">DataBaseConnectivity for which <see cref="SessionFactoryElement" /> to be retrieved.</param>
        /// <returns>Returns <see cref="SessionFactoryElement" />.</returns>
        public SessionFactoryElement GetSessionFactoryElementFromName(DataBaseConnectivity dataBaseConnectivity)
        {
            Check.Require(!string.IsNullOrEmpty(dataBaseConnectivity.ToString()),
                "DataBaseConnectivity should not be null nor empty");

            OpenSessionInViewSection openSessionInViewSection = GetOpenSessionInViewSection();

            SessionFactoryElement sessionFactoryElement = null;

            try
            {
                // Loop through all the SessionFactoryElements and find the one which matched with the DataBaseConnectivity.
                foreach (SessionFactoryElement sessionFactorySettings in openSessionInViewSection.SessionFactories)
                {
                    if (sessionFactorySettings.Name == dataBaseConnectivity.ToString())
                    {
                        sessionFactoryElement = sessionFactorySettings;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error at GetSessionFactoryFromName: ", ex);
                throw;
            }

            Check.Require(sessionFactoryElement != null,
                "SessionFactoryElement should not be null nor empty");

            return sessionFactoryElement;
        }
        /// <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;
            }
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitOfWorkImpl"/> class.
        /// </summary>
        /// <param name="dataBaseConnectivity"><see cref="DataBaseConnectivity" /> to be used for getting the <see cref="SessionFactoryElement" /></param>
        public UnitOfWorkImpl(DataBaseConnectivity dataBaseConnectivity)
        {
            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);
            NHibernateSessionManager.Instance.BeginTransactionOn(this.sessionFactoryElement.FactoryConfigPath);
        }
        /// <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;
        }
示例#5
0
        /// <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;

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

            Check.Require(sessionFactoryElement != null,
                "SessionFactoryElement should not be null.");

            return sessionFactoryElement;
        }