public UserTaskCollection LoadUserTasksByActivity(string activityID, Action<InSqlClauseBuilder> action)
		{
			action.NullCheck("action");

			InSqlClauseBuilder builder = new InSqlClauseBuilder();

			action(builder);

			string sql = string.Format("SELECT * FROM WF.USER_TASK WHERE ACTIVITY_ID = {0}",
				TSqlBuilder.Instance.CheckUnicodeQuotationMark(activityID));

			if (builder.Count > 0)
				sql += " AND " + builder.ToSqlStringWithInOperator(TSqlBuilder.Instance);

			UserTaskCollection result = new UserTaskCollection();

			DataTable table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0];

			foreach (DataRow row in table.Rows)
			{
				UserTask task = new UserTask();

				ORMapping.DataRowToObject(row, task);

				result.Add(task);
			}

			return result;
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fillAssignees"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public WfProcessCurrentInfoCollection Load(bool fillAssignees, Action<WhereSqlClauseBuilder> action)
        {
            action.NullCheck("action");

            WfProcessCurrentInfoCollection result = new WfProcessCurrentInfoCollection();

            WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder();

            action(whereBuilder);

            string fieldNames = ORMapping.GetSelectFieldsNameSql<WfProcessInstanceData>("Data");

            string sql = string.Format("SELECT {0} FROM WF.PROCESS_INSTANCES WHERE {1}",
                    fieldNames,
                    whereBuilder.ToSqlString(TSqlBuilder.Instance));

            DataTable table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0];

            result.LoadFromDataView(table.DefaultView);

            if (fillAssignees)
                FillAssignees(result);

            return result;
        }
        /// <summary>
        /// 操作执行的包装类,在操作的开始和结束输出时间信息
        /// </summary>
        /// <param name="operationName"></param>
        /// <param name="action"></param>
        private static void ExecutionWrapper(string operationName, Action action)
        {
            operationName.CheckStringIsNullOrEmpty("operationName");
            action.NullCheck("action");

            WfExecutorLogContextInfo.Writer.WriteLine("\t\t{0}开始:{1:yyyy-MM-dd HH:mm:ss.fff}",
                    operationName, DateTime.Now);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            try
            {
                action();
            }
            finally
            {
                sw.Stop();
                WfExecutorLogContextInfo.Writer.WriteLine("\t\t{0}结束:{1:yyyy-MM-dd HH:mm:ss.fff};经过时间:{2:#,##0}毫秒",
                    operationName, DateTime.Now, sw.ElapsedMilliseconds);
            }
        }
		/// <summary>
		/// 执行操作,通过日志输出操作时间
		/// </summary>
		/// <param name="operationName"></param>
		/// <param name="action"></param>
		public void ExecutionWrapper(string operationName, Action action)
		{
			operationName.CheckStringIsNullOrEmpty("operationName");
			action.NullCheck("action");

			ProcessProgress.Current.Output.WriteLine("\t\t{0}开始:{1:yyyy-MM-dd HH:mm:ss.fff}",
					operationName, DateTime.Now);

			Stopwatch sw = new Stopwatch();

			sw.Start();
			try
			{
				action();
			}
			finally
			{
				sw.Stop();
				ProcessProgress.Current.Output.WriteLine("\t\t{0}结束:{1:yyyy-MM-dd HH:mm:ss.fff};经过时间:{2:#,##0}毫秒",
					operationName, DateTime.Now, sw.ElapsedMilliseconds);
			}
		}
		public UserTaskCollection LoadUserTasks(Action<WhereSqlClauseBuilder> action)
		{
			action.NullCheck("action");

			WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

			action(builder);

			string sql = string.Format("SELECT * FROM WF.USER_TASK WHERE {0}", builder.ToSqlString(TSqlBuilder.Instance));

			UserTaskCollection result = new UserTaskCollection();

			DataTable table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0];

			foreach (DataRow row in table.Rows)
			{
				UserTask task = new UserTask();

				ORMapping.DataRowToObject(row, task);

				result.Add(task);
			}

			return result;
		}
        private WfProcessCollection LoadProcesses(Action<WhereSqlClauseBuilder> action)
        {
            action.NullCheck("action");

            var whereBuilder = new WhereSqlClauseBuilder();

            action(whereBuilder);

            var mapping = ORMapping.GetMappingInfo<WfProcessInstanceData>();

            string[] fields = ORMapping.GetSelectFieldsName(mapping, "Data");

            var sql = string.Format("SELECT {0},{1} FROM {2} WHERE {3}",
                string.Join(",", fields),
                BINARYDATA,
                mapping.TableName,
                whereBuilder.ToSqlString(TSqlBuilder.Instance));

            var table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0];

            WfProcessCollection result = null;

            PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("DataTableToProcessCollection",
                () => result = DataTableToProcessCollection(table)
            );

            return result;
        }
        private void DeleteProcesses(Action<WhereSqlClauseBuilder> action)
        {
            action.NullCheck("action");

            ORMappingItemCollection mapping = ORMapping.GetMappingInfo<WfProcessInstanceData>();

            WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder();

            action(whereBuilder);

            string sql = string.Format("DELETE {0} WHERE {1}", mapping.TableName, whereBuilder.ToSqlString(TSqlBuilder.Instance));
            WfProcessCurrentInfoCollection processesInfo = WfProcessCurrentInfoAdapter.Instance.Load(false, action);

            Dictionary<object, object> context = new Dictionary<object, object>();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DbHelper.RunSql(sql, GetConnectionName());

                WfProcessCurrentActivityAdapter.Instance.DeleteProcessActivities(processesInfo);
                WfRelativeProcessAdapter.Instance.Delete(processesInfo);

                WfExtraPersistenceSettings.GetConfig().GetPersisters().DeleteData(processesInfo, context);

                scope.Complete();
            }
        }
        /// <summary>
        /// 删除EmailMessage
        /// </summary>
        /// <param name="action"></param>
        public void Delete(Action<WhereSqlClauseBuilder> action)
        {
            action.NullCheck("action");

            WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

            action(builder);
            builder.AppendTenantCode();

            StringBuilder strB = new StringBuilder();

            using (StringWriter writer = new StringWriter(strB))
            {
                WriteDeleteEmailAddressesSql(writer, builder);
                WriteDeleteEmailAttachmentsSql(writer, builder);
                writer.WriteLine("DELETE MSG.EMAIL_MESSAGES WHERE {0}",
                    builder.ToSqlString(TSqlBuilder.Instance));
            }

            DbHelper.RunSqlWithTransaction(strB.ToString(), GetConnectionName());
        }
        private static WfClientProcessInfo ExecuteProcessAction(string processID, WfClientRuntimeContext runtimeContext, Action<IWfProcess> action)
        {
            processID.CheckStringIsNullOrEmpty("processID");
            action.NullCheck("action");

            IWfProcess process = GetProcessByProcessID(processID, runtimeContext);

            MeregeRuntimeContext(process, runtimeContext);

            DoPrincipalAction(runtimeContext, () => action(process));

            return process.ToClientProcessInfo(runtimeContext.Operator);
        }