Exemplo n.º 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);
            }
        }
Exemplo n.º 2
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;

                this.minorTimer = new Timer(minorInterval.TotalMilliseconds);
                this.minorTimer.Elapsed += OnMinorInterval;
                
                this.majorTimer = new Timer(majorInterval.TotalMilliseconds);
                this.majorTimer.Elapsed += OnMajorInterval;
            }
        }
Exemplo n.º 3
0
        public void Start()
        {
            logger.Debug("Preparing engine to start.");


            if (!reader.IsTriggerMode())
            {
                secondTimer.Start();

                var minorTimerStart = minorIntervalTimer.Start((triggered, nextInterval) =>
                {
                    logger.Info("Minor interval triggered. Triggered: " + triggered + " Next: " + nextInterval);
                    nextMinor = nextInterval;
                    OnMinorInterval(triggered, nextInterval);
                }, (triggered, nextInterval) =>
                {
                    logger.Info("Minor interval Started. Triggered: " + triggered + " Next: " + nextInterval);
                    nextMinor            = nextInterval;
                    minorIntervalStarted = triggered;
                    lock (this.listeners)
                    {
                        foreach (var listener in this.listeners)
                        {
                            logger.Debug("Informing " + listener.GetType().Name + " of next minor interval " +
                                         nextInterval);
                            listener.NextMinor(nextInterval);
                        }
                    }
                });

                logger.Debug("Minor interval will start at " + minorTimerStart);
                nextMinor = minorTimerStart;
                lock (this.listeners)
                {
                    foreach (var listener in this.listeners)
                    {
                        logger.Debug("Informing " + listener.GetType().Name + " of minor start time " +
                                     minorTimerStart);
                        listener.NextMinor(minorTimerStart);
                    }
                }


                var majorTimerStart = majorIntervalTimer.Start((triggered, nextInterval) =>
                {
                    logger.Info("Major interval triggered. Triggered: " + triggered + " Next: " + nextInterval);
                    nextMajor = nextInterval;
                    OnMajorInterval(triggered, nextInterval);
                }, (triggered, nextInterval) =>
                {
                    logger.Info("Major interval Started. Triggered: " + triggered + " Next: " + nextInterval);
                    nextMajor            = nextInterval;
                    majorIntervalStarted = triggered;
                    lock (this.listeners)
                    {
                        foreach (var listener in this.listeners)
                        {
                            logger.Debug("Informing " + listener.GetType().Name + " of next major interval " +
                                         nextInterval);
                            listener.NextMajor(nextInterval);
                        }
                    }
                });

                logger.Debug("Major interval will start at " + majorTimerStart);
                nextMajor = majorTimerStart;
                lock (this.listeners)
                {
                    foreach (var listener in this.listeners)
                    {
                        logger.Debug("Informing " + listener.GetType().Name + " of major start time.");
                        listener.NextMajor(majorTimerStart);
                    }
                }
            }
        }