コード例 #1
0
 //RunCommand(2, 1, '99');
 public Result RunCommand(int commandId, string arg1, string arg2)
 {
     return(CommandProcessor.RunCommandAsync(commandId, arg1, arg2, CancellationToken.None).Result);
 }
コード例 #2
0
 public async Task<Result> RunCommandAsync(int? commandId, string argument, string argument2,
     CancellationToken cancellationToken)
 {
     var commandProcessor = new CommandProcessor(AdapterManager, EntityContextConnection, Log);
     return await commandProcessor.RunCommandAsync(commandId, argument, argument2, cancellationToken);
 }
コード例 #3
0
        private async void Run(CancellationToken cancellationToken)
        {
            IsRunning = true;
            while (true)
            {
                if (UpdateCache)
                {
                    CommandScheduledTasksCache = await GetScheduledTasksAsync(Cts.Token);

                    UpdateCache = false;
                }

                foreach (var task in CommandScheduledTasksCache)
                {
                    var needsToRun = false;

                    switch (task.TaskType)
                    {
                    case ScheduledTaskType.OneTime:
                    {
                        needsToRun = task.EvalOneTimeTrigger(TimeProvider);
                        break;
                    }

                    case ScheduledTaskType.Daily:
                    {
                        needsToRun = task.EvalDailyTrigger(TimeProvider);
                        break;
                    }

                    case ScheduledTaskType.Interval:
                    {
                        needsToRun = task.EvalIntervalTrigger(TimeProvider);
                        break;
                    }

                    case ScheduledTaskType.Weekly:
                    {
                        needsToRun = task.EvalWeeklyTrigger(TimeProvider);
                        break;
                    }

                    case ScheduledTaskType.Monthly:
                    {
                        needsToRun = task.EvalMonthlyTrigger(TimeProvider);
                        break;
                    }
                    }
                    if (!needsToRun)
                    {
                        continue;
                    }

                    await Log.ReportInfoFormatAsync(cancellationToken, "Scheduled task '{0}' executed", task.Name);

                    var task1 = task;
                    await Task.Run(async() => await CommandProcessor.RunCommandAsync(task1.CommandId, task1.Argument, task1.Argument2, cancellationToken), cancellationToken);
                }

                try
                {
                    await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
                }
                catch (OperationCanceledException)
                {
                    break;
                }
            }

            IsRunning = false;
            await Log.ReportInfoAsync("ScheduledTask runner stopped", CancellationToken.None);
        }