///// <summary>
        /////
        ///// </summary>
        ///// <param name="connectString"></param>
        ///// <param name="getStoredProc"></param>
        ///// <param name="setStoredProc"></param>
        ///// <param name="refreshStoredProc"></param>
        ///// <param name="removeStoredProc"></param>
        //[TargetConstructor]
        //public SqlConfigurationSource(
        //                [Value("ConnectionString")]string connectString,
        //                [Value("GetStoredProcedure")]string getStoredProc,
        //                [Value("SetStoredProcedure")]string setStoredProc,
        //                [Value("RefreshStoredProcedure")]string refreshStoredProc,
        //                [Value("RemoveStoredProcedure")]string removeStoredProc
        //                )
        //{
        //    if (string.IsNullOrEmpty(connectString)) throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "connectString");
        //    if (string.IsNullOrEmpty(getStoredProc)) throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "getStoredProc");
        //    if (string.IsNullOrEmpty(setStoredProc)) throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "setStoredProc");
        //    if (string.IsNullOrEmpty(refreshStoredProc)) throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "refreshStoredProc");
        //    if (string.IsNullOrEmpty(removeStoredProc)) throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "removeStoredProc");

        //    this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc);

        //    EnsureImplementation(data);
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="connectString"></param>
        /// <param name="getStoredProc"></param>
        /// <param name="setStoredProc"></param>
        /// <param name="refreshStoredProc"></param>
        /// <param name="removeStoredProc"></param>
        public SqlConfigurationSource(
            string connectString,
            string getStoredProc,
            string setStoredProc,
            string refreshStoredProc,
            string removeStoredProc
            )
        {
            if (string.IsNullOrEmpty(connectString))
            {
                throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "connectString");
            }
            if (string.IsNullOrEmpty(getStoredProc))
            {
                throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "getStoredProc");
            }
            if (string.IsNullOrEmpty(setStoredProc))
            {
                throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "setStoredProc");
            }
            if (string.IsNullOrEmpty(refreshStoredProc))
            {
                throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "refreshStoredProc");
            }
            if (string.IsNullOrEmpty(removeStoredProc))
            {
                throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "removeStoredProc");
            }

            this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc);

            EnsureImplementation(data);
        }
        /// <summary>
        /// <exclude>For unit testing purposes.</exclude>
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static SqlConfigurationSourceImplementation GetImplementation(SqlConfigurationData data)
        {
            EnsureImplementation(data);
            string connectString = data.ConnectionString;

            return((implementationByConnectionString.ContainsKey(connectString)) ? implementationByConnectionString[connectString] : null);
        }
Esempio n. 3
0
 private static void PrepareConfigSystem(SqlConfigurationData data)
 {
     if (SqlConfigurationManager.initState < SqlConfigurationManager.InitState.Usable)
     {
         SqlConfigurationManager.EnsureConfigurationSystem(data);
     }
 }
Esempio n. 4
0
 private static void EnsureConfigurationSystem(SqlConfigurationData data)
 {
     lock (SqlConfigurationManager.initLock)
     {
         if (SqlConfigurationManager.initState >= SqlConfigurationManager.InitState.Usable)
         {
             return;
         }
         SqlConfigurationManager.initState = SqlConfigurationManager.InitState.Started;
         try
         {
             try
             {
                 SqlConfigurationManager.configSystem = new SqlConfigurationSystem(data);
                 SqlConfigurationManager.initState    = SqlConfigurationManager.InitState.Usable;
             }
             catch (Exception exception1)
             {
                 throw new ConfigurationErrorsException(Properties.Resources.ExceptionConfigurationInitialization, exception1);
             }
         }
         catch
         {
             SqlConfigurationManager.initState = SqlConfigurationManager.InitState.Completed;
             throw;
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sectionName"></param>
 /// <param name="data"></param>
 public static void RemoveSection(string sectionName, SqlConfigurationData data)
 {
     if (!string.IsNullOrEmpty(sectionName))
     {
         SqlConfigurationManager.PrepareConfigSystem(data);
         SqlConfigurationManager.configSystem.RemoveSection(sectionName);
     }
 }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="refresh"></param>
        public SqlConfigurationSourceImplementation(SqlConfigurationData data, bool refresh)
        {
            this.data = new SqlConfigurationData(data);

            this.refresh = refresh;

            this.watchedConfigSourceMapping = new Dictionary <string, ConfigurationSourceWatcher>();
            this.watchedSectionMapping      = new Dictionary <string, ConfigurationSourceWatcher>();
        }
Esempio n. 7
0
 /// <summary>
 /// Retrieves a specified configuration section for the current application's configuration
 /// </summary>
 /// <param name="sectionName">The configuration section name.</param>
 /// <param name="data">The configuration data for this connection.</param>
 /// <returns>The specified System.Configuration.ConfigurationSection object, or null if the section does not exist.</returns>
 public static object GetSection(string sectionName, SqlConfigurationData data)
 {
     if (string.IsNullOrEmpty(sectionName))
     {
         return(null);
     }
     SqlConfigurationManager.PrepareConfigSystem(data);
     return(SqlConfigurationManager.configSystem.GetSection(sectionName));
 }
 private static void EnsureImplementation(SqlConfigurationData data)
 {
     if (!implementationByConnectionString.ContainsKey(data.ConnectionString))
     {
         lock (lockObject)
         {
             SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(data);
             implementationByConnectionString.Add(data.ConnectionString, implementation);
         }
     }
 }
        public void TestInitialize()
        {
            string connectString     = @"server=(local)\SQLExpress;database=Northwind;Integrated Security=true";
            string getStoredProc     = @"EntLib_GetConfig";
            string setStoredProc     = @"EntLib_SetConfig";
            string refreshStoredProc = @"UpdateSectionDate";
            string removeStoredProc  = @"EntLib_RemoveSection";

            this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc);

            ClearConfigs();
        }
Esempio n. 10
0
        public void Initialize()
        {
            string connectString1    = @"server=(local)\SQLExpress;database=Northwind;Integrated Security=true";
            string connectString2    = @"server=(local)\SQLExpress;database=Northwind;";
            string getSproc          = @"EntLib_GetConfig";
            string setStoredProc     = @"EntLib_SetConfig";
            string refreshStoredProc = @"UpdateSectionDate";
            string removeStoredProc  = @"EntLib_RemoveSection";

            data1 = new SqlConfigurationData(connectString1, getSproc, setStoredProc, refreshStoredProc, removeStoredProc);
            data2 = new SqlConfigurationData(connectString2, getSproc, setStoredProc, refreshStoredProc, removeStoredProc);
        }
        /// <summary>
        /// <exclude>For unit testing purposes.</exclude>
        /// </summary>
        public static void ResetImplementation(SqlConfigurationData data, bool refreshing)
        {
            SqlConfigurationSourceImplementation currentImplementation = null;

            implementationByConnectionString.TryGetValue(data.ConnectionString, out currentImplementation);
            implementationByConnectionString[data.ConnectionString] =
                new SqlConfigurationSourceImplementation(data.ConnectionString, data.GetStoredProcedure, data.SetStoredProcedure, data.RefreshStoredProcedure, data.RemoveStoredProcedure, refreshing);

            if (currentImplementation != null)
            {
                currentImplementation.Dispose();
            }
        }
Esempio n. 12
0
        public void SharedConfigurationFilesCanHaveDifferentCasing()
        {
            SqlConfigurationSourceImplementation configSourceImpl1 = SqlConfigurationSource.GetImplementation(data1);

            SqlConfigurationData tempData = new SqlConfigurationData(
                data1.ConnectionString.ToUpper(),
                data1.GetStoredProcedure.ToUpper(),
                data1.SetStoredProcedure.ToUpper(),
                data1.RefreshStoredProcedure.ToUpper(),
                data1.RemoveStoredProcedure.ToUpper());
            SqlConfigurationSourceImplementation configSourceImpl2 = SqlConfigurationSource.GetImplementation(tempData);

            Assert.AreSame(configSourceImpl1, configSourceImpl2);
        }
Esempio n. 13
0
        public void Setup()
        {
            string connectString     = @"server=(local)\SQLExpress;database=Northwind;Integrated Security=true";
            string getStoredProc     = @"EntLib_GetConfig";
            string setStoredProc     = @"EntLib_SetConfig";
            string refreshStoredProc = @"UpdateSectionDate";
            string removeStoredProc  = @"EntLib_RemoveSection";

            this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc);

            SqlConfigurationSource.ResetImplementation(data, false);

            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            DummySection rwSection;

            rwConfiguration.Sections.Remove(localSection);
            rwConfiguration.Sections.Add(localSection, rwSection = new DummySection());
            rwSection.Name  = localSection;
            rwSection.Value = 10;
            SqlConfigurationSourceImplementation configSourceImpl = new SqlConfigurationSourceImplementation(this.data, false);

            configSourceImpl.SaveSection(rwSection.Name, rwSection);

            rwConfiguration.Sections.Remove(externalSection);
            rwConfiguration.Sections.Add(externalSection, rwSection = new DummySection());
            rwSection.Name  = externalSection;
            rwSection.Value = 20;
            configSourceImpl.SaveSection(rwSection.Name, rwSection);

            rwConfiguration.Sections.Remove(localSection2);
            rwConfiguration.Sections.Add(localSection2, rwSection = new DummySection());
            rwSection.Name  = localSection2;
            rwSection.Value = 30;
            configSourceImpl.SaveSection(rwSection.Name, rwSection);

            rwConfiguration.Save();

            SqlConfigurationManager.RefreshSection(localSection, this.data);
            SqlConfigurationManager.RefreshSection(localSection2, this.data);
            SqlConfigurationManager.RefreshSection(externalSection, this.data);

            ConfigurationChangeSqlWatcher.ResetDefaultPollDelay();

            updatedSectionsTally = new Dictionary <string, int>(0);
        }
Esempio n. 14
0
        public void TestInitialize()
        {
            string connectString     = @"server=(local)\SQLExpress;database=Northwind;Integrated Security=true";
            string getStoredProc     = @"EntLib_GetConfig";
            string setStoredProc     = @"EntLib_SetConfig";
            string removeStoredProc  = @"EntLib_RemoveSection";
            string refreshStoredProc = @"UpdateSectionDate";

            this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc);

            configSystem = new SqlConfigurationSystem(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc);
            if (SqlConfigurationManager.InitializationState == SqlConfigurationManager.InitState.NotStarted)
            {
                SqlConfigurationManager.SetConfigurationSystem(configSystem, true);
            }

            ClearConfigs();
        }
Esempio n. 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 public SqlConfigurationSourceImplementation(SqlConfigurationData data)
     : this(data, true)
 {
 }
Esempio n. 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sectionName"></param>
 /// <param name="section"></param>
 /// <param name="data"></param>
 public static void SaveSection(string sectionName, SerializableConfigurationSection section, SqlConfigurationData data)
 {
     if (!string.IsNullOrEmpty(sectionName))
     {
         SqlConfigurationManager.PrepareConfigSystem(data);
         SqlConfigurationManager.configSystem.SaveSection(sectionName, section);
     }
 }