protected override void OnStart(string[] args) { Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); _logger.Trace("File version: {0}", fileVersionInfo.FileVersion); _logger.Trace("Assembly version: {0}", assembly.GetName().Version); string historianConnection; string pdgtmConnectionString; string settingsConnectionString; try { historianConnection = ConfigurationManager.ConnectionStrings["HistorianConnection"].ConnectionString; pdgtmConnectionString = ConfigurationManager.ConnectionStrings["TeamworkConnection"].ConnectionString; settingsConnectionString = ConfigurationManager.ConnectionStrings["SettingsDb"].ConnectionString; _logger.Trace("Database connection strings loaded successfully"); } catch (Exception ex) { _logger.Fatal("Fail to load connection strings", ex); throw; } try { ISettingsManager settingsManager = new SettingsManager(settingsConnectionString); IPdgtmDbAdapter pdgtmDbAdapter = new PdgtmDbAdapter(pdgtmConnectionString); IHistorianAdapter historianAdapter = new HistorianAdapter(historianConnection); IDatabaseObserver databaseObserver = new DatabaseObserver(historianConnection, pdgtmConnectionString); IReporter reporter = new DbReporter(historianAdapter); IEmulator emulator = new Emulator(reporter); IReplicator replicator = new Replicator(pdgtmDbAdapter, historianAdapter); var wellEmulator = new WellEmulator( emulator, replicator, pdgtmDbAdapter, historianAdapter, settingsManager, databaseObserver); if (_serviceHost != null) { _serviceHost.Close(); _serviceHost = null; } _serviceHost = new ServiceHost(wellEmulator); var behavior = _serviceHost.Description.Behaviors.Find <ServiceBehaviorAttribute>(); behavior.InstanceContextMode = InstanceContextMode.Single; _serviceHost.Open(); _logger.Trace("Service started!"); } catch (Exception ex) { _logger.Fatal("Service failed with fatal error! See stack trace.", ex); throw; } }
public void TestMultiDbObserver() { RunTestVariants(() => { _dbObserver = Native.c4dbobs_create(Db, DBObserverCallback, this); CreateRev("A", C4Slice.Constant("1-aa"), Body); _dbCallbackCalls.Should().Be(1, "because we should have received a callback"); CreateRev("B", C4Slice.Constant("1-bb"), Body); _dbCallbackCalls.Should().Be(1, "because we should have received a callback"); CheckChanges(new[] { "A", "B" }, new[] { "1-aa", "1-bb" }); // Open another database on the same file var otherdb = (C4Database *)LiteCoreBridge.Check(err => Native.c4db_open(DatabasePath(), Native.c4db_getConfig(Db), err)); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(otherdb, err)); try { CreateRev(otherdb, "C", C4Slice.Constant("1-cc"), Body); CreateRev(otherdb, "D", C4Slice.Constant("1-dd"), Body); CreateRev(otherdb, "E", C4Slice.Constant("1-ee"), Body); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(otherdb, true, err)); } _dbCallbackCalls.Should().Be(2, "because the observer should cover all connections"); CheckChanges(new[] { "C", "D", "E" }, new[] { "1-cc", "1-dd", "1-ee" }, true); _dbObserver.Dispose(); _dbObserver = null; CreateRev("A", C4Slice.Constant("2-aaaa"), Body); _dbCallbackCalls.Should().Be(2, "because the observer was disposed"); LiteCoreBridge.Check(err => Native.c4db_close(otherdb, err)); Native.c4db_free(otherdb); }); }
public void Initialization() { Database database = new Database(); DatabaseObserver observer = new DatabaseObserver(database); FingerprintScanner fingerprint = new FingerprintScanner(database); Task.Run(() => database.onDatabaseConnection()); Task.Run(() => fingerprint.Acid()); }
protected override void TeardownVariant(int option) { _dbObserver?.Dispose(); _dbObserver = null; _docObserver?.Dispose(); _docObserver = null; base.TeardownVariant(option); }
/// <summary> /// Deletes the database /// </summary> public void Delete() { ThreadSafety.DoLocked(() => { CheckOpen(); ThrowIfActiveItems(); LiteCoreBridge.Check(err => Native.c4db_delete(_c4db, err)); Native.c4db_free(_c4db); _c4db = null; _obs?.Dispose(); _obs = null; }); }
private void Open() { if (_c4db != null) { return; } Directory.CreateDirectory(Config.Directory); var path = DatabasePath(Name, Config.Directory); var config = DBConfig; var encrypted = ""; #if COUCHBASE_ENTERPRISE if (Config.EncryptionKey != null) { var key = Config.EncryptionKey; var i = 0; config.encryptionKey.algorithm = C4EncryptionAlgorithm.AES256; foreach (var b in key.KeyData) { config.encryptionKey.bytes[i++] = b; } encrypted = "encrypted "; } #endif Log.To.Database.I(Tag, $"Opening {encrypted}database at {path}"); var localConfig1 = config; ThreadSafety.DoLocked(() => { _c4db = (C4Database *)NativeHandler.Create() .AllowError((int)C4ErrorCode.NotADatabaseFile, C4ErrorDomain.LiteCoreDomain).Execute(err => { var localConfig2 = localConfig1; return(Native.c4db_open(path, &localConfig2, err)); }); if (_c4db == null) { throw new CouchbaseLiteException(StatusCode.Unauthorized); } _obs = Native.c4dbobs_create(_c4db, _DbObserverCallback, this); }); }
public void Should_raise_event_after_insert() { // Arrange var connStr = @"Data Source=.\SQLEXPRESS;Initial Catalog=Runtime_Test;Integrated Security=true;"; var mock = new Mock <IStub>(); var observer = new DatabaseObserver(); observer.StartObserverOn(connStr); observer.Observe(@"SELECT [Id], [Name] FROM [Runtime_Test].[dbo].[Well]", connStr, mock.Object.Do); // Act using (var connection = new SqlConnection(connStr)) { connection.Open(); using (var command = new SqlCommand(@"INSERT INTO [Runtime_Test].[dbo].[Well] ([Name]) VALUES ('Name1');", connection)) { command.ExecuteNonQuery(); } } // Assert mock.Verify(x => x.Do(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Once); }
public void TestDBObserver() { RunTestVariants(() => { _dbObserver = Native.c4dbobs_create(Db, DBObserverCallback, this); CreateRev("A", C4Slice.Constant("1-aa"), Body); _dbCallbackCalls.Should().Be(1, "because we should have received a callback"); CreateRev("B", C4Slice.Constant("1-bb"), Body); _dbCallbackCalls.Should().Be(1, "because we should have received a callback"); CheckChanges(new[] { "A", "B" }, new[] { "1-aa", "1-bb" }); CreateRev("B", C4Slice.Constant("2-bbbb"), Body); _dbCallbackCalls.Should().Be(2, "because we should have received a callback"); CreateRev("C", C4Slice.Constant("1-cc"), Body); _dbCallbackCalls.Should().Be(2, "because we should have received a callback"); CheckChanges(new[] { "B", "C" }, new[] { "2-bbbb", "1-cc" }); _dbObserver.Dispose(); _dbObserver = null; CreateRev("A", C4Slice.Constant("2-aaaa"), Body); _dbCallbackCalls.Should().Be(2, "because the observer was disposed"); }); }
private void Run() { string historianConnection; string pdgtmConnectionString; string settingsConnectionString; try { historianConnection = ConfigurationManager.ConnectionStrings["HistorianConnection"].ConnectionString; pdgtmConnectionString = ConfigurationManager.ConnectionStrings["TeamworkConnection"].ConnectionString; settingsConnectionString = ConfigurationManager.ConnectionStrings["SettingsDb"].ConnectionString; } catch (Exception ex) { _logger.Fatal("Can not load connection strings", ex); throw; } try { ISettingsManager settingsManager = new SettingsManager(settingsConnectionString); IPdgtmDbAdapter pdgtmDbAdapter = new PdgtmDbAdapter(pdgtmConnectionString); IHistorianAdapter historianAdapter = new HistorianAdapter(historianConnection); IDatabaseObserver databaseObserver = new DatabaseObserver(historianConnection, pdgtmConnectionString); IReporter reporter = new DbReporter(historianAdapter); IEmulator emulator = new Emulator(reporter); IReplicator replicator = new Replicator(pdgtmDbAdapter, historianAdapter); var wellEmulator = new WellEmulator( emulator, replicator, pdgtmDbAdapter, historianAdapter, settingsManager, databaseObserver); _serviceHost = new ServiceHost(wellEmulator); var behavior = _serviceHost.Description.Behaviors.Find <ServiceBehaviorAttribute>(); behavior.InstanceContextMode = InstanceContextMode.Single; _serviceHost.Open(); _serviceHost.Faulted += OnFault; _logger.Trace("Service started!"); System.Console.WriteLine("The service is ready."); System.Console.WriteLine("Press the Enter key to terminate service."); System.Console.ReadLine(); _logger.Trace("Service stopped."); } catch (CommunicationObjectFaultedException ex) { _logger.Fatal("Restart with administrator rights.", ex); System.Console.WriteLine(ex.ToString()); System.Console.WriteLine(); System.Console.WriteLine("Restart with administrator rights."); System.Console.ReadLine(); } catch (Exception ex) { _logger.Fatal("Service loading failed.", ex); throw; } }
private void Attach(DatabaseObserver observer) { observers.Add(observer); }