Пример #1
0
        public async Task InvokeAsync(ScheduledTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken)
        {
            while (true)
            {
                var synchronizedTime = GetNextTriggerTime(triggerInfo, DateTimeOffset.UtcNow);
                if (synchronizedTime == null)
                {
                    return;
                }

                var nextTriggerTime = synchronizedTime.Value;
                if (!triggerInfo.SynchronizeTimeZone)
                {
                    //ignore offset
                    nextTriggerTime = new DateTimeOffset(nextTriggerTime.DateTime, DateTimeOffset.UtcNow.Offset);
                }

                context.ReportNextTrigger(nextTriggerTime);
                await Task.Delay(nextTriggerTime - DateTimeOffset.UtcNow, cancellationToken);

                //important: use synchronized time
                var session = await context.CreateSession(SessionKey.Create("ScheduledTrigger", synchronizedTime.Value));

                await session.Invoke();
            }
        }
Пример #2
0
        public async Task InvokeAsync(OnAppStartupTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken)
        {
            var session = await context.CreateSession(SessionKey.Create("OnAppStartup", DateTimeOffset.UtcNow));

            await session.Invoke();

            await Task.Delay(int.MaxValue, cancellationToken);
        }
Пример #3
0
        public async Task InvokeAsync(SystemRestartTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken)
        {
            var now         = DateTime.UtcNow;
            var uptime      = TimeSpan.FromMilliseconds(GetTickCount64());
            var startupTime = now.Add(-uptime);

            var session = await context.CreateSession(SessionKey.Create("SystemRestart"));

            if (!session.Info.Executions.Any(x => x.CreatedOn > startupTime))
            {
                await session.Invoke();
            }

            await Task.Delay(TimeSpan.MaxValue, cancellationToken);
        }
Пример #4
0
        public async Task InvokeAsync(OnAppStartupTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken)
        {
            var session = await context.CreateSession(SessionKey.Create("OnAppStart", DateTime.Now.Date));

            if (triggerInfo.OncePerDay)
            {
                if (session.Info.Executions.Any())
                {
                    await Task.Delay(int.MaxValue, cancellationToken);
                }
            }

            await session.Invoke();

            await Task.Delay(int.MaxValue, cancellationToken);
        }
Пример #5
0
 public OnJoinTriggerService(IClientEventNotifier clientEvents)
 {
     _clientEvents        = clientEvents;
     _clientConnectedLock = new AsyncLock();
     _sessionTrigger      = new AsyncLazy <TaskSessionTrigger>(() => _context.CreateSession(SessionKey.Create("OnClientJoin")));
 }
Пример #6
0
        public async Task InvokeAsync(ImmediatelyTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken)
        {
            var session = await context.CreateSession(SessionKey.Create("Immediate", DateTimeOffset.UtcNow));

            await session.Invoke();
        }