예제 #1
0
        /// <summary>
        /// Gets connection string from
        /// </summary>
        /// <returns></returns>
        public static string GetNHibernateConnectionString(string contextName)
        {
            string      nhibernateConfigFile = NHibernateSessionContext.GetConfigFilePath(contextName);
            XmlDocument doc = new XmlDocument();

            doc.Load(nhibernateConfigFile);
            var properties = doc.GetElementsByTagName("session-factory")[0].ChildNodes;

            for (int i = 0; i < properties.Count; i++)
            {
                if (properties[i].Attributes["name"].Value == "connection.connection_string")
                {
                    return(properties[i].InnerText.Trim());
                }
            }

            return(null);
        }
        /// <summary>
        /// Gets the name of the context by.
        /// </summary>
        /// <param name="contextName">Name of the context.</param>
        /// <returns></returns>
        public NHibernateSessionContext GetContextByName(string contextName)
        {
            Check.Require(string.IsNullOrEmpty(contextName) == false, "contextName cannot be null or empty");

            NHibernateSessionContext context = null;

            lock (lockObject)
            {
                if (_ContextList.ContainsKey(contextName))
                {
                    context = (NHibernateSessionContext)_ContextList[contextName];
                }
                else
                {
                    context = new NHibernateSessionContext(contextName);
                    _ContextList.Add(contextName, context);
                }
            }

            Check.Ensure(context != null);

            return(context);
        }