Exemple #1
0
        /// <summary>
        /// Get the current DaoContext instance for the specified logicalName.
        /// If a DaoContext has already been instantiated for the specified logicalName
        /// the connection string is updated with the one specified.
        /// </summary>
        /// <param name="contextName">The name of the DaoContext to retrieve.</param>
        /// <param name="connString">The connection string to assign to the specified</param>
        /// <returns>DaoContext instance.</returns>
        public static DaoContext Get(string contextName, string connString)
        {
            if (contexts.ContainsKey(contextName))
            {
                return(contexts[contextName]);
            }

            // if no connection string was specified check if this logical name has
            // been initialized
            string connectionString = connString;

            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = GetContextConnectionString(contextName);
            }

            DatabaseAgent agent = DatabaseAgent.CreateAgent(GetContextDatabaseType(contextName), connectionString);

            DaoContext dao = new DaoContext();

            dao.DatabaseAgent = agent;

            if (!contexts.ContainsKey(contextName))
            {
                contexts.Add(contextName, dao);
            }
            else
            {
                contexts[contextName] = dao;
            }

            OnDaoContextConnectionStringSet(dao, contextName);

            return(dao);
        }