コード例 #1
0
        protected override void OnListening(CommandContext context, IWorker worker)
        {
            var scheduler = worker as IScheduler;

            if (scheduler == null)
            {
                throw new CommandException("");
            }

            scheduler.Handled   += this.Scheduler_Handled;
            scheduler.Occurred  += this.Scheduler_Occurred;
            scheduler.Occurring += this.Scheduler_Occurring;
            scheduler.Scheduled += this.Scheduler_Scheduled;

            if (scheduler.Retriever != null)
            {
                scheduler.Retriever.Failed    += this.Retriever_Failed;
                scheduler.Retriever.Succeed   += this.Retriever_Succeed;
                scheduler.Retriever.Discarded += this.Retriever_Discarded;
            }

            //调用基类同名方法(打印欢迎信息)
            base.OnListening(context, worker);

            //打印基本信息
            context.Output.WriteLine(SchedulerCommand.GetInfo(scheduler, true).AppendLine());
        }
コード例 #2
0
        protected override void Info(CommandContext context, IWorker worker)
        {
            if (worker is IScheduler scheduler)
            {
                //构造基本信息内容
                var content = SchedulerCommand.GetInfo(scheduler, true).AppendLine();

                //获取“limit”命令参数
                var limit = context.Expression.Options.GetValue <int>(KEY_LIMIT_OPTION);

                if (limit > 0)
                {
                    var index = 0;

                    //遍历生成触发器信息
                    foreach (var trigger in scheduler.Triggers)
                    {
                        if (index == limit)
                        {
                            content.AppendLine(CommandOutletColor.DarkMagenta, "\t... ...");
                            break;
                        }

                        //获取当前触发器下的处理器集合
                        var tokens = scheduler.GetHandlers(trigger);

                        content.Append(CommandOutletColor.DarkYellow, $"[{++index}] ")
                        .Append(CommandOutletColor.DarkGreen, trigger.ToString())
                        .AppendLine(CommandOutletColor.DarkMagenta, $" ({tokens.Length})");

                        if (!string.IsNullOrWhiteSpace(trigger.Description))
                        {
                            content.AppendLine(CommandOutletColor.DarkGray, trigger.Description);
                        }

                        //遍历生成处理器信息
                        for (int i = 0; i < tokens.Length; i++)
                        {
                            if (i >= limit)
                            {
                                content.AppendLine(CommandOutletColor.DarkMagenta, "\t... ...");
                                break;
                            }

                            content.Append(CommandOutletColor.DarkCyan, $"    {tokens[i].ScheduleId, 5}")
                            .Append(CommandOutletColor.DarkGray, " : ")
                            .AppendLine(tokens[i].ToString());
                        }
                    }
                }

                //输出整个信息内容
                context.Output.WriteLine(content);
            }
            else
            {
                //调用基类同名方法
                base.Info(context, worker);
            }
        }
コード例 #3
0
        private void Scheduler_Occurring(object sender, OccurringEventArgs e)
        {
            //获取调度器的基本信息内容(不需包含状态信息)
            var content = SchedulerCommand.GetInfo((IScheduler)sender, false);

            content.Prepend(Properties.Resources.Scheduler_Occurring_Name)
            .After(CommandOutletColor.DarkGray, "(")
            .After(CommandOutletColor.DarkCyan, e.ScheduleId)
            .After(CommandOutletColor.DarkGray, ")");

            this.Context.Output.WriteLine(content.First);
        }
コード例 #4
0
        private void Scheduler_Scheduled(object sender, ScheduledEventArgs e)
        {
            //获取调度器的基本信息内容(不需包含状态信息)
            var content = SchedulerCommand.GetInfo((IScheduler)sender, false);

            content.Prepend(Properties.Resources.Scheduler_Scheduled_Name)
            .After(CommandOutletColor.DarkGray, "(")
            .After(CommandOutletColor.DarkCyan, e.ScheduleId)
            .After(CommandOutletColor.DarkGray, "): ")
            .After(CommandOutletColor.Magenta, e.Count.ToString() + " ");

            if (e.Triggers != null && e.Triggers.Length > 0)
            {
                content.AppendLine();

                for (int i = 0; i < e.Triggers.Length; i++)
                {
                    content.Append(CommandOutletColor.DarkYellow, $"[{i + 1}] ")
                    .AppendLine(e.Triggers[i].ToString());
                }
            }

            this.Context.Output.WriteLine(content.First);
        }
コード例 #5
0
        protected override void Info(CommandContext context, IWorker worker)
        {
            if (worker is IScheduler scheduler)
            {
                //构造基本信息内容
                var content = SchedulerCommand.GetInfo(scheduler, true);

                //获取“limit”命令参数
                var limit = context.Expression.Options.GetValue <int>(KEY_LIMIT_OPTION);

                if (limit > 0)
                {
                    //构造触发器信息内容
                    content.AppendLine().AppendLine()
                    .AppendLine(CommandOutletColor.DarkMagenta, string.Format(Properties.Resources.Scheduler_Triggers, scheduler.Triggers.Count));

                    var index = 0;

                    //遍历生成触发器信息
                    foreach (var trigger in scheduler.Triggers)
                    {
                        //限制输出前100个
                        if (index == limit)
                        {
                            content.AppendLine(CommandOutletColor.Gray, "\t... ...");
                            break;
                        }

                        content.Append(CommandOutletColor.DarkYellow, $"[{++index}] ")
                        .AppendLine(trigger.ToString());
                    }

                    //构造处理器信息内容
                    content.AppendLine()
                    .AppendLine(CommandOutletColor.DarkMagenta, string.Format(Properties.Resources.Scheduler_Handlers, scheduler.Handlers.Count));

                    index = 0;

                    //遍历生成处理器信息
                    foreach (var handler in scheduler.Handlers)
                    {
                        //限制输出前100个
                        if (index == limit)
                        {
                            content.AppendLine(CommandOutletColor.Gray, "\t... ...");
                            break;
                        }

                        content.Append(CommandOutletColor.DarkYellow, $"[{++index}] ")
                        .AppendLine(handler.ToString());
                    }
                }

                //输出整个信息内容
                context.Output.WriteLine(content);
            }
            else
            {
                //调用基类同名方法
                base.Info(context, worker);
            }
        }