EnsureId() публичный Метод

Creates the or fetch application id.
public EnsureId ( MySqlConnection connection ) : int
connection MySql.Data.MySqlClient.MySqlConnection The connection.
Результат int
Пример #1
0
    /// <summary>
    /// Initializes the provider with the property values specified in the ASP.NET application configuration file
    /// </summary>
    /// <param name="name">The name of the provider instance to initialize.</param>
    /// <param name="config">Object that contains the names and values of configuration options for the provider.
    /// </param>
    public override void Initialize(string name, NameValueCollection config)
    {
      //Initialize values from web.config.
      if (config == null)
        throw new ArgumentException("config");
      if (name == null || name.Length == 0)
        throw new ArgumentException("name");
      if (String.IsNullOrEmpty(config["description"]))
      {
        config.Remove("description");
        config["description"] = "MySQL Session State Store Provider";
      }
      base.Initialize(name, config);
      string applicationName = HostingEnvironment.ApplicationVirtualPath;
      if (!String.IsNullOrEmpty(config["applicationName"]))
        applicationName = config["applicationName"];

      // Get <sessionState> configuration element.
      Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath);
      sessionStateConfig = (SessionStateSection)webConfig.SectionGroups["system.web"].Sections["sessionState"];

      // Initialize connection.
      connectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
      if (connectionStringSettings == null || connectionStringSettings.ConnectionString.Trim() == "")
        throw new HttpException("Connection string can not be blank");
      connectionString = connectionStringSettings.ConnectionString;

      writeExceptionsToEventLog = false;
      if (config["writeExceptionsToEventLog"] != null)
      {
        writeExceptionsToEventLog = (config["writeExceptionsToEventLog"].ToUpper() == "TRUE");
      }

      enableExpireCallback = false;

      if (config["enableExpireCallback"] != null)
      {
        enableExpireCallback = (config["enableExpireCallback"].ToUpper() == "TRUE");
      }

      // Make sure we have the correct schema.
      SchemaManager.CheckSchema(connectionString, config);
      app = new Application(applicationName, base.Description);

      // Get the application id.
      try
      {
        using (MySqlConnection conn = new MySqlConnection(connectionString))
        {
          conn.Open();
          app.EnsureId(conn);
          CheckStorageEngine(conn);         
        }
      }
      catch (MySqlException e)
      {
        HandleMySqlException(e, "Initialize");
      }

      // Add  cleanup interval
      MySqlTransaction mySqlTransaction = null;
      try
      {
        using (MySqlConnection conn = new MySqlConnection(connectionString))
        {
          MySqlCommand cmd = new MySqlCommand(
              "INSERT IGNORE INTO my_aspnet_sessioncleanup SET" +
              " ApplicationId = @ApplicationId, " +
              " LastRun = NOW(), " +
              " IntervalMinutes = 10",
             conn);
          cmd.Parameters.AddWithValue("@ApplicationId", ApplicationId);
          conn.Open();
          mySqlTransaction = conn.BeginTransaction();
          cmd.ExecuteNonQuery();
          mySqlTransaction.Commit();
          cleanupInterval = GetCleanupInterval(conn, ApplicationId);
        }
      }
      catch (MySqlException e)
      {
        if (mySqlTransaction != null)
        {
          try
          {
            Trace.WriteLine("Initialize: Attempt to rollback");
            mySqlTransaction.Rollback();
          }
          catch (MySqlException ex)
          {
            HandleMySqlException(ex, "Initialize: Rollback Failed");
          }
        }
        HandleMySqlException(e, "Initialize");
      }
      finally
      {
        if (mySqlTransaction != null)
          mySqlTransaction.Dispose();
      }

   
      // Setup the cleanup timer
      if (cleanupInterval <= 0)
        cleanupInterval = 1;
      cleanupTimer = new Timer(new TimerCallback(CleanupOldSessions), null, 0,
          cleanupInterval * 1000 * 60);
    }
Пример #2
0
        /// <summary>
        /// Initializes the provider with the property values specified in the ASP.NET application configuration file
        /// </summary>
        /// <param name="name">The name of the provider instance to initialize.</param>
        /// <param name="config">Object that contains the names and values of configuration options for the provider.
        /// </param>
        public override void Initialize(string name, NameValueCollection config)
        {
            //Initialize values from web.config.
              if (config == null)
            throw new ArgumentException("config");
              if (name == null || name.Length == 0)
            throw new ArgumentException("name");
              if (String.IsNullOrEmpty(config["description"]))
              {
            config.Remove("description");
            config["description"] = "MySQL Session State Store Provider";
              }
              base.Initialize(name, config);
              string applicationName = HostingEnvironment.ApplicationVirtualPath;
              if (!String.IsNullOrEmpty(config["applicationName"]))
            applicationName = config["applicationName"];

              // Get <sessionState> configuration element.
              Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath);
              sessionStateConfig = (SessionStateSection)webConfig.SectionGroups["system.web"].Sections["sessionState"];

              // Initialize connection.
              connectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
              if (connectionStringSettings == null || connectionStringSettings.ConnectionString.Trim() == "")
            throw new HttpException("Connection string can not be blank");
              connectionString = connectionStringSettings.ConnectionString;

              writeExceptionsToEventLog = false;
              if (config["writeExceptionsToEventLog"] != null)
              {
            writeExceptionsToEventLog = (config["writeExceptionsToEventLog"].ToUpper() == "TRUE");
              }

              // Make sure we have the correct schema.
              SchemaManager.CheckSchema(connectionString, config);
              app = new Application(applicationName, base.Description);

              // Get the application id.
              try
              {
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
              conn.Open();
              app.EnsureId(conn);
              CheckStorageEngine(conn);
              cleanupInterval = GetCleanupInterval(conn);
            }
              }
              catch (MySqlException e)
              {
            HandleMySqlException(e, "Initialize");
              }

              // Setup the cleanup timer
              if (cleanupInterval <= 0)
            cleanupInterval = 1;
              cleanupTimer = new Timer(new TimerCallback(CleanupOldSessions), null, 0,
              cleanupInterval * 1000 * 60);
        }
    /// <summary>
    /// Initializes settings values for Personalization Provider
    /// </summary>
    /// <param name="name"></param>
    /// <param name="config"></param>
    public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
    {
      if (config == null)
        throw new ArgumentNullException("config");

      if (string.IsNullOrEmpty(name))
      {
        name = "MySqlPersonalizationProvider";
      }

      if (string.IsNullOrEmpty(config["description"]))
      {
        config.Remove("description");
        config.Add("description", "MySql Personalization provider");      
      }

      base.Initialize(name, config);

      string applicationName = HostingEnvironment.ApplicationVirtualPath;
      if (!String.IsNullOrEmpty(config["applicationName"]))
        applicationName = config["applicationName"];


      if (!(config["writeExceptionsToEventLog"] == null))
      {
        if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE")
        {
          writeExceptionsToEventLog = true;
        }
      }

      connectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
      if (connectionStringSettings != null)
        connectionString = connectionStringSettings.ConnectionString.Trim();
      else
        connectionString = "";

      if (String.IsNullOrEmpty(connectionString)) return;

      // Make sure we have the correct schema.
      SchemaManager.CheckSchema(connectionString, config);

      app = new Application(applicationName, base.Description);

      // Get the application id.
      try
      {
        using (MySqlConnection conn = new MySqlConnection(connectionString))
        {
          conn.Open();
          app.EnsureId(conn);          
        }
      }
      catch (Exception ex)
      {
        if (writeExceptionsToEventLog)
          WriteToEventLog(ex, "MySQLPersonalizationProvider - Initialize");        
        throw;
      }  
    }