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 Should_call_insert_method() { // Arrange var mockHistAdapter = new Mock <IHistorianAdapter>(); var dbReporter = new DbReporter(mockHistAdapter.Object, new Dictionary <string, IList <double> >()); // Act dbReporter.Save(); // Assert mockHistAdapter.Verify(x => x.InsertTagValues(It.IsAny <IDictionary <string, IList <double> > >()), Times.Once); }
public void Should_add_new_key_to_dictionary() { // Arrange var mockHistAdapter = new Mock <IHistorianAdapter>(); var mockDictionary = new Mock <IDictionary <string, IList <double> > >(); var dbReporter = new DbReporter(mockHistAdapter.Object, mockDictionary.Object); var keys = new[] { "asd", "dfg" }; // Act foreach (var s in keys) { dbReporter[s] = 0.1; } // Assert mockDictionary.Verify(x => x.Add(It.IsAny <string>(), It.IsAny <IList <double> >()), Times.Exactly(keys.Length)); }
public void Should_not_add_new_key_to_dictionary() { // Arrange var mockHistAdapter = new Mock <IHistorianAdapter>(); var mockDictionary = new Mock <IDictionary <string, IList <double> > >(); var dbReporter = new DbReporter(mockHistAdapter.Object, mockDictionary.Object); IList <double> list = new List <double>(); mockDictionary .Setup(x => x.TryGetValue(It.Is <string>(s => s == "asd"), out list)) .Returns(true); // Act dbReporter["asd"] = 1.2; dbReporter["asd"] = 1.2; // Assert mockDictionary.Verify(x => x.Add(It.IsAny <string>(), It.IsAny <IList <double> >()), Times.Never); }
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; } }