示例#1
0
        /// <summary>
        /// Get show connection string in specific environment.
        /// </summary>
        /// <param name="showCode"></param>
        /// <param name="environment"></param>
        /// <param name="appTypeCode"></param>
        /// <returns></returns>
        public virtual string GetConnectionString(string showCode, ServerTypeCode environment, AppTypeCode appTypeCode)
        {
            // flush environment keys
            CMSecurity.Flush();

            // find environment master
            DataRow[] server = ConnectionManagerBase.ServerTable.Select("servertypecode = '" + environment.ToString() + "' and IsEnvironmentMaster = 1");
            if (server.Length == 0)
            {
                throw new Exception("Failed to retrieve environment server information.");
            }
            string entServerName = server[0]["ServerName"].ToString();

            // for caching purpose
            string cachedConnectionStringKey = string.Concat(entServerName, showCode, appTypeCode.ToString()).ToLower();

            if (cachedConnectionStrings.ContainsKey(cachedConnectionStringKey))
            {
                return(cachedConnectionStrings[cachedConnectionStringKey].ToString());
            }

            return(this.GetConnectionString(
                       cachedConnectionStringKey,
                       ConnectionManagerBase.GetGenericConnectionString(entServerName, this.EntDatabaseName),
                       showCode,
                       appTypeCode.ToString()));
        }
示例#2
0
        /// <summary>
        /// Pass in temporary enterprise connection string instead of retrieving from config file.
        /// Might be used to retrieve show connection string from other server.
        /// </summary>
        /// <param name="entConnectionString"></param>
        public ConnectionManagerBase(string entConnectionString)
        {
            CMSecurity.Flush();

            // need to validate if this is an enterprise connection string
            string enterpriseDatabaseName = "Enterprise";

            // VS2005
            if (System.Configuration.ConfigurationManager.AppSettings[DefaultEntDatabaseNameAppSettingsKey] != null)
            {
                // VS2005
                enterpriseDatabaseName = System.Configuration.ConfigurationManager.AppSettings[DefaultEntDatabaseNameAppSettingsKey];
            }

            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"database\s*=\s*" + enterpriseDatabaseName, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            if (reg.IsMatch(entConnectionString))
            {
                this.passedEntConnectionString = entConnectionString;
            }
            else
            {
                string   newEntConnectionString = "";
                string[] part = entConnectionString.Split(';');
                for (int i = 0; i < part.Length; i++)
                {
                    if (part[i].Length > 0)
                    {
                        if (part[i].ToLower().Trim().IndexOf("database") == 0)
                        {
                            part[i] = "database=" + enterpriseDatabaseName;
                        }
                        newEntConnectionString += part[i];
                        if (i != part.Length - 1)
                        {
                            newEntConnectionString += ";";
                        }
                    }
                }
                this.passedEntConnectionString = newEntConnectionString;
            }
        }