Exemple #1
0
        public async void TestTimerRule2()
        {
            Context.Dispatcher.Clear();
            await Rule.Stop();

            var paramDelay = GetRuleInterfaceByTemplate(TimerRuleFactory.RuleTimerParameter);
            var timerData  = new TimerPropertyData()
            {
                StartTime   = DateTime.Now.AddSeconds(1),
                StopTime    = DateTime.Now.AddSeconds(2),
                EnabledDays = new List <DayOfWeek>()
                {
                    DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday,
                    DayOfWeek.Saturday, DayOfWeek.Sunday
                }
            };

            timerData.EnabledDays.Remove(DateTime.Now.DayOfWeek);

            paramDelay.Value = timerData;

            await Rule.Start();

            await Task.Delay(1500);

            var values = Context.Dispatcher.GetValues(Automatica.Core.Base.IO.DispatchableType.RuleInstance);

            Assert.Equal(0, values.Count);
            await Rule.Stop();
        }
Exemple #2
0
        public override Task <bool> Start()
        {
            if (_timerProperty?.Value != null)
            {
                _timerPropertyData = (TimerPropertyData)_timerProperty.Value;
            }
            else
            {
                Context.Logger.LogError("No or invalid timer property found");
                return(Task.FromResult(false));
            }

            CalculateTickTime(true);


            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();
            return(base.Start());
        }