public void Ctor_CanCreateSqlServerStorage_WithExistingConnection() { var connection = ConnectionUtils.CreateConnection(); var storage = new SqlServerStorage(connection); Assert.NotNull(storage); }
private static CountersAggregator CreateAggregator(SqlConnection connection) { var storage = new SqlServerStorage(connection, new SqlServerStorageOptions { SqlServer2005Compatibility = true }); return new CountersAggregator(storage, TimeSpan.Zero); }
public void Ctor_CreatesSqlServer2005Settings() { var options = new SqlServerStorageOptions { SqlServer2005Compatibility = true }; var storage = new SqlServerStorage(ConnectionUtils.GetConnectionString(), options); Assert.Equal(typeof(SqlServer2005Settings), storage.SqlServerSettings.GetType()); }
/// <summary> /// Tells the bootstrapper to use SQL Server as a job storage, /// that can be accessed using the given connection string or /// its name. /// </summary> /// <param name="configuration">Configuration</param> /// <param name="nameOrConnectionString">Connection string or its name</param> public static SqlServerStorage UseSqlServerStorage( this IBootstrapperConfiguration configuration, string nameOrConnectionString) { var storage = new SqlServerStorage(nameOrConnectionString); configuration.UseStorage(storage); return storage; }
public void DistributedLocks_AreReEntrant_FromTheSameThread_OnTheSameResource() { var storage = new SqlServerStorage(ConnectionUtils.GetConnectionString()); using (new SqlServerDistributedLock(storage, "hello", TimeSpan.FromMinutes(5))) using (new SqlServerDistributedLock(storage, "hello", TimeSpan.FromMinutes(5))) { Assert.True(true); } }
public void OrdersExtractBad2() { var storage = new SqlServerStorage(typeof(OrdersVerticalBar)); storage.SelectSql = "SELECT TOP 100 * FROM Orders"; storage.FillRecordCallback = new FillRecordHandler(FillRecordOrder); Assert.Throws <BadUsageException>(() => storage.ExtractRecords()); }
public void OrdersExtractBad4() { var storage = new SqlServerStorage(typeof(OrdersVerticalBar), "NEON-64", "SureThatThisDontExist"); storage.SelectSql = "SELECT TOP 100 * FROM Orders"; Assert.Throws <SqlException>(() => storage.ExtractRecords()); }
public static SqlServerStorage UseServiceBusQueues( this SqlServerStorage storage, string connectionString) { return(UseServiceBusQueues(storage, new ServiceBusQueueOptions { ConnectionString = connectionString, Queues = new[] { EnqueuedState.DefaultQueue } })); }
public void GetConnection_ReturnsExistingConnection_WhenStorageUsesIt() { var connection = ConnectionUtils.CreateConnection(); var storage = new SqlServerStorage(connection); using (var storageConnection = (SqlServerConnection)storage.GetConnection()) { Assert.Same(connection, storageConnection.Connection); Assert.False(storageConnection.OwnsConnection); } }
public SqlServerFetchedJob( DelayedJob job, SqlServerStorage storage, IDbConnection connection, IDbTransaction transaction) { Job = job; _storage = storage; _connection = connection; _transaction = transaction; }
public void GetConnection_ReturnsExistingConnection_WhenStorageUsesIt() { var connection = ConnectionUtils.CreateConnection(); var storage = new SqlServerStorage(connection); using (var storageConnection = (SqlServerConnection) storage.GetConnection()) { Assert.Same(connection, storageConnection.Connection); Assert.False(storageConnection.OwnsConnection); } }
public void OrdersInsertEasy() { SqlServerStorage storage = new SqlServerStorage(typeof(CustomersVerticalBar)); storage.ServerName = "NEON-64"; storage.DatabaseName = "Northwind"; storage.InsertSqlCallback = new InsertSqlHandler(GetInsertSqlCust); FileDataLink.EasyInsertFromFile(storage, TestCommon.TestPath(@"Good\CustomersVerticalBar.txt")); }
public static SqlServerStorage UseServiceBusQueues( this SqlServerStorage storage, string connectionString, params string[] queues) { return(UseServiceBusQueues(storage, new ServiceBusQueueOptions { ConnectionString = connectionString, Queues = queues })); }
private void UseConnections(Action <SqlConnection, SqlServerConnection> action) { using (var sqlConnection = ConnectionUtils.CreateConnection()) { var storage = new SqlServerStorage(sqlConnection); using (var connection = new SqlServerConnection(storage)) { action(sqlConnection, connection); } } }
/// <summary> /// Tells the bootstrapper to use SQL Server as a job storage /// with the given options, that can be accessed using the specified /// connection string or its name. /// </summary> /// <param name="configuration">Configuration</param> /// <param name="nameOrConnectionString">Connection string or its name</param> /// <param name="options">Advanced options</param> public static SqlServerStorage UseSqlServerStorage( this IBootstrapperConfiguration configuration, string nameOrConnectionString, SqlServerStorageOptions options) { var storage = new SqlServerStorage(nameOrConnectionString, options); configuration.UseStorage(storage); return(storage); }
public void OrdersInsert() { SqlServerStorage storage = new SqlServerStorage(typeof(CustomersVerticalBar)); storage.ServerName = "NEON-64"; storage.DatabaseName = "Northwind"; storage.InsertSqlCallback = new InsertSqlHandler(GetInsertSqlCust); storage.InsertRecords(CommonEngine.ReadFile(typeof(CustomersVerticalBar), TestCommon.TestPath(@"Good\CustomersVerticalBar.txt"))); }
public static SqlServerStorage UseRabbitMq(this SqlServerStorage storage, Action <RabbitMqConnectionConfiguration> configureAction, params string[] queues) { if (storage == null) { throw new ArgumentNullException("storage"); } if (queues == null) { throw new ArgumentNullException("queues"); } if (queues.Length == 0) { throw new ArgumentException("No queue(s) specified for RabbitMQ provider.", "queues"); } if (configureAction == null) { throw new ArgumentNullException("configureAction"); } var conf = new RabbitMqConnectionConfiguration(); configureAction(conf); var cf = new ConnectionFactory(); // Use configuration from URI, otherwise use properties if (conf.Uri != null) { cf.uri = conf.Uri; } else { cf.HostName = conf.HostName; cf.Port = conf.Port; cf.UserName = conf.Username; cf.Password = conf.Password; cf.VirtualHost = conf.VirtualHost; } cf.NetworkRecoveryInterval = conf.NetworkRecoveryInterval; cf.TopologyRecoveryEnabled = conf.TopologyRecoveryEnabled; cf.AutomaticRecoveryEnabled = conf.AutomaticRecoveryEnabled; var provider = new RabbitMqJobQueueProvider(queues, cf, channel => channel.BasicQos(0, conf.PrefetchCount, false // applied separately to each new consumer on the channel )); storage.QueueProviders.Add(provider, queues); return(storage); }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); var storage1 = new SqlServerStorage("HangfireR3"); var storage2 = new SqlServerStorage("HangfireR4"); app.UseHangfireDashboard("/hangfire1", new DashboardOptions(), storage1); app.UseHangfireDashboard("/hangfire2", new DashboardOptions(), storage2); //app.UseHangfireServer(); }
private void UseConnections(Action <SqlConnection, SqlServerConnection> action, bool useBatching = false) { using (var sqlConnection = ConnectionUtils.CreateConnection()) { var storage = new SqlServerStorage(sqlConnection, new SqlServerStorageOptions { CommandBatchMaxTimeout = useBatching ? TimeSpan.FromMinutes(1) : (TimeSpan?)null }); using (var connection = new SqlServerConnection(storage)) { action(sqlConnection, connection); } } }
private void ConfigureStorage() { string connectionstring = "data source=(localdb)\\MSSQLLocalDB;initial catalog=LocalBWorkerDB;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework;"; var sqlStorage = new SqlServerStorage(connectionstring); var options = new BackgroundJobServerOptions { ServerName = "(localdb)\\MSSQLLocalDB" }; JobStorage.Current = sqlStorage; GlobalConfiguration.Configuration.UseSqlServerStorage(connectionstring); }
private static void UseConnection(Action <IDbConnection, SqlServerStorage> action, bool useMicrosoftDataSqlClient) { using (var connection = ConnectionUtils.CreateConnection(useMicrosoftDataSqlClient)) { var storage = new SqlServerStorage( connection, new SqlServerStorageOptions { SlidingInvisibilityTimeout = TimeSpan.FromSeconds(10) }); action(connection, storage); } }
static void Main(string[] args) { SqlServerStorage storage = new SqlServerStorage(typeof(CustomersVerticalBar)); storage.ServerName = "MYSERVER"; storage.DatabaseName = "Northwind"; // Comment this for Windows Auth storage.UserName = "******"; storage.UserPass = "******"; storage.InsertSqlCallback = new InsertSqlHandler(GetInsertSqlCust); storage.InsertRecords(CommonEngine.ReadFile(typeof(CustomersVerticalBar), "infile.txt")); Console.ReadKey(); }
public static SqlServerStorage UseServiceBusQueues( this SqlServerStorage storage, string connectionString, Action <QueueDescription> configureAction, params string[] queues) { return(UseServiceBusQueues(storage, new ServiceBusQueueOptions { ConnectionString = connectionString, Configure = configureAction, Queues = queues })); }
public static SqlServerStorage UseMsmqQueues(this SqlServerStorage storage, string pathPattern, params string[] queues) { if (storage == null) { throw new ArgumentNullException("storage"); } var provider = new MsmqJobQueueProvider(pathPattern, queues); storage.QueueProviders.Add(provider, queues); return(storage); }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); //string cs = ConfigurationManager.ConnectionStrings["RevenueConnectEntities"].ConnectionString; var storage1 = new SqlServerStorage("Data Source = db101; Initial Catalog = spReportScheduler; User ID = poprocksuser; Password = rock#roll"); //app.UseHangfireDashboard("/hangfire", new DashboardOptions(),storage1); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new MyAuthorizationFilter() } }, storage1); }
private void UseConnections(Action<SqlConnection, SqlServerConnection> action) { using (var sqlConnection = ConnectionUtils.CreateConnection()) { var storage = new SqlServerStorage(sqlConnection, new SqlServerStorageOptions { SqlServer2005Compatibility = true }); using (var connection = new SqlServerConnection(storage)) { action(sqlConnection, connection); } } }
public static void Configure(IAppBuilder app) { GlobalConfiguration.Configuration.UseBatches(); var nugetDemoStorage = new SqlServerStorage("NugetDemo"); app.UseHangfireDashboard("/nugetDemo", new DashboardOptions(), nugetDemoStorage); var hangfireDemoStorage = new RedisStorage( "hangfiredemo.redis.cache.windows.net:6380,password=Ihtp+DY31J5i5/CIC2NaZyvQz2q8e5WeCrC4fBcEMNU=,ssl=True,abortConnect=False"); app.UseHangfireDashboard("/hangfireDemo", new DashboardOptions(), hangfireDemoStorage); }
public override void PreInitialize() { Configuration.UnitOfWork.Timeout = TimeSpan.FromMinutes(30); Configuration.UnitOfWork.IsTransactional = false; // Disable static mapper usage since it breaks unit tests (see https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2052) Configuration.Modules.AbpAutoMapper().UseStaticMapper = false; Configuration.BackgroundJobs.IsJobExecutionEnabled = false; // mock IWebHostEnvironment IocManager.IocContainer.Register(Component.For <IWebHostEnvironment>().ImplementedBy <TestWebHostEnvironment>().LifestyleSingleton()); var configuration = new Mock <IConfiguration>(); configuration.Setup(c => c.GetSection(It.IsAny <String>())).Returns(new Mock <IConfigurationSection>().Object); IocManager.IocContainer.Register( Component.For <IConfiguration>() .Instance(configuration.Object) .LifestyleSingleton() ); IocManager.Register(typeof(IEntityConfigurationStore), typeof(EntityConfigurationStore), DependencyLifeStyle.Singleton); IocManager.IocContainer.Register( Component.For <IBackgroundJobClient>() .UsingFactoryMethod(() => { var storage = new SqlServerStorage(ConnectionString); JobStorage.Current = storage; return(new BackgroundJobClient(storage)); }) .LifestyleSingleton() ); // Use database for language management Configuration.Modules.Zero().LanguageManagement.EnableDbLocalization(); RegisterFakeService <SheshaDbMigrator>(); Configuration.ReplaceService <IDynamicRepository, DynamicRepository>(DependencyLifeStyle.Transient); // replace email sender Configuration.ReplaceService <IEmailSender, NullEmailSender>(DependencyLifeStyle.Transient); // replace connection string resolver Configuration.ReplaceService <IDbPerTenantConnectionStringResolver, TestConnectionStringResolver>(DependencyLifeStyle.Transient); }
private static IGdprCapability CreateGdprCapability(bool useMock = false) { IStorage storage; if (useMock) { storage = new MemoryStorage(); } else { storage = new SqlServerStorage("Data Source=localhost;Initial Catalog=LeverExampleGdpr;Persist Security Info=True;User ID=LeverExampleGdprUser;Password=Password123!;Pooling=False;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=True"); } return(new Mapper(storage)); }
public void OrdersExtract2() { SqlServerStorage storage = new SqlServerStorage(typeof(OrdersVerticalBar), "NEON-64", "Northwind"); storage.SelectSql = "SELECT TOP 100 * FROM Orders"; storage.FillRecordCallback = new FillRecordHandler(FillRecordOrder); OrdersVerticalBar[] res = (OrdersVerticalBar[])storage.ExtractRecords(); Assert.AreEqual(100, res.Length); Assert.AreEqual("VINET", res[0].CustomerID); Assert.AreEqual("TOMSP", res[1].CustomerID); Assert.AreEqual("HANAR", res[2].CustomerID); }
public static void RegisterJobsWorker(this IKernel kernel) { string connectionstring = "data source=(localdb)\\MSSQLLocalDB;initial catalog=LocalBWorkerDB;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework;"; var sqlStorage = new SqlServerStorage(connectionstring); var options = new BackgroundJobServerOptions { ServerName = "(localdb)\\MSSQLLocalDB" }; JobStorage.Current = sqlStorage; GlobalConfiguration.Configuration.UseSqlServerStorage(connectionstring); //HangFire //GlobalConfiguration.Configuration.UseNinjectActivator(kernel); }
public void OrdersExtractToFile() { var storage = new SqlServerStorage(typeof(OrdersVerticalBar)); storage.ServerName = "NEON-64"; storage.DatabaseName = "Northwind"; storage.SelectSql = "SELECT * FROM Orders"; storage.FillRecordCallback = new FillRecordHandler(FillRecordOrder); try { FileDataLink.EasyExtractToFile(storage, "tempord.txt"); } catch (SqlException ex) { if (ex.Number == 208) { Assert.Ignore("You dont have this tables in your SqlServer"); } if (ex.Number == 6) { Assert.Ignore("SqlServer not found, skipping this test."); } Assert.Ignore(ex.ToString()); } var link = new FileDataLink(storage); link.ExtractToFile("tempord.txt"); var res = CommonEngine.ReadFile(typeof(OrdersVerticalBar), "tempord.txt") as OrdersVerticalBar[]; if (File.Exists("tempord.txt")) { File.Delete("tempord.txt"); } Assert.AreEqual(830, res.Length); Assert.AreEqual("VINET", res[0].CustomerID); Assert.AreEqual("TOMSP", res[1].CustomerID); Assert.AreEqual("HANAR", res[2].CustomerID); }
public virtual void OnAppStartup() { string jobSchedulerDbConnectionString = AppEnvironment.GetConfig <string>("JobSchedulerDbConnectionString"); SqlServerStorage storage = new SqlServerStorage(jobSchedulerDbConnectionString, new SqlServerStorageOptions { PrepareSchemaIfNecessary = false, UseRecommendedIsolationLevel = true, SchemaName = "HangFire", CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), QueuePollInterval = TimeSpan.Zero, UsePageLocksOnDequeue = true, DisableGlobalLocks = true }); // https://docs.hangfire.io/en/latest/configuration/using-sql-server.html#configuration if (AppEnvironment.HasConfig("JobSchedulerAzureServiceBusConnectionString")) { string signalRAzureServiceBusConnectionString = AppEnvironment.GetConfig <string>("JobSchedulerAzureServiceBusConnectionString"); storage.UseServiceBusQueues(signalRAzureServiceBusConnectionString); } JobStorage.Current = storage; GlobalConfiguration.Configuration.UseStorage(storage); GlobalConfiguration.Configuration.UseAutofacActivator(_lifetimeScope); GlobalConfiguration.Configuration.UseLogProvider(LogProvider); if (GlobalJobFilters.Filters.Any(f => f.Instance is AutomaticRetryAttribute)) { GlobalConfiguration.Configuration.UseFilter(new DefaultAutomaticRetryAttribute { }); GlobalJobFilters.Filters.Remove(GlobalJobFilters.Filters.ExtendedSingle("Finding automatic retry job filter attribute to remove it from global job filters", f => f.Instance is AutomaticRetryAttribute).Instance); } BackgroundJobServerOptions options = new BackgroundJobServerOptions { Activator = JobActivator }; foreach (IHangfireOptionsCustomizer customizer in Customizers) { customizer.Customize(GlobalConfiguration.Configuration, options, storage); } _backgroundJobServer = new BackgroundJobServer(options, storage); }
public static IGlobalConfiguration <SqlServerStorage> UseSqlServerStorage( [NotNull] this IGlobalConfiguration configuration, [NotNull] Func <DbConnection> connectionFactory) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (connectionFactory == null) { throw new ArgumentNullException(nameof(connectionFactory)); } var storage = new SqlServerStorage(connectionFactory); return(configuration.UseStorage(storage)); }
/// <summary> /// 设置SqlServer仓库(并指定数据库连接字符串) /// </summary> /// <param name="configuration"></param> /// <param name="nameOrConnectionString"></param> /// <returns></returns> public static IGlobalConfiguration <SqlServerStorage> UseSqlServerStorage( [NotNull] this IGlobalConfiguration configuration, [NotNull] string nameOrConnectionString) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (nameOrConnectionString == null) { throw new ArgumentNullException(nameof(nameOrConnectionString)); } var storage = new SqlServerStorage(nameOrConnectionString); return(configuration.UseStorage(storage)); }
public MAMQSqlServerConnection(SqlServerStorage storage, IEnumerable <string>?queues) { const string sqlServerConnectionTypeName = "Hangfire.SqlServer.SqlServerConnection"; Type? type = typeof(SqlServerStorage) .Assembly .GetType(sqlServerConnectionTypeName); if (type == null) { throw new InvalidOperationException($"{sqlServerConnectionTypeName} has not been loaded into the process."); } var connection = type.Assembly.CreateInstance(type.FullName, false, BindingFlags.Instance | BindingFlags.Public, null, new[] { storage }, null, null) as JobStorageConnection; _sqlServerConnection = connection ?? throw new InvalidOperationException($"Could not create an instance for {sqlServerConnectionTypeName}"); _queues = queues; }
public void InnerDistributedLock_DoesNotConsumeADatabaseConnection() { // Arrange var storage = new SqlServerStorage(ConnectionUtils.GetConnectionString()); // Act using (var outer = new SqlServerDistributedLock(storage, "hello", TimeSpan.FromMinutes(5))) using (var inner = new SqlServerDistributedLock(storage, "hello", TimeSpan.FromMinutes(5))) { // Assert var field = typeof(SqlServerDistributedLock).GetField("_connection", BindingFlags.Instance | BindingFlags.NonPublic); Assert.NotNull(field); Assert.NotNull(field.GetValue(outer)); Assert.Null(field.GetValue(inner)); } }
private static SqlServerJobQueue CreateJobQueue(SqlConnection connection) { var storage = new SqlServerStorage(connection); return new SqlServerJobQueue(storage, new SqlServerStorageOptions()); }
private ExpirationManager CreateManager(SqlConnection connection) { var storage = new SqlServerStorage(connection); return new ExpirationManager(storage, TimeSpan.Zero); }
private static CountersAggregator CreateAggregator(SqlConnection connection) { var storage = new SqlServerStorage(connection); return new CountersAggregator(storage, TimeSpan.Zero); }
private void UseConnections(Action<SqlConnection, SqlServerConnection> action) { using (var sqlConnection = ConnectionUtils.CreateConnection()) { var storage = new SqlServerStorage(sqlConnection); using (var connection = new SqlServerConnection(storage)) { action(sqlConnection, connection); } } }
public ExpirationManager(SqlServerStorage storage) { _storage = storage; }
public ExpirationManagerFacts() { _storage = new SqlServerStorage(ConnectionUtils.GetConnectionString()); _token = new CancellationToken(true); }
public MsmqSqlServerStorageExtensionsFacts() { _storage = new SqlServerStorage( @"Server=.\sqlexpress;Database=TheDatabase;Trusted_Connection=True;", new SqlServerStorageOptions { PrepareSchemaIfNecessary = false }); }