Beispiel #1
0
        public AudioViewEngine(TimeSpan minorInterval, TimeSpan majorInterval, IMeterReader reader)
        {
            logger.Info("Started engine with major: {0} minor: {1}", majorInterval, minorInterval);
            reader.SetMinorInterval(minorInterval);
            reader.SetMajorInterval(majorInterval);

            this.listeners = new List <IMeterListener>();
            this.reader    = reader;
            this.reader.SetEngine(this);
            this.minorInterval = minorInterval;
            this.majorInterval = majorInterval;

            this.reader.ConnectionStatusEvent += connected =>
            {
                if (ConnectionStatusEvent != null)
                {
                    ConnectionStatusEvent(connected);
                }
            };

            if (!reader.IsTriggerMode())
            {
                this.secondTimer          = new Timer(new TimeSpan(0, 0, 1).TotalMilliseconds);
                this.secondTimer.Elapsed += OnSecond;

                minorIntervalTimer = new IntervalTimer(minorInterval);
                majorIntervalTimer = new IntervalTimer(majorInterval);
            }
        }
Beispiel #2
0
        public void Stop()
        {
            logger.Debug("Stopping the engine.");
            if (this.secondTimer != null)
            {
                this.secondTimer.Enabled = false;
            }
            if (this.minorIntervalTimer != null)
            {
                this.minorIntervalTimer.Stop();
            }
            if (this.majorIntervalTimer != null)
            {
                this.majorIntervalTimer.Stop();
            }

            if (reader != null)
            {
                reader.Close();
            }

            this.secondTimer        = null;
            this.minorIntervalTimer = null;
            this.majorIntervalTimer = null;
            this.reader             = null;
        }
        public AudioViewEngine(TimeSpan minorInterval, TimeSpan majorInterval, IMeterReader reader)
        {
            logger.Info("Started engine with major: {0} minor: {1}", majorInterval, minorInterval);
            reader.SetMinorInterval(minorInterval);
            reader.SetMajorInterval(majorInterval);

            this.listeners = new List<IMeterListener>();
            this.reader = reader;
            this.reader.SetEngine(this);
            this.minorInterval = minorInterval;
            this.majorInterval = majorInterval;

            this.reader.ConnectionStatusEvent += connected =>
            {
                if (ConnectionStatusEvent != null)
                {
                    ConnectionStatusEvent(connected);
                }
            };

            if (!reader.IsTriggerMode())
            {
                this.secondTimer = new Timer(new TimeSpan(0, 0, 1).TotalMilliseconds);
                this.secondTimer.Elapsed += OnSecond;

                this.minorTimer = new Timer(minorInterval.TotalMilliseconds);
                this.minorTimer.Elapsed += OnMinorInterval;
                
                this.majorTimer = new Timer(majorInterval.TotalMilliseconds);
                this.majorTimer.Elapsed += OnMajorInterval;
            }
        }
Beispiel #4
0
        public MeterWorker(ILogger <MeterWorker> logger, IMeterReader meterReader, IOptions <ConfigSettings> config)
        {
            _logger      = logger;
            _meterReader = meterReader;
            _config      = config.Value;

            // Retrieve storage account information from connection string.
            _storageTableHelper = new StorageTableHelper(_config.StorageConnectionstring);
        }
        public MeasurementViewModel(Guid id, MeasurementSettings settings, IMeterReader reader)
        {
            MinorReadings = new ConcurrentQueue<Tuple<DateTime, ReadingData>>();
            MajorReadings = new ConcurrentQueue<Tuple<DateTime, ReadingData>>();
            BarMajorValues = new ObservableCollection<Tuple<DateTime, double>>();
            BarMinorValues = new ObservableCollection<Tuple<DateTime, double>>();
            LineValues = new ObservableCollection<Tuple<DateTime, double>>();
            OctaveValues = new ObservableCollection<double>();
            MinorSpan = TimeSpan.FromTicks(settings.MinorInterval.Ticks * 15);
            MajorSpan = TimeSpan.FromTicks(settings.MajorInterval.Ticks * 15);


            started = DateTime.Now;
            popOutWindows = new LinkedList<MetroWindow>();
            this.engine = new AudioViewEngine(settings.MinorInterval, settings.MajorInterval, reader);
            this.settings = settings;

            this.engine.ConnectionStatusEvent += connected =>
            {
                if(ConnectionStatus == connected)
                    return; // No need

                Task.Run(() =>
                {
                    ConnectionStatus = connected;
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        OnPropertyChanged(nameof(IsDisconnected));
                    });
                });
            };
            
            if (settings.IsLocal)
            {
                // Registering the TCP Server for remote connections
                tcpServer = new TCPServerListener(settings);
                this.engine.RegisterListener(tcpServer);

                // Register the data storange unit
                dataStorage = new DataStorageMeterListener(id, DateTime.Now, settings);
                this.engine.RegisterListener(dataStorage);
            }

            this.engine.RegisterListener(this);
            this.engine.EngineStartDelayedEvent += (waitTime) =>
            {
                MinorClock = new AudioViewCountDownViewModel(false,
                        settings.MinorInterval,
                        settings.MinorDBLimit,
                        settings.MinorClockMainItemId,
                        settings.MinorClockSecondaryItemId);
                MajorClock = new AudioViewCountDownViewModel(true,
                        settings.MajorInterval,
                        settings.MajorDBLimit,
                        settings.MajorClockMainItemId,
                        settings.MajorClockSecondaryItemId);
                MinorClock.NextMinor(DateTime.Now + waitTime);
                MinorClock.NextMajor(DateTime.Now + waitTime);
                MajorClock.NextMinor(DateTime.Now + waitTime);
                MajorClock.NextMajor(DateTime.Now + waitTime);
            };
            this.engine.EngineStartedEvent += () =>
            {
                this.engine.RegisterListener(MinorClock);
                this.engine.RegisterListener(MajorClock);
            };
            this.engine.Start();

            Title = settings.ProjectName;
        }
