Exemplo n.º 1
0
        /// <summary>开始</summary>
        public override void Start()
        {
            var svr = Server;

            // 使用配置中心账号
            var ant = new AntClient(svr)
            {
                UserName = AppID,
                Password = Secret
            };

            ant.Open();

            // 断开前一个连接
            Ant.TryDispose();
            Ant = ant;

            var ws = Schedule?.Jobs;

            //var jobs = GetJobs(ws.Select(e => e.Name).ToArray());
            var list = new List <IJob>();

            foreach (var wrk in ws)
            {
                var job = wrk.Job ?? new JobModel();

                job.Name = wrk.Name;
                job.Mode = wrk.Mode;

                // 描述
                if (job is JobModel job2)
                {
                    var dis = wrk.GetType().GetDisplayName();
                    if (!dis.IsNullOrEmpty())
                    {
                        job2.DisplayName = dis;
                    }
                    var des = wrk.GetType().GetDescription();
                    if (!des.IsNullOrEmpty())
                    {
                        job2.Description = des;
                    }
                }

                list.Add(job);
            }
            if (list.Count > 0)
            {
                Ant.AddJobs(list.ToArray());
            }

            // 定时更新邻居
            _timer = new TimerX(DoCheckPeer, null, 1_000, 30_000)
            {
                Async = true
            };
        }
Exemplo n.º 2
0
        /// <summary>开始</summary>
        public override void Start()
        {
            var svr = Server;

            // 使用配置中心账号
            var ant = new AntClient(svr)
            {
                UserName = AppID,
                Password = Secret
            };

            if (Debug)
            {
                ant.EncoderLog = XTrace.Log;
            }
            ant.Open();

            // 断开前一个连接
            Ant.TryDispose();
            Ant = ant;

            var bs = Schedule?.Handlers;

            //var jobs = GetJobs(ws.Select(e => e.Name).ToArray());
            var list = new List <IJob>();

            foreach (var handler in bs)
            {
                var job = handler.Job ?? new JobModel();

                job.Name      = handler.Name;
                job.ClassName = handler.GetType().FullName;
                job.Mode      = handler.Mode;

                // 描述
                if (job is JobModel job2)
                {
                    var dis = handler.GetType().GetDisplayName();
                    if (!dis.IsNullOrEmpty())
                    {
                        job2.DisplayName = dis;
                    }
                    var des = handler.GetType().GetDescription();
                    if (!des.IsNullOrEmpty())
                    {
                        job2.Description = des;
                    }

                    if (handler is MessageHandler mhandler)
                    {
                        job2.Topic = mhandler.Topic;
                    }
                }

                list.Add(job);
            }
            if (list.Count > 0)
            {
                Ant.AddJobs(list.ToArray());
            }

            // 定时更新邻居
            _timer = new TimerX(DoCheckPeer, null, 1_000, 30_000)
            {
                Async = true
            };
        }