Exemple #1
0
        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;
            }
        }
        // Occurs when the user changes the selection in the historian list box.
        // It saves the selection made by the user for future steps in the setup process.
        private void HistorianAdapterListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            HistorianAdapter adapter = HistorianAdapterListBox.SelectedItem as HistorianAdapter;

            if (adapter != null)
            {
                m_assemblyName = adapter.AssemblyName;
                m_typeName     = adapter.TypeName;

                m_state["historianTypeName"]     = m_typeName;
                m_state["historianAssemblyName"] = m_assemblyName;

                AssemblyInfoTextBox.Content = m_typeName + " from " + m_assemblyName;
            }
        }
        /// <summary>
        /// Creates a new instance of the <see cref="HistorianSetupScreen"/>.
        /// </summary>
        public HistorianSetupScreen()
        {
            m_parametersScreen  = new HistorianConnectionStringScreen();
            m_historianAdapters = new List <HistorianAdapter>();

            // This can fail if user is not running under proper credentials
            try
            {
                foreach (Type type in GetHistorianTypes())
                {
                    m_historianAdapters.Add(new HistorianAdapter(type));
                }
            }
            catch (Exception ex)
            {
                LogFile logger = new LogFile();
                logger.FileName = FilePath.GetAbsolutePath("ErrorLog.txt");
                logger.WriteTimestampedLine(ErrorLogger.GetExceptionInfo(ex, false));
                logger.Dispose();
            }

            if (m_historianAdapters.Count > 0)
            {
                m_defaultAdapter = m_historianAdapters.Find(adapter => adapter.TypeName == "HistorianAdapters.LocalOutputAdapter");

                if (m_defaultAdapter == null)
                {
                    m_defaultAdapter = m_historianAdapters[0];
                }

                m_assemblyName = m_defaultAdapter.AssemblyName;
                m_typeName     = m_defaultAdapter.TypeName;
            }

            if (m_defaultAdapter == null)
            {
                m_assemblyName = FilePath.GetAbsolutePath("HistorianAdapters.dll");
                m_typeName     = "HistorianAdapters.LocalOutputAdapter";
            }

            InitializeComponent();
        }
Exemple #4
0
        /// <summary>
        /// Creates a new instance of the <see cref="HistorianSetupScreen"/>.
        /// </summary>
        public HistorianSetupScreen()
        {
            m_parametersScreen  = new HistorianConnectionStringScreen();
            m_historianAdapters = new List <HistorianAdapter>();

            // This could fail if user is not running under proper credentials
            try
            {
                foreach (Type type in GetHistorianTypes())
                {
                    m_historianAdapters.Add(new HistorianAdapter(type));
                }
            }
            catch (Exception ex)
            {
                ((App)Application.Current).ErrorLogger.Log(ex);
            }

            if (m_historianAdapters.Count > 0)
            {
                m_defaultAdapter = m_historianAdapters.Find(adapter => adapter.TypeName == DefaultType);

                if (m_defaultAdapter == null)
                {
                    m_defaultAdapter = m_historianAdapters[0];
                }

                m_assemblyName = m_defaultAdapter.AssemblyName;
                m_typeName     = m_defaultAdapter.TypeName;
            }

            if (m_defaultAdapter == null)
            {
                m_assemblyName = FilePath.GetAbsolutePath(DefaultAssembly);
                m_typeName     = DefaultType;
            }

            InitializeComponent();
        }
Exemple #5
0
        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;
            }
        }
        /// <summary>
        /// Creates a new instance of the <see cref="HistorianSetupScreen"/>.
        /// </summary>
        public HistorianSetupScreen()
        {
            m_parametersScreen = new HistorianConnectionStringScreen();
            m_historianAdapters = new List<HistorianAdapter>();

            // This can fail if user is not running under proper credentials
            try
            {
                foreach (Type type in GetHistorianTypes())
                {
                    m_historianAdapters.Add(new HistorianAdapter(type));
                }
            }
            catch (Exception ex)
            {
                ((App)Application.Current).ErrorLogger.Log(ex);
            }

            if (m_historianAdapters.Count > 0)
            {
                m_defaultAdapter = m_historianAdapters.Find(adapter => adapter.TypeName == "TestingAdapters.VirtualOutputAdapter");

                if (m_defaultAdapter == null)
                    m_defaultAdapter = m_historianAdapters[0];

                m_assemblyName = m_defaultAdapter.AssemblyName;
                m_typeName = m_defaultAdapter.TypeName;
            }

            if (m_defaultAdapter == null)
            {
                m_assemblyName = FilePath.GetAbsolutePath("TestingAdapters.dll");
                m_typeName = "TestingAdapters.VirtualOutputAdapter";
            }

            InitializeComponent();
        }
        /// <summary>
        /// Creates a new instance of the <see cref="HistorianSetupScreen"/>.
        /// </summary>
        public HistorianSetupScreen()
        {
            m_parametersScreen = new HistorianConnectionStringScreen();
            m_historianAdapters = new List<HistorianAdapter>();

            // This can fail if user is not running under proper credentials
            try
            {
                foreach (Type type in GetHistorianTypes())
                {
                    m_historianAdapters.Add(new HistorianAdapter(type));
                }
            }
            catch (Exception ex)
            {
                LogFile logger = new LogFile();
                logger.FileName = FilePath.GetAbsolutePath("ErrorLog.txt");
                logger.WriteTimestampedLine(ErrorLogger.GetExceptionInfo(ex, false));
                logger.Dispose();
            }

            if (m_historianAdapters.Count > 0)
            {
                m_defaultAdapter = m_historianAdapters.Find(adapter => adapter.TypeName == "HistorianAdapters.LocalOutputAdapter");

                if (m_defaultAdapter == null)
                    m_defaultAdapter = m_historianAdapters[0];

                m_assemblyName = m_defaultAdapter.AssemblyName;
                m_typeName = m_defaultAdapter.TypeName;
            }

            if (m_defaultAdapter == null)
            {
                m_assemblyName = FilePath.GetAbsolutePath("HistorianAdapters.dll");
                m_typeName = "HistorianAdapters.LocalOutputAdapter";
            }

            InitializeComponent();
        }