public void CreateSimpleSysTask()
		{
			DO.SysTask task = new DO.SysTask()
			{
				TaskID = UuidHelper.NewUuidString(),
				TaskTitle = "新任务",
			};

			DO.SysTaskAdapter.Instance.Update(task);

			DO.SysTask taskLoaded = DO.SysTaskAdapter.Instance.Load(task.TaskID);

			Assert.IsNotNull(taskLoaded);
			Assert.AreEqual(task.TaskID, taskLoaded.TaskID);
			Assert.AreEqual(task.TaskTitle, taskLoaded.TaskTitle);
		}
Beispiel #2
0
        public void CreateSimpleSysTask()
        {
            DO.SysTask task = new DO.SysTask()
            {
                TaskID    = UuidHelper.NewUuidString(),
                TaskTitle = "新任务",
            };

            DO.SysTaskAdapter.Instance.Update(task);

            DO.SysTask taskLoaded = DO.SysTaskAdapter.Instance.Load(task.TaskID);

            Assert.IsNotNull(taskLoaded);
            Assert.AreEqual(task.TaskID, taskLoaded.TaskID);
            Assert.AreEqual(task.TaskTitle, taskLoaded.TaskTitle);
        }
Beispiel #3
0
        private static void SetSysTaskToCompletedSub(DO.SysTask task1, SysTaskStatus status, string statusText)
        {
            DO.SysTaskAdapter.Instance.Update(task1);

            SysTaskAdapter.Instance.MoveToCompletedSysTask(task1.TaskID, status, statusText);

            DO.SysTask task11 = SysTaskAdapter.Instance.Load(task1.TaskID);

            Assert.IsNull(task11);

            var task12 = SysAccomplishedTaskAdapter.Instance.Load(task1.TaskID);

            Assert.IsNotNull(task12);

            Assert.AreEqual(status, task12.Status);
        }
Beispiel #4
0
        public void InvokeServiceTaskTest()
        {
            //准备Job信息
            //调用SysTaskSettings.GetSettings().GetExecutor("InvokeService")执行服务
            //检验状态

            InvokeWebServiceJob job = new InvokeWebServiceJob()
            {
                JobID            = UuidHelper.NewUuidString(),
                JobType          = JobType.InvokeService,
                Category         = "测试权限中心服务",
                Description      = "仅用于测试",
                Enabled          = true,
                Name             = "任务和作业的单元测试",
                SvcOperationDefs = new Workflow.WfServiceOperationDefinitionCollection()
            };

            WfServiceOperationParameterCollection parameters = new WfServiceOperationParameterCollection();

            parameters.Add(new WfServiceOperationParameter()
            {
                Name = "callerID", Type = WfSvcOperationParameterType.RuntimeParameter, Value = "callerID"
            });

            job.SvcOperationDefs.Add(new Workflow.WfServiceOperationDefinition(new Workflow.WfServiceAddressDefinition(Workflow.WfServiceRequestMethod.Post, null,
                                                                                                                       "http://localhost/MCSWebApp/PermissionCenterServices/services/PermissionCenterToADService.asmx"), "GetVersion", parameters, string.Empty));
            InvokeWebServiceJobAdapter.Instance.Update(job);

            DO.SysTask task = new DO.SysTask()
            {
                TaskID     = UuidHelper.NewUuidString(),
                TaskTitle  = "测试任务",
                ResourceID = job.JobID
            };

            SysTaskAdapter.Instance.Update(task);

            ISysTaskExecutor executor = SysTaskSettings.GetSettings().GetExecutor("InvokeService");

            executor.Execute(task);

            var task2 = SysTaskAdapter.Instance.Load(task.TaskID);

            Assert.IsNull(task2);
        }
        /// <summary>
        /// 执行并且验证Task的返回结果
        /// </summary>
        /// <param name="func"></param>
        private static void ExecuteAndAssertTask(Func <DO.SysTask> func)
        {
            func.NullCheck("func");

            DO.SysTask task = func();

            DO.SysTask taskLoaded = SysTaskAdapter.Instance.Load(task.TaskID);

            ISysTaskExecutor executor = SysTaskSettings.GetSettings().GetExecutor(taskLoaded.TaskType);

            executor.Execute(taskLoaded);

            SysAccomplishedTask accomplishedTask = SysAccomplishedTaskAdapter.Instance.Load(taskLoaded.TaskID);

            Assert.IsNotNull(accomplishedTask);

            Console.WriteLine(accomplishedTask.StatusText);
            Assert.AreEqual(SysTaskStatus.Completed, accomplishedTask.Status);
        }
		public void InvokeServiceTaskTest()
		{
			//准备Job信息
			//调用SysTaskSettings.GetSettings().GetExecutor("InvokeService")执行服务
			//检验状态

			InvokeWebServiceJob job = new InvokeWebServiceJob()
			{
				JobID = UuidHelper.NewUuidString(),
				JobType = JobType.InvokeService,
				Category = "测试权限中心服务",
				Description = "仅用于测试",
				Enabled = true,
				Name = "任务和作业的单元测试",
				SvcOperationDefs = new Workflow.WfServiceOperationDefinitionCollection()
			};

			WfServiceOperationParameterCollection parameters = new WfServiceOperationParameterCollection();

			parameters.Add(new WfServiceOperationParameter() { Name = "callerID", Type = WfSvcOperationParameterType.RuntimeParameter, Value = "callerID" });

			job.SvcOperationDefs.Add(new Workflow.WfServiceOperationDefinition(new Workflow.WfServiceAddressDefinition(Workflow.WfServiceRequestMethod.Post, null,
				"http://localhost/MCSWebApp/PermissionCenterServices/services/PermissionCenterToADService.asmx"), "GetVersion", parameters, string.Empty));
			InvokeWebServiceJobAdapter.Instance.Update(job);

			DO.SysTask task = new DO.SysTask()
			{
				TaskID = UuidHelper.NewUuidString(),
				TaskTitle = "测试任务",
				ResourceID = job.JobID
			};

			SysTaskAdapter.Instance.Update(task);

			ISysTaskExecutor executor = SysTaskSettings.GetSettings().GetExecutor("InvokeService");

			executor.Execute(task);

			var task2 = SysTaskAdapter.Instance.Load(task.TaskID);

			Assert.IsNull(task2);
		}