Beispiel #6
0
 public AudioViewEngine(IMeterReader reader)
     : this(new TimeSpan(0, 1, 0), new TimeSpan(0, 15, 0), reader)
 {
 }
 public AudioViewEngine(IMeterReader reader)
     : this(new TimeSpan(0,1,0), new TimeSpan(0, 15, 0), reader)
 {
 }
        public void Stop()
        {
            logger.Debug("Stopping the engine.");
            if (this.secondTimer != null)
                this.secondTimer.Enabled = false;
            if (this.minorTimer != null)
                this.minorTimer.Enabled = false;
            if (this.majorTimer != null)
                this.majorTimer.Enabled = false;

            if (reader != null)
                reader.Close();

            this.secondTimer = null;
            this.minorTimer = null;
            this.majorTimer = null;
            this.reader = null;
        }
Beispiel #9
0
        public MeasurementViewModel(Guid id, MeasurementSettings settings, IMeterReader reader)
        {
            MinorReadings        = new ConcurrentQueue <Tuple <DateTime, ReadingData> >();
            MajorReadings        = new ConcurrentQueue <Tuple <DateTime, ReadingData> >();
            OctaveValues         = new ObservableCollection <OctaveBandGraphValue>();
            MinorSpan            = TimeSpan.FromTicks(settings.MinorInterval.Ticks * 15);
            MajorSpan            = TimeSpan.FromTicks(settings.MajorInterval.Ticks * 15);
            readingHistory       = new ReadingsStorage(MajorSpan);
            minorIntervalHistory = new ReadingsStorage(MinorSpan);
            majorIntervalHistory = new ReadingsStorage(majorSpan);
            minorGraphViewModel  = new GraphViewModel("LAeq", readingHistory, minorIntervalHistory, MinorSpan);
            majorGraphViewModel  = new GraphViewModel("LAeq", null, majorIntervalHistory, MajorSpan, false, true);
            lastMinorInterval    = new DateTime();
            lastMajorInterval    = new DateTime();

            started       = DateTime.Now;
            popOutWindows = new LinkedList <MetroWindow>();
            this.engine   = new AudioViewEngine(settings.MinorInterval, settings.MajorInterval, reader);
            this.settings = settings;

            this.engine.ConnectionStatusEvent += connected =>
            {
                if (ConnectionStatus == connected)
                {
                    return; // No need
                }
                Task.Run(() =>
                {
                    ConnectionStatus = connected;
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        OnPropertyChanged(nameof(IsDisconnected));
                    });
                });
            };

            if (settings.IsLocal)
            {
                // Registering the TCP Server for remote connections
                tcpServer = new TCPServerListener(settings);
                this.engine.RegisterListener(tcpServer);

                // Register the data storange unit
                dataStorage = new DataStorageMeterListener(id, DateTime.Now, settings);
                this.engine.RegisterListener(dataStorage);
            }

            this.engine.RegisterListener(new LocalStorageListener(AudioViewSettings.Instance.AutoSaveLocation, settings.ProjectName));

            this.engine.RegisterListener(this);
            MinorClock = new AudioViewCountDownViewModel(false,
                                                         settings.MinorInterval,
                                                         settings.MinorDBLimit,
                                                         settings.MinorClockMainItem,
                                                         settings.MinorClockSecondaryItem);
            MajorClock = new AudioViewCountDownViewModel(true,
                                                         settings.MajorInterval,
                                                         settings.MajorDBLimit,
                                                         settings.MajorClockMainItem,
                                                         settings.MajorClockSecondaryItem);
            this.engine.RegisterListener(MinorClock);
            this.engine.RegisterListener(MajorClock);
            this.engine.Start();

            Title = settings.ProjectName;
        }