Ejemplo n.º 1
0
        public void Init()
        {
            _storageEngine = new Mock<IStorageEngine>();

            var bootstrapper = new OverlookBootStrapper(_storageEngine.Object);
            _browser = new Browser(bootstrapper);
        }
Ejemplo n.º 2
0
        private void ProcessMetricRequests()
        {
            _logger.Debug("Beginning to process metric requests");

            var storageEngine = new SqliteStorageEngine(ApplicationSettings.DatabaseName);

            // Start the webserver
            _logger.Debug("Beginning webserver on port {0}", _webPortNumber);
            var bootstrapper = new OverlookBootStrapper(storageEngine);
            var uri = new Uri("http://localhost:" + _webPortNumber);
            var webServer = new NancyHost(uri, bootstrapper);
            webServer.Start();
            _logger.Debug("Web server started");

            var retrievers = new IMetricRetriever[]
            {
                new OpenProcessMetricRetriever(),
                new OpenHardwareMonitorMetricRetriever()
            };

            UpdateDisplays(storageEngine);

            var lastSnapshotTime = DateTime.MinValue;
            var secondsBetweenChecks = ApplicationSettings.SecondsBetweenSnapshots;
            while (!_cancellationTokenSource.Token.IsCancellationRequested)
            {
                if ((DateTime.Now - lastSnapshotTime).TotalSeconds > secondsBetweenChecks)
                {
                    _logger.Debug("Generating snapshot");

                    var snapshot = new Snapshot
                    {
                        Date = DateTime.Now,
                        MetricValues = retrievers.SelectMany(x => x.GetCurrentMetricValues())
                                                 .ToArray()
                    };

                    _logger.Debug("Storing Snapshot");
                    storageEngine.StoreSnapshot(snapshot);
                    _logger.Debug("Snapshot stored");

                    UpdateDisplays(storageEngine);
                    lastSnapshotTime = DateTime.Now;
                }
                else
                {
                    Thread.Sleep(100);
                }
            }

            _logger.Debug("Stopping webserver");
            webServer.Stop();
            _logger.Debug("Webserver stopped");
        }