コード例 #1
0
        private async Task CalibrationMinimumLight(IContext context)
        {
            if (context.Message is StopCommand stopCommand)
            {
                // Ignore previous commands if we receive any
                if (stopCommand[MessageProperties.Context] == "MAX")
                {
                    return;
                }

                Become(StandardMode);

                ForwardToPowerAdapter(TurnOffCommand.Default);

                ResetStateValues();

                TryCalculateSpectrum();

                Logger.LogInformation($"Calibration of {Uid} : calibration finished with MIN: {_Minimum}, MAX: {_Maximum}, RANGE: {_Range}");

                await Task.Delay(WAIT_AFTER_CHANGE).ConfigureAwait(false);

                ForwardToPowerAdapter(TurnOnCommand.Create(CHANGE_POWER_STATE_TIME));
            }
            else if (context.Message is PropertyChangedEvent minimumState)
            {
                await MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, StopCommand.Create("MIN")), TimeSpan.FromMilliseconds(1500)).ConfigureAwait(false);

                _Minimum = minimumState.AsDouble(MessageProperties.NewValue);
            }
            else
            {
                await StandardMode(context).ConfigureAwait(false);
            }
        }
コード例 #2
0
        public async Task SendAfterDelay(ActorMessageContext message, TimeSpan delay, bool cancelExisting = true, CancellationToken token = default)
        {
            var uid = message.GetMessageUid();

            if (cancelExisting)
            {
                await _scheduler.CancelJob(uid);
            }

            await _scheduler.DelayExecution <ActorMessageJob, ActorMessageContext>(delay, message, uid, token);
        }
コード例 #3
0
ファイル: DenonAdapter.cs プロジェクト: kmate95/HomeCenter
        protected override async Task OnStarted(IContext context)
        {
            await base.OnStarted(context).ConfigureAwait(false);

            _hostName     = AsString(MessageProperties.Hostname);
            _poolInterval = AsIntTime(MessageProperties.PoolInterval, DEFAULT_POOL_INTERVAL);
            _zone         = AsInt(MessageProperties.Zone);

            await MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, RefreshCommand.Default), TimeSpan.FromSeconds(1));

            await ScheduleDeviceLightRefresh(_poolInterval).ConfigureAwait(false);
        }
コード例 #4
0
ファイル: Component.cs プロジェクト: kmate95/HomeCenter
        private async Task HandleEventInTrigger(Trigger trigger)
        {
            if (await trigger.ValidateCondition().ConfigureAwait(false))
            {
                foreach (var command in trigger.Commands)
                {
                    if (command.ContainsProperty(MessageProperties.ExecutionDelay))
                    {
                        var executionDelay = command.AsTime(MessageProperties.ExecutionDelay);
                        var cancelPrevious = command.AsBool(MessageProperties.CancelPrevious, false);

                        await MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, command), executionDelay, cancelPrevious).ConfigureAwait(false);

                        continue;
                    }

                    MessageBroker.Send(command, Self);
                }
            }
        }
コード例 #5
0
        private async Task CalibrationMaximumLight(IContext context)
        {
            if (context.Message is StopCommand stopCommand)
            {
                Become(CalibrationMinimumLight);
                ForwardToPowerAdapter(TurnOffCommand.Default);
                await Task.Delay(WAIT_AFTER_CHANGE).ConfigureAwait(false);

                Logger.LogInformation($"Calibration of {Uid} : waiting to reach MIN state");
                ForwardToPowerAdapter(TurnOnCommand.Default);
            }
            else if (context.Message is PropertyChangedEvent maximumState)
            {
                // Resend stop message to cancel scheduled message
                await MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, StopCommand.Create("MAX")), TimeSpan.FromMilliseconds(1500), true).ConfigureAwait(false);

                _Maximum = maximumState.AsDouble(MessageProperties.NewValue);
            }
            else
            {
                await StandardMode(context).ConfigureAwait(false);
            }
        }
コード例 #6
0
 public Task SendWithSimpleRepeat(ActorMessageContext message, TimeSpan interval, CancellationToken token = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
コード例 #7
0
 public Task SendWithCronRepeat(ActorMessageContext message, string cronExpression, CancellationToken token = default(CancellationToken), string calendar = null)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
 public Task SendDailyAt(ActorMessageContext message, TimeSpan time, CancellationToken token = default(CancellationToken), string calendar = null)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public Task SendAtTime(ActorMessageContext message, DateTimeOffset time, CancellationToken token = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
コード例 #10
0
 public Task SendAfterDelay(ActorMessageContext message, TimeSpan delay, bool cancelExisting = true, CancellationToken token = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
コード例 #11
0
        public async Task SendDailyAt(ActorMessageContext message, TimeSpan time, CancellationToken token = default, string calendar = default)
        {
            var uid = message.GetMessageUid();

            await _scheduler.ScheduleDailyTimeInterval <ActorMessageJob, ActorMessageContext>(time, message, uid, token);
        }
コード例 #12
0
        public async Task SendAtTime(ActorMessageContext message, DateTimeOffset time, CancellationToken token = default)
        {
            var uid = message.GetMessageUid();

            await _scheduler.DelayExecution <ActorMessageJob, ActorMessageContext>(time, message, uid, token);
        }
コード例 #13
0
        public Task SendWithCronRepeat(ActorMessageContext message, string cronExpression, CancellationToken token = default, string calendar = default)
        {
            var uid = message.GetMessageUid();

            return(_scheduler.ScheduleCron <ActorMessageJob, ActorMessageContext>(cronExpression, message, uid, token, calendar));
        }
コード例 #14
0
 public Task SendWithSimpleRepeat(ActorMessageContext message, TimeSpan interval, CancellationToken token = default)
 {
     return(_scheduler.ScheduleInterval <ActorMessageJob, ActorMessageContext>(interval, message, message.GetMessageUid(), token));
 }
コード例 #15
0
 protected Task DelayDeviceRefresh(TimeSpan interval)
 {
     return(MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, RefreshLightCommand.Default), interval,
                                         false, _disposables.Token));
 }
コード例 #16
0
 protected Task ScheduleDeviceLightRefresh(TimeSpan interval)
 {
     return(MessageBroker.SendWithSimpleRepeat(ActorMessageContext.Create(Self, RefreshLightCommand.Default),
                                               interval, _disposables.Token));
 }