Example #1
0
        public void Start_WithParams_Test()
        {
            var taskManager =
                TaskBuilder.Create()
                //设置日志记录
                .WithLoggers(new DebugLogger("TaskManager"), new DebugLogger("Task"))
                //设置通知器
                .WithNotifier(new TestNotifier())
                .Build();

            taskManager.Start(nameof(TeskTaskWithParams), 1);
        }
Example #2
0
        public void Start_WithTaskCompleteAction_Test()
        {
            var taskManager =
                TaskBuilder.Create()
                //设置日志记录
                .WithLoggers(new DebugLogger("TaskManager"), new DebugLogger("Task"))
                //设置通知器
                .WithNotifier(new TestNotifier())
                .WithTaskCompleteAction((task) =>
            {
                flag = 1;
                new DebugLogger("Debug").Log(Logger.LoggerLevels.Debug, "Test——WithTaskCompleteAction");
            })
                .Build();

            taskManager.Start(nameof(TeskTaskWithParams), 1);
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(flag == 1);
        }
Example #3
0
        public void Start_WithException_Test()
        {
            var taskManager =
                TaskBuilder.Create()
                //设置日志记录
                .WithLoggers(new DebugLogger("TaskManager"), new DebugLogger("Task"))
                //设置通知器
                .WithNotifier(new TestNotifier())
                .WithTaskCompleteAction((task) =>
            {
                flag = 1;
                Assert.IsNotNull(task.Exception);
                new DebugLogger("Debug").Log(Logger.LoggerLevels.Error, task.Exception.Message);
            })
                .Build();

            taskManager.Start(nameof(TeskTaskWithException));
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(flag == 1);
        }
Example #4
0
        /// <summary>
        /// 配置任务管理器
        /// </summary>
        public static void ConfigTaskManager()
        {
            var taskManager =
                TaskBuilder.Create()
                //设置日志记录
                .WithLoggers(new NLogLogger("TaskManager"), new NLogLogger("Task"))
                //设置通知器
                .WithNotifier(WeiChatApplicationContext.Current.Notifier)
                .WithTaskCompleteAction((task) =>
            {
                var notifyInfo = task.NotifyInfo as Site_Notify;
                using (var db = new AppDbContext())
                {
                    db.Site_Notifies.Add(notifyInfo);
                    db.SaveChanges();
                }
            })
                .Build();

            WeiChatApplicationContext.Current.TaskManager = taskManager;
        }