private void Error(object sender, ErrorEventArgs e) { DependencyError = e; tableDependency.Stop(); tableDependency.OnChanged -= Changed; tableDependency.OnChanged += Changed; tableDependency.Start(); }
public void start() { if (dependency.Status != TableDependencyStatus.Started || dependency.Status != TableDependencyStatus.Starting) { dependency.OnChanged += change; dependency.Start(); } else { dependency.Stop(); dependency.OnChanged += change; dependency.Start(); } }
public void TaskCancellationTest() { string naming = null; SqlTableDependency <TaskCancellationTestSqlServerModel> tableDependency = null; try { var mapper = new ModelToTableMapper <TaskCancellationTestSqlServerModel>(); mapper.AddMapping(c => c.Name, "First Name").AddMapping(c => c.Surname, "Second Name"); tableDependency = new SqlTableDependency <TaskCancellationTestSqlServerModel>(ConnectionStringForTestUser, TableName, mapper); tableDependency.OnChanged += TableDependency_Changed; tableDependency.Start(); naming = tableDependency.DataBaseObjectsNamingConvention; Thread.Sleep(5000); tableDependency.Stop(); Thread.Sleep(5000); } catch { tableDependency?.Dispose(); } Assert.IsTrue(base.AreAllDbObjectDisposed(naming)); Assert.IsTrue(base.CountConversationEndpoints(naming) == 0); }
static void Main(string[] args) { // Create a dependency connection. //Don't forget to enable service broker ALTER DATABASE the_db SET ENABLE_BROKER; SqlFieldDependency <UnStatut, string> sqlDependency = new SqlFieldDependency <UnStatut, string>(p => p.Name == "Code", Properties.Settings.Default.DB_Conn_String, receiveDetails: true, identity: Guid.NewGuid()); SqlTableDependency <UnStatut> sqlTableDependency = new SqlTableDependency <UnStatut>(Properties.Settings.Default.DB_Conn_String, receiveDetails: true, identity: Guid.NewGuid()); sqlTableDependency.ValueChanged += SqlDependency_TableChanged; sqlDependency.ValueChanged += SqlDependency_ValueChanged; sqlDependency.Start(); sqlTableDependency.Start(); DebugMode(); do { Thread.Sleep(100); } while (Console.ReadLine().ToLower() != "x"); Console.WriteLine("stopping..."); sqlDependency.Stop(); sqlTableDependency.Stop(); //Console.WriteLine(ExtendedSqlDependency.GetDependencyDbIdentities(Properties.Settings.Default.DB_Conn_String)); ExtendedSqlDependency.CleanDatabase(Properties.Settings.Default.DB_Conn_String); Console.WriteLine("Stopped..."); Console.ReadLine(); }
public void Test() { bool startReceivingMessages = false; var tableDependency = new SqlTableDependency <EndpointsStatusModel>(ConnectionStringForTestUser, includeOldValues: true); tableDependency.OnChanged += (o, args) => { startReceivingMessages = true; }; tableDependency.Start(); var naming = tableDependency.DataBaseObjectsNamingConvention; Assert.IsTrue(this.IsSenderEndpointInStatus(naming, ConversationEndpointState.SO)); Assert.IsTrue(this.IsReceiverEndpointInStatus(naming, null)); var t = new Task(InsertRecord); t.Start(); while (startReceivingMessages == false) { Thread.Sleep(1000 * 1 * 1); } Assert.IsTrue(this.IsSenderEndpointInStatus(naming, ConversationEndpointState.CO)); Assert.IsTrue(this.IsReceiverEndpointInStatus(naming, ConversationEndpointState.CO)); tableDependency.Stop(); Thread.Sleep(1000 * 30 * 1); Assert.IsTrue(base.AreAllDbObjectDisposed(naming)); Assert.IsTrue(base.CountConversationEndpoints(naming) == 0); }
private void UsersForm_FormClosing(object sender, FormClosingEventArgs e) { userDependency.Stop(); roleUserDependency.Stop(); userDependency.OnChanged += null; roleUserDependency.OnChanged += null; }
public void Dispose() { Log.Information($"RecordChangeNotificationService Stop: {DateTime.Now}"); _notifier.Stop(); Log.Information($"RecordChangeNotificationService Dispose: {DateTime.Now}"); _notifier.Dispose(); }
public void TestInsertAfterStop() { var mapper = new ModelToTableMapper <DatabaseObjectCleanUpTestSqlServerModel>(); mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name"); var tableDependency = new SqlTableDependency <DatabaseObjectCleanUpTestSqlServerModel>( ConnectionStringForTestUser, includeOldValues: true, tableName: TableName, mapper: mapper); tableDependency.OnChanged += (sender, e) => { }; tableDependency.Start(); var dbObjectsNaming = tableDependency.DataBaseObjectsNamingConvention; var t = new Task(BigModifyTableContent); t.Start(); Thread.Sleep(1000 * 15 * 1); tableDependency.Stop(); SmalModifyTableContent(); Thread.Sleep(1 * 15 * 1000); Assert.IsTrue(base.AreAllDbObjectDisposed(dbObjectsNaming)); Assert.IsTrue(base.CountConversationEndpoints(dbObjectsNaming) == 0); }
private static void Setup() { var mapper = new ModelToTableMapper <Customer>(); mapper.AddMapping(c => c.Surname, "LastName"); mapper.AddMapping(c => c.Name, "FirstName"); using (var dep = new SqlTableDependency <Customer>(_con, "Customer", mapper: mapper)) { dep.OnChanged += (s, e) => { Customer customer = e.Entity; Console.WriteLine("DML Op: {0}", e.ChangeType); Console.WriteLine("ID: {0}", customer.Id); Console.WriteLine("First Name: {0}", customer.Name); Console.WriteLine("Last Name: {0}", customer.Surname); customerQue.Enqueue(customer); }; dep.Start(); Timer timer = new Timer((arg) => { ProcessData(); }, null, 0, 5000); Console.WriteLine("Press a key to exit"); Console.ReadKey(); dep.Stop(); } }
public void TestStopWhileStillInserting() { SqlTableDependency <DatabaseObjectCleanUpTestSqlServerModel> tableDependency = new SqlTableDependency <DatabaseObjectCleanUpTestSqlServerModel>( ConnectionStringForTestUser, tableName: TableName); string objectNaming = tableDependency.DataBaseObjectsNamingConvention; tableDependency.OnChanged += (sender, e) => { }; objectNaming = tableDependency.DataBaseObjectsNamingConvention; tableDependency.Start(); Thread.Sleep(1000); // Run async tasks insering 1000 rows in table every 250 milliseconds var task1 = Task.Factory.StartNew(() => ModifyTableContent()); var task2 = Task.Factory.StartNew(() => ModifyTableContent()); var task3 = Task.Factory.StartNew(() => ModifyTableContent()); Thread.Sleep(5000); tableDependency.Stop(); Thread.Sleep(5000); Assert.IsTrue(base.AreAllDbObjectDisposed(objectNaming)); Assert.IsTrue(base.CountConversationEndpoints(objectNaming) == 0); }
public void DatabaseObjectCleanUpTest() { var mapper = new ModelToTableMapper <EventForAllColumnsTestSqlServerModel>(); mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name"); var tableDependency = new SqlTableDependency <EventForAllColumnsTestSqlServerModel>(ConnectionStringForTestUser, TableName, mapper); tableDependency.OnChanged += TableDependency_OnChanged; tableDependency.Start(); DbObjectsNaming = tableDependency.DataBaseObjectsNamingConvention; Thread.Sleep(50); var t = new Task(BigModifyTableContent); t.Start(); Thread.Sleep(1000 * 10 * 1); Thread.Sleep(1000 * 30 * 1); tableDependency.Stop(); SmalModifyTableContent(); Thread.Sleep(4 * 60 * 1000); Assert.IsTrue(base.AreAllDbObjectDisposed(DbObjectsNaming)); Assert.IsTrue(base.CountConversationEndpoints(DbObjectsNaming) == 0); }
public static void Main() { // The mapper object is used to map model properties // that do not have a corresponding table column name. // In case all properties of your model have same name // of table columns, you can avoid to use the mapper. var mapper = new ModelToTableMapper <Customer>(); mapper.AddMapping(c => c.Surname, "Surname"); mapper.AddMapping(c => c.Name, "Name"); // Here - as second parameter - we pass table name: // this is necessary only if the model name is different from table name // (in our case we have Customer vs Customers). // If needed, you can also specifiy schema name. using (var dep = new SqlTableDependency <Customer>( connectionString: _con, tableName: "Customers", mapper: mapper, executeUserPermissionCheck: false)) { dep.OnChanged += Changed; dep.Start(); string x = Console.ReadLine(); Console.WriteLine("Press a key to exit"); Console.ReadKey(); if (x == "c") { dep.Stop(); } } }
public void Test() { SqlTableDependency <StopAndStartTestModel> tableDependency = null; string naming; try { tableDependency = new SqlTableDependency <StopAndStartTestModel>(ConnectionStringForTestUser, tableName: TableName); tableDependency.OnChanged += TableDependency_Changed; tableDependency.Start(); Thread.Sleep(1000 * 15 * 1); tableDependency.Stop(); Thread.Sleep(1000 * 10 * 1); tableDependency.Start(); naming = tableDependency.DataBaseObjectsNamingConvention; var t = new Task(ModifyTableContent); t.Start(); Thread.Sleep(1000 * 15 * 1); } finally { tableDependency?.Dispose(); } Assert.AreEqual(_counter, 3); Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.Name, _checkValues[ChangeType.Insert.ToString()].Item1.Name); Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.Name, _checkValues[ChangeType.Update.ToString()].Item1.Name); Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.Name, _checkValues[ChangeType.Delete.ToString()].Item1.Name); Assert.IsTrue(base.AreAllDbObjectDisposed(naming)); Assert.IsTrue(base.CountConversationEndpoints(naming) == 0); }
private static int counter = 1; // For debug to check whether the interval is running // The constructor initializes the database connections and adds column mappings if any public SQLServerStream() { /** * No need to do mappings since model class properties exactly match the db column names. If otherwise then need to * var mapper = new ModelToTableMapper<Customer>(); * mapper.AddMapping(c => c.Surname, "Second Name"); * mapper.AddMapping(c => c.Name, "First Name"); **/ using (var dep = new SqlTableDependency <ModelProcessedHistory>(Globals.DBConnectionString, Globals.DBTableName)) { dep.OnChanged += Changed; dep.Start(); Console.WriteLine("Press a key to exit"); #if DEBUG // Need to use this in debug mode to read user input keys to either quit, pause or resume service // In other location, the program is kept alive by infite loop if key is not either if Q, P or R // In Progaram.Main(), ConsoleHarness.Run() is called for every input key which in turn determines whether // the service should (P)ause, (R)esume or (Stop) OR keep running infinitely for any other key that isn't // in this set. Makes the service easy to debug Console.ReadKey(); #else // We don't really need Console.ReadKey(); here since the console input isn't important // Just need to put the service in infinite loop waiting for user input thus keeping it alive Thread.Sleep(Timeout.Infinite); #endif dep.Stop(); } }
protected void Dispose(bool dispose) { if (dispose) { _dependency.Stop(); _dependency.Dispose(); } }
public SqlMonitor(string tableName, Expression <Func <T, bool> > filter = null, DmlTriggerType monitorType = DmlTriggerType.All) { tableDependency = new SqlTableDependency <T>(ConnectionStringInfo.Get(), tableName, filter: new SqlTableDependencyFilter <T>(filter), notifyOn: monitorType); tableDependency.Stop(); tableDependency.OnChanged += Changed; tableDependency.OnError += Error; tableDependency.Start(); }
public static void Dispose() { deBook.Stop(); deGenre.Stop(); deReader.Stop(); deStaff.Stop(); deAccount.Stop(); deReceipt.Stop(); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { _tableDependency.Stop(); } disposedValue = true; } }
private void BookForm_FormClosing(object sender, FormClosingEventArgs e) { bookDependency.Stop(); genreDependency.Stop(); writerDependency.Stop(); publishingDependency.Stop(); bookDependency.OnChanged += null; genreDependency.OnChanged += null; writerDependency.OnChanged += null; publishingDependency.OnChanged += null; }
protected void Button1_Click(object sender, EventArgs e) { using (var tableDepend = new SqlTableDependency <SqlNotify>(ConfigurationManager.ConnectionStrings["AsmsGenericMaster"].ConnectionString, "tblARInvoices")) { tableDepend.OnChanged += TableDependency_Changed; tableDepend.OnError += TableDependency_OnError; tableDepend.Stop(); tableDepend.Start(); } }
public void Tracker() { using (var tableDependency = new SqlTableDependency <StudentEnrollments>(ConfigurationManager.ConnectionStrings["DBString"].ConnectionString, includeOldValues: true)) { tableDependency.OnChanged += TableDependency_Changed; tableDependency.Start(); Console.WriteLine("Waiting for receiving notifications..."); Console.WriteLine("Press a key to stop"); Console.ReadKey(); tableDependency.Stop(); } }
public void TeardownTests() { SqlTableDependency <TeardownTestSqlserver5Model> tableDependency = null; string dataBaseObjectsNamingConvention = null; var mapper = new ModelToTableMapper <TeardownTestSqlserver5Model>(); mapper.AddMapping(c => c.Description, "Long Description"); //////////////////////////////////////////////////////// // First Round //////////////////////////////////////////////////////// try { tableDependency = new SqlTableDependency <TeardownTestSqlserver5Model>(ConnectionString, mapper: mapper, teardown: false); tableDependency.OnChanged += TableDependency_Changed; tableDependency.Start(); dataBaseObjectsNamingConvention = tableDependency.DataBaseObjectsNamingConvention; Thread.Sleep(5000); } finally { tableDependency?.Dispose(); } Thread.Sleep(5000); //////////////////////////////////////////////////////// // Inserd data while sql table dependency is not running //////////////////////////////////////////////////////// ModifyTableContent(); //////////////////////////////////////////////////////// // Second Round //////////////////////////////////////////////////////// tableDependency = new SqlTableDependency <TeardownTestSqlserver5Model>(ConnectionString, mapper: mapper, teardown: true, namingForObjectsAlreadyExisting: dataBaseObjectsNamingConvention); tableDependency.OnChanged += TableDependency_Changed; tableDependency.Start(); Thread.Sleep(5000); tableDependency.Stop(); Thread.Sleep(3 * 60 * 1000); Assert.AreEqual(_counter, 1000); Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(ConnectionString, dataBaseObjectsNamingConvention)); }
static void TableDependency() { // Exchange var exchange = "topic_logqueue"; // Producer using var producer = new RabbitMQEx(factory); producer.PrepareProduce(exchange, durable: true); producer.ProduceConfirm((deliveryTag, multiple, success) => { Console.WriteLine($"Message acknowledged at {DateTime.UtcNow:ss:fff} for {deliveryTag}: {success}"); return(Task.CompletedTask); }); // Consumer using var consumer = new RabbitMQEx(factory); consumer.PrepareConsume((body, routingKey, redelivered) => { var message = Encoding.UTF8.GetString(body.ToArray()); Console.WriteLine($"Message received at {DateTime.UtcNow:ss:fff} from {routingKey} : {message}"); return(Task.FromResult(true)); }, exchange, routingKey: "system.test", durable: true, autoAck: false); // Definition, Insert change only using var dep = new SqlTableDependency <LogQueue>(connectionString, "SysLogQueue", notifyOn: DmlTriggerType.Insert); // Change callback dep.OnChanged += (object sender, RecordChangedEventArgs <LogQueue> e) => { var entity = e.Entity; Console.WriteLine("--------------------"); Console.WriteLine($"Change received at {DateTime.UtcNow:ss:fff}, happened at {entity.Creation:ss:fff}"); Console.WriteLine($"Data: {entity.Data}"); // Body var body = entity.Data == null?Array.Empty <byte>() : Encoding.UTF8.GetBytes(entity.Data); // Produce producer.Produce(body, exchange, "system.test", true); Console.WriteLine("Message pushed..."); }; // Start dep.Start(); // Tip Console.WriteLine("Service is running. Press a key to exit"); Console.ReadKey(); // Stop dep.Stop(); }
public override void PauseChangeMonitoring() { _schedMonitor.Stop(); _demandMonitor.Stop(); _requestGroupDefMonitor.Stop(); _dataPointDefMonitor.Stop(); _connectionDefMonitor.Stop(); _deviceDefMonitor.Stop(); _taskDefMonitor.Stop(); _subscriptionMonitor.Stop(); Globals.SystemManager.LogApplicationEvent(this, "", "Database change monitoring stopped"); }
private bool _disposedValue; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _clients.All.ended(); _tableDependency.Stop(); } _disposedValue = true; } }
public Task StopAsync(CancellationToken token = default) { if (_clanGameLogDependency != null) { _logger.LogInformation("Stopping the Clan War Notification service"); _clanGameLogDependency.Stop(); _clanGameLogDependency.Dispose(); _clanGameLogDependency = null; } return(Task.CompletedTask); }
public static void Main() { using (var dep = new SqlTableDependency <HaftalikPlan>(_con, "HaftalikYuklemePlan", "Operasyon")) { dep.OnChanged += Changed; dep.Start(); Console.WriteLine("Press a key to exit"); Console.ReadKey(); dep.Stop(); } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing && sqlTableDependency != null) { sqlTableDependency.Stop(); sqlTableDependency.Dispose(); } disposedValue = true; } }
public SqlTableDependencyConfigurator(ElasticClient elasticClient) { _elasticClient = elasticClient; using (var sqlDependency = new SqlTableDependency <Product>(_connectionString, "Products")) { sqlDependency.OnChanged += Changed; sqlDependency.Start(); Thread.Sleep(50000); sqlDependency.Stop(); } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { _likesTableDependency.Stop(); _friendRequestsTableDependency.Stop(); _postsTableDependency.Stop(); } disposedValue = true; } }