Beispiel #7
0
        public void StartSysTaskProcessTest()
        {
            SysTaskAdapter.Instance.ClearAll();

            SysTaskProcess process = PrepareSysTaskProcessData(() => PrepareInvokeServiceTask());

            SysTaskProcessRuntime.StartProcess(process);

            DO.SysTask moveToTask = SysTaskAdapter.Instance.LoadByResourceID(process.Activities[0].ID).FirstOrDefault();

            Assert.IsNotNull(moveToTask);

            SysTaskCommon.ExecuteAndAssertTask(moveToTask);

            SysTaskProcessRuntime.ClearCache();

            process = SysTaskProcessRuntime.GetProcessByID(process.ID);

            Assert.AreEqual(1, process.CurrentActivityIndex);
        }
        public void InvokeServiceTaskExecuteTest()
        {
            DO.InvokeServiceTask task = PrepareTask();

            DO.InvokeServiceTaskAdapter.Instance.Update(task);

            DO.SysTask taskLoaded = DO.SysTaskAdapter.Instance.Load(task.TaskID);

            ISysTaskExecutor executor = SysTaskSettings.GetSettings().GetExecutor(taskLoaded.TaskType);

            executor.Execute(taskLoaded);

            Console.WriteLine(WfServiceInvoker.InvokeContext[task.SvcOperationDefs.FirstOrDefault().RtnXmlStoreParamName]);

            SysAccomplishedTask accomplishedTask = SysAccomplishedTaskAdapter.Instance.Load(taskLoaded.TaskID);

            Assert.IsNotNull(accomplishedTask);
            Assert.AreEqual(taskLoaded.Data, accomplishedTask.Data);

            Console.WriteLine(accomplishedTask.StatusText);
        }
Beispiel #9
0
        public void FetchNotRunningTasks()
        {
            SysTaskAdapter.Instance.ClearAll();

            for (int i = 0; i < 8; i++)
            {
                var task = new DO.SysTask()
                {
                    TaskID    = UuidHelper.NewUuidString(),
                    TaskTitle = "新任务"
                };

                SysTaskAdapter.Instance.Update(task);
            }

            SysTaskAdapter.Instance.FetchNotRuningSysTasks(2, m =>
            {
                SysTaskAdapter.Instance.MoveToCompletedSysTask(m.TaskID, SysTaskStatus.Aborted, "Unit Test Error");
            });

            var result = SysTaskAdapter.Instance.FetchNotRuningSysTasks(8, null);

            Assert.AreEqual(6, result.Count);
        }
		public void FetchNotRunningTasks()
		{
			SysTaskAdapter.Instance.ClearAll();

			for (int i = 0; i < 8; i++)
			{
				var task = new DO.SysTask()
				{
					TaskID = UuidHelper.NewUuidString(),
					TaskTitle = "新任务"
				};

				SysTaskAdapter.Instance.Update(task);
			}

			SysTaskAdapter.Instance.FetchNotRuningSysTasks(2, m =>
			{
				SysTaskAdapter.Instance.MoveToCompletedSysTask(m.TaskID, SysTaskStatus.Aborted, "Unit Test Error");
			});

			var result = SysTaskAdapter.Instance.FetchNotRuningSysTasks(8, null);

			Assert.AreEqual(6, result.Count);
		}
 /// <summary>
 /// 得到Job信息
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 protected abstract JobBase GetJobInfo(SysTask task);
Beispiel #12
0
 /// <summary>
 /// 执行之前
 /// </summary>
 /// <param name="task"></param>
 public void BeforeExecute(SysTask task)
 {
     OnBeforeExecute(task);
 }
Beispiel #13
0
 /// <summary>
 /// 执行具体的内容
 /// </summary>
 /// <param name="task"></param>
 protected abstract void OnExecute(SysTask task);
		public void InvokeHugeServiceTasksTest()
		{
			SysTaskAdapter.Instance.ClearAll();
			SysAccomplishedTaskAdapter.Instance.ClearAll();

			InvokeWebServiceJob job = new InvokeWebServiceJob()
			{
				JobID = UuidHelper.NewUuidString(),
				JobType = JobType.InvokeService,
				Category = "测试权限中心服务",
				Description = "仅用于测试",
				Enabled = true,
				Name = "任务和作业的单元测试",
				SvcOperationDefs = new Workflow.WfServiceOperationDefinitionCollection()
			};

			job.SvcOperationDefs.Add(new Workflow.WfServiceOperationDefinition(new Workflow.WfServiceAddressDefinition(Workflow.WfServiceRequestMethod.Post, null, "http://localhost/MCSWebApp/PermissionCenterServices/services/PermissionCenterToADService.asmx"), "GetVersion", null, string.Empty));
			InvokeWebServiceJobAdapter.Instance.Update(job);

			for (int i = 0; i < 400; i++)
			{
				DO.SysTask task = new DO.SysTask()
				{
					TaskID = UuidHelper.NewUuidString(),
					TaskTitle = "测试任务" + i,
					ResourceID = job.JobID,
					TaskType = "InvokeService"
				};

				SysTaskAdapter.Instance.Update(task);
			}

			int count = 0;
			var tasks = SysTaskAdapter.Instance.FetchNotRuningSysTasks(800, m =>
			{
				SysTaskAdapter.Instance.UpdateStatus(m.TaskID, SysTaskStatus.Running);

			});
			Thread thread = Thread.CurrentThread;

			Assert.AreEqual(400, tasks.Count);

			Debug.WriteLine(DateTime.Now + "开始执行");
			Stopwatch watch = new Stopwatch();
			watch.Start();

			var result = System.Threading.Tasks.Parallel.ForEach<DO.SysTask>(tasks, t =>
			{
				if (t.TaskType == "InvokeService")
				{
					Debug.WriteLine(DateTime.Now + "当前执行:" + System.Threading.Interlocked.Increment(ref count) + "  主线程状态" + thread.ThreadState + "当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
					ISysTaskExecutor exec = SysTaskSettings.GetSettings().GetExecutor("InvokeService");
					exec.Execute(t);
				}
			});

			watch.Stop();

			Debug.WriteLine(string.Format("已完成所有任务: {0} 耗时 {1}ms", result.IsCompleted, watch.ElapsedMilliseconds));
			Debug.WriteLine(DateTime.Now + "主线程执行结束");



		}
Beispiel #15
0
 /// <summary>
 /// 执行之后,置执行状态,并且移动到已完成中
 /// </summary>
 /// <param name="task"></param>
 /// <returns>返回的已完成任务</returns>
 protected virtual SysAccomplishedTask OnAfterExecute(SysTask task)
 {
     //Move,修改Task的状态为Completed
     return(SysTaskAdapter.Instance.MoveToCompletedSysTask(task, SysTaskStatus.Completed, string.Empty));
 }
		public void InvokeHugeServiceTasksTest2()
		{
			SysTaskAdapter.Instance.ClearAll();
			SysAccomplishedTaskAdapter.Instance.ClearAll();

			InvokeWebServiceJob job = new InvokeWebServiceJob()
			{
				JobID = UuidHelper.NewUuidString(),
				JobType = JobType.InvokeService,
				Category = "测试权限中心服务",
				Description = "仅用于测试",
				Enabled = true,
				Name = "任务和作业的单元测试",
				SvcOperationDefs = new Workflow.WfServiceOperationDefinitionCollection()
			};

			job.SvcOperationDefs.Add(new Workflow.WfServiceOperationDefinition(new Workflow.WfServiceAddressDefinition(Workflow.WfServiceRequestMethod.Post, null, "http://localhost/MCSWebApp/PermissionCenterServices/services/PermissionCenterToADService.asmx"), "GetVersion", null, string.Empty));
			InvokeWebServiceJobAdapter.Instance.Update(job);

			for (int i = 0; i < 1500; i++)
			{
				DO.SysTask task = new DO.SysTask()
				{
					TaskID = UuidHelper.NewUuidString(),
					TaskTitle = "测试任务" + i,
					ResourceID = job.JobID,
					TaskType = "InvokeService"
				};

				SysTaskAdapter.Instance.Update(task);
			}

			int count = 0;

			var tasks = SysTaskAdapter.Instance.FetchNotRuningSysTasks(-1, m =>
			{
				SysTaskAdapter.Instance.UpdateStatus(m.TaskID, SysTaskStatus.Running);
			});

			Debug.WriteLine(DateTime.Now + "开始执行");
			Stopwatch watch = new Stopwatch();
			watch.Start();
			using (AutoResetEvent eventAuto = new AutoResetEvent(false))
			{
				foreach (var task in tasks)
				{
					ThreadPool.QueueUserWorkItem(item =>
					{
						DO.SysTask curTask = (DO.SysTask)item;
						if (curTask.TaskType == "InvokeService")
						{
							try
							{
								ISysTaskExecutor exec = SysTaskSettings.GetSettings().GetExecutor("InvokeService");
								exec.Execute(curTask);
							}
							catch (Exception exx)
							{
								Debug.WriteLine("出现了意外的错误" + exx.ToString());
							}
							finally
							{
								int newCount = System.Threading.Interlocked.Increment(ref count);
								Debug.WriteLine(DateTime.Now + "当前执行:" + newCount + "当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
								eventAuto.Set();
							}
						}
					}, task);
				}

				int workerThreads, completionPortThreads;
				ThreadPool.GetAvailableThreads(out  workerThreads, out completionPortThreads);

				Debug.WriteLine("线程池可用线程数" + workerThreads);

				while (count != tasks.Count)
				{
					eventAuto.WaitOne();
				}
			}

			watch.Stop();

			Debug.WriteLine(string.Format("耗时 {0}ms", watch.ElapsedMilliseconds));
			Debug.WriteLine(DateTime.Now + "主线程执行结束");
		}
Beispiel #17
0
 /// <summary>
 /// 出现异常,置执行状态,并且移动到已完成中
 /// </summary>
 /// <param name="task"></param>
 /// <param name="ex"></param>
 /// <returns>返回的已完成任务</returns>
 protected virtual SysAccomplishedTask OnError(SysTask task, System.Exception ex)
 {
     //Move,修改Task的状态为Aborted
     return(SysTaskAdapter.Instance.MoveToCompletedSysTask(task, SysTaskStatus.Aborted, ex.GetRealException().ToString()));
 }
        public SysTaskActivity(SysTask task)
        {
            task.NullCheck("task");

            this._Task = task;
        }
Beispiel #19
0
        public void InvokeHugeServiceTasksTest2()
        {
            SysTaskAdapter.Instance.ClearAll();
            SysAccomplishedTaskAdapter.Instance.ClearAll();

            InvokeWebServiceJob job = new InvokeWebServiceJob()
            {
                JobID            = UuidHelper.NewUuidString(),
                JobType          = JobType.InvokeService,
                Category         = "测试权限中心服务",
                Description      = "仅用于测试",
                Enabled          = true,
                Name             = "任务和作业的单元测试",
                SvcOperationDefs = new Workflow.WfServiceOperationDefinitionCollection()
            };

            job.SvcOperationDefs.Add(new Workflow.WfServiceOperationDefinition(new Workflow.WfServiceAddressDefinition(Workflow.WfServiceRequestMethod.Post, null, "http://localhost/MCSWebApp/PermissionCenterServices/services/PermissionCenterToADService.asmx"), "GetVersion", null, string.Empty));
            InvokeWebServiceJobAdapter.Instance.Update(job);

            for (int i = 0; i < 1500; i++)
            {
                DO.SysTask task = new DO.SysTask()
                {
                    TaskID     = UuidHelper.NewUuidString(),
                    TaskTitle  = "测试任务" + i,
                    ResourceID = job.JobID,
                    TaskType   = "InvokeService"
                };

                SysTaskAdapter.Instance.Update(task);
            }

            int count = 0;

            var tasks = SysTaskAdapter.Instance.FetchNotRuningSysTasks(-1, m =>
            {
                SysTaskAdapter.Instance.UpdateStatus(m.TaskID, SysTaskStatus.Running);
            });

            Debug.WriteLine(DateTime.Now + "开始执行");
            Stopwatch watch = new Stopwatch();

            watch.Start();
            using (AutoResetEvent eventAuto = new AutoResetEvent(false))
            {
                foreach (var task in tasks)
                {
                    ThreadPool.QueueUserWorkItem(item =>
                    {
                        DO.SysTask curTask = (DO.SysTask)item;
                        if (curTask.TaskType == "InvokeService")
                        {
                            try
                            {
                                ISysTaskExecutor exec = SysTaskSettings.GetSettings().GetExecutor("InvokeService");
                                exec.Execute(curTask);
                            }
                            catch (Exception exx)
                            {
                                Debug.WriteLine("出现了意外的错误" + exx.ToString());
                            }
                            finally
                            {
                                int newCount = System.Threading.Interlocked.Increment(ref count);
                                Debug.WriteLine(DateTime.Now + "当前执行:" + newCount + "当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
                                eventAuto.Set();
                            }
                        }
                    }, task);
                }

                int workerThreads, completionPortThreads;
                ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);

                Debug.WriteLine("线程池可用线程数" + workerThreads);

                while (count != tasks.Count)
                {
                    eventAuto.WaitOne();
                }
            }

            watch.Stop();

            Debug.WriteLine(string.Format("耗时 {0}ms", watch.ElapsedMilliseconds));
            Debug.WriteLine(DateTime.Now + "主线程执行结束");
        }
Beispiel #20
0
        public void InvokeHugeServiceTasksTest()
        {
            SysTaskAdapter.Instance.ClearAll();
            SysAccomplishedTaskAdapter.Instance.ClearAll();

            InvokeWebServiceJob job = new InvokeWebServiceJob()
            {
                JobID            = UuidHelper.NewUuidString(),
                JobType          = JobType.InvokeService,
                Category         = "测试权限中心服务",
                Description      = "仅用于测试",
                Enabled          = true,
                Name             = "任务和作业的单元测试",
                SvcOperationDefs = new Workflow.WfServiceOperationDefinitionCollection()
            };

            job.SvcOperationDefs.Add(new Workflow.WfServiceOperationDefinition(new Workflow.WfServiceAddressDefinition(Workflow.WfServiceRequestMethod.Post, null, "http://localhost/MCSWebApp/PermissionCenterServices/services/PermissionCenterToADService.asmx"), "GetVersion", null, string.Empty));
            InvokeWebServiceJobAdapter.Instance.Update(job);

            for (int i = 0; i < 400; i++)
            {
                DO.SysTask task = new DO.SysTask()
                {
                    TaskID     = UuidHelper.NewUuidString(),
                    TaskTitle  = "测试任务" + i,
                    ResourceID = job.JobID,
                    TaskType   = "InvokeService"
                };

                SysTaskAdapter.Instance.Update(task);
            }

            int count = 0;
            var tasks = SysTaskAdapter.Instance.FetchNotRuningSysTasks(800, m =>
            {
                SysTaskAdapter.Instance.UpdateStatus(m.TaskID, SysTaskStatus.Running);
            });
            Thread thread = Thread.CurrentThread;

            Assert.AreEqual(400, tasks.Count);

            Debug.WriteLine(DateTime.Now + "开始执行");
            Stopwatch watch = new Stopwatch();

            watch.Start();

            var result = System.Threading.Tasks.Parallel.ForEach <DO.SysTask>(tasks, t =>
            {
                if (t.TaskType == "InvokeService")
                {
                    Debug.WriteLine(DateTime.Now + "当前执行:" + System.Threading.Interlocked.Increment(ref count) + "  主线程状态" + thread.ThreadState + "当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
                    ISysTaskExecutor exec = SysTaskSettings.GetSettings().GetExecutor("InvokeService");
                    exec.Execute(t);
                }
            });

            watch.Stop();

            Debug.WriteLine(string.Format("已完成所有任务: {0} 耗时 {1}ms", result.IsCompleted, watch.ElapsedMilliseconds));
            Debug.WriteLine(DateTime.Now + "主线程执行结束");
        }
        protected override void OnExecute(SysTask task)
        {
            JobBase job = GetJobInfo(task);

            job.Start();
        }
Beispiel #22
0
 public TxActivityActionServiceTask(SysTask other)
     : base(other)
 {
 }
 public ExecuteSysTaskActivityTask(SysTask other)
     : base(other)
 {
     this.AfterLoad();
 }
Beispiel #24
0
        protected override SysAccomplishedTask OnError(SysTask task, Exception ex)
        {
            DoCompensationAction(task);

            return(base.OnError(task, ex));
        }