internal static void InitPolling(string database)
        {
            SqlCacheDependencySection sqlCacheDependency = RuntimeConfig.GetAppConfig().SqlCacheDependency;

            if (!sqlCacheDependency.Enabled)
            {
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Polling_not_enabled_for_sql_cache"), sqlCacheDependency.ElementInformation.Properties["enabled"].Source, sqlCacheDependency.ElementInformation.Properties["enabled"].LineNumber);
            }
            SqlCacheDependencyDatabase databaseConfig = GetDatabaseConfig(database);

            if (databaseConfig.PollTime == 0)
            {
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Polltime_zero_for_database_sql_cache", new object[] { database }), databaseConfig.ElementInformation.Properties["pollTime"].Source, databaseConfig.ElementInformation.Properties["pollTime"].LineNumber);
            }
            if (!s_DatabaseNotifStates.ContainsKey(database))
            {
                string connection = SqlConnectionHelper.GetConnectionString(databaseConfig.ConnectionStringName, true, true);
                if ((connection == null) || (connection.Length < 1))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Connection_string_not_found", new object[] { databaseConfig.ConnectionStringName }), databaseConfig.ElementInformation.Properties["connectionStringName"].Source, databaseConfig.ElementInformation.Properties["connectionStringName"].LineNumber);
                }
                lock (s_DatabaseNotifStates)
                {
                    if (!s_DatabaseNotifStates.ContainsKey(database))
                    {
                        DatabaseNotifState state;
                        state = new DatabaseNotifState(database, connection, databaseConfig.PollTime)
                        {
                            _timer = new Timer(s_timerCallback, state, 0, databaseConfig.PollTime)
                        };
                        s_DatabaseNotifStates.Add(database, state);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void Main()
        {
// <Snippet1>
            // Get the Web application configuration.
            System.Configuration.Configuration webConfig =
                WebConfigurationManager.OpenWebConfiguration("/aspnetTest");

            // Get the section.
            string configPath = "system.web/cache/sqlCacheDependency";

            System.Web.Configuration.SqlCacheDependencySection sqlDs =
                (System.Web.Configuration.SqlCacheDependencySection)webConfig.GetSection(
                    configPath);

            // Get the databases element at 0 index.
            System.Web.Configuration.SqlCacheDependencyDatabase sqlCdd =
                sqlDs.Databases[0];

// </Snippet1>


// <Snippet2>

            // Get the current PollTime property value.
            Int32 pollTimeValue = sqlCdd.PollTime;

            // Set the PollTime property to 1000 milliseconds.
            sqlCdd.PollTime = 1000;

// </Snippet2>


// <Snippet3>

            // Get the current Name property value.
            string nameValue = sqlCdd.Name;

            // Set the Name for this configuration element.
            sqlCdd.Name = "ConfigElementName";

// </Snippet3>


// <Snippet4>

            // Get the current ConnectionStringName property value.
            string connectionNameValue = sqlCdd.ConnectionStringName;

            // Set the ConnectionName property. This is the database name.
            sqlCdd.ConnectionStringName = "DataBaseName";

// </Snippet4>


// <Snippet5>
            SqlCacheDependencyDatabase dbElement0 =
                new SqlCacheDependencyDatabase(
                    "dataBase", "dataBaseElement", 500);

// </Snippet5>

// <Snippet6>

            SqlCacheDependencyDatabase dbElement1 =
                new SqlCacheDependencyDatabase(
                    "dataBase1", "dataBaseElement1");

// </Snippet6>
        }
 // Methods
 public void Add(SqlCacheDependencyDatabase name)
 {
 }
 public void Set(SqlCacheDependencyDatabase user)
 {
 }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
// <Snippet1>
            // Get the Web application configuration.
            Configuration webConfig =
                WebConfigurationManager.OpenWebConfiguration("/aspnetTest");

            // Get the section.
            string configPath = "system.web/cache/sqlCacheDependency";
            SqlCacheDependencySection sqlCacheDependencySection =
                (SqlCacheDependencySection)webConfig.GetSection(configPath);

            // Get the database element at the specified index.
            SqlCacheDependencyDatabaseCollection sqlCdds =
                sqlCacheDependencySection.Databases;

// </Snippet1>

// <Snippet2>

            object[] collectionKeys = sqlCdds.AllKeys;

// </Snippet2>

// <Snippet3>
            SqlCacheDependencyDatabase dbElement =
                new SqlCacheDependencyDatabase(
                    "dataBase", "dataBaseElement", 500);

            sqlCdds.Add(dbElement);

// </Snippet3>

// <Snippet4>
            sqlCdds.Clear();

// </Snippet4>

// <Snippet5>
            SqlCacheDependencyDatabase dbElement1 =
                sqlCdds.Get(0);

// </Snippet5>

// <Snippet6>
            SqlCacheDependencyDatabase dbElement3 =
                sqlCdds.Get("dataBaseElement");

// </Snippet6>

// <Snippet7>
            string thisKey = sqlCdds.GetKey(0).ToString();

// </Snippet7>

// <Snippet8>
            sqlCdds.Remove("dataBaseElement");

// </Snippet8>

// <Snippet9>
            sqlCdds.RemoveAt(0);

// </Snippet9>

// <Snippet10>
            SqlCacheDependencyDatabase dbElement2 =
                new SqlCacheDependencyDatabase(
                    "dataBase2", "dataBaseElement2", 500);

            sqlCdds.Set(dbElement2);

// </Snippet10>
        }
 // Methods
 public void Add(SqlCacheDependencyDatabase name)
 {
 }
 public void Set(SqlCacheDependencyDatabase user)
 {
 }