protected QueueTest(string connectionStringName)
 {
     var connectionStringBuilder =
         new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString);
     var databaseName = connectionStringBuilder.InitialCatalog;
     connectionStringBuilder.InitialCatalog = "master";
     using(var connection = new SqlConnection(connectionStringBuilder.ConnectionString))
     {
         connection.Open();
         using(var createCommand = new SqlCommand(
         @"
         IF ((SELECT DB_ID ('<databasename, sysname, queuedb>')) IS NULL)
         BEGIN
             CREATE DATABASE [<databasename, sysname, queuedb>]
         END".Replace("<databasename, sysname, queuedb>", databaseName), connection))
         {
             createCommand.CommandType = CommandType.Text;
             createCommand.ExecuteNonQuery();
         }
     }
     try
     {
         var storage = new QueueStorage(connectionStringName);
         storage.Initialize();
     }
     catch(SqlException)
     {
         new SchemaCreator().Create(connectionStringName, 2204);
     }
     StorageUtil.PurgeAll(connectionStringName);
 }
        public QueueManager(string connectionStringName)
        {
            QueueStorage = new QueueStorage(connectionStringName);
            QueueStorage.Initialize();

            PurgeOldDataTimer = new Timer(PurgeOldData, null, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3));
        }
Example #3
0
        protected void EnsureStorage( string connectionString )
        {
            bool runInstall = CreateDatabaseIfNotExists( connectionString );

             if( runInstall )
             {
            SchemaManager.Install( connectionString );
             }

             var storage = new QueueStorage( connectionString );

             try
             {
            storage.Initialize();
             }
             catch(Exception ex)
             {
            if ( !( ex is InvalidOperationException ) && !( ex is SqlException ) )
            {
               throw;
            }

            SchemaManager.Install( connectionString );
            storage.Initialize();
             }

             using ( var qManager = new QueueManager( connectionString, port: 2204 ) )
             {
            qManager.ConfigureEndPoint();
             }

             StorageUtil.PurgeAll( connectionString );
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueManager"/> class.
 /// </summary>
 /// <param name="connectionString">The connectionstring.</param>
 /// <param name="scheme">The scheme or <c>null</c> to use the default (tcp).</param>
 /// <param name="host">The host or <c>null</c> for localhost.</param>
 /// <param name="port">The port or <c>null</c> for the default (2204).</param>
 public QueueManager( string connectionString, string scheme = null, string host = null, int? port = null )
 {
     baseUri = new Uri( string.Format( "{0}://{1}:{2}", scheme ?? "tcp", host ?? "localhost", port ?? 2204 ) );
        queueStorage = new QueueStorage( connectionString );
        queueStorage.Initialize();
        purgeOldDataTimer = new Timer( PurgeOldData, null, TimeSpan.FromMinutes( 3 ), TimeSpan.FromMinutes( 3 ) );
 }
 public CanUseQueue() : base("testqueue")
 {
     QueueStorage = new QueueStorage("testqueue");
     QueueStorage.Initialize();
     QueueStorage.Global(actions =>
     {
         actions.BeginTransaction();
         actions.CreateQueue(QueueUri);
         actions.Commit();
     });
 }
 public CanUseQueue()
 {
     EnsureStorage( ConnectionString );
     qf = new QueueStorage( ConnectionString );
     qf.Initialize();
     qf.Global(actions =>
     {
         actions.BeginTransaction();
         actions.CreateQueue(queueUri);
         actions.Commit();
     });
 }
		protected QueueTest(string connectionStringName)
		{
			var connectionStringBuilder =
				new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString);
			var databaseName = connectionStringBuilder.InitialCatalog;
			connectionStringBuilder.InitialCatalog = "master";
			using(var connection = new SqlConnection(connectionStringBuilder.ConnectionString))
			{
			    bool databaseExists = false;
				connection.Open();
                using (var dbExistsCommand = new SqlCommand($"SELECT DB_ID ('{databaseName}')", connection))
                {
                   dbExistsCommand.CommandType = CommandType.Text;
                   var result = dbExistsCommand.ExecuteScalar();
                   databaseExists = !String.IsNullOrEmpty(result.ToString());
                }
                //Create database if it does not exist
			    if (!databaseExists)
			    {
			        using (var createCommand = new SqlCommand(
			            @"				
				BEGIN
					CREATE DATABASE [<databasename, sysname, queuedb>]
				END".Replace("<databasename, sysname, queuedb>", databaseName), connection))
			        {
			            createCommand.CommandType = CommandType.Text;

			            createCommand.ExecuteNonQuery();
			        }
			    }

			
			}
			try
			{
                var storage = new QueueStorage(connectionStringName);
				storage.Initialize();
			}
			catch(SqlException ex)
            {
                new SchemaCreator().Create(connectionStringName, 2204);
            }
			StorageUtil.PurgeAll(connectionStringName);
		}