Beispiel #1
0
 internal void Initialize()
 {
     this._workItemState             = WorkItem.WorkItemState.InQueue;
     this._workItemCompleted         = null;
     this._workItemCompletedRefCount = 0;
     this._waitingOnQueueStopwatch   = new Stopwatch();
     this._processingStopwatch       = new Stopwatch();
     this._expirationTime            = ((this._workItemInfo.Timeout > 0L) ? (DateTime.UtcNow.Ticks + this._workItemInfo.Timeout * 10000L) : 9223372036854775807L);
 }
Beispiel #2
0
 private void SetWorkItemState(WorkItem.WorkItemState workItemState)
 {
     Monitor.Enter(this);
     try
     {
         if (WorkItem.IsValidStatesTransition(this._workItemState, workItemState))
         {
             this._workItemState = workItemState;
         }
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
        /// <summary>
        /// 获取查询任务的状态
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public WorkItem.WorkItemState GetWorkItemState(int value)
        {
            WorkItem.WorkItemState state = new WorkItem.WorkItemState();
            switch (value)
            {
            case 0: state = WorkItem.WorkItemState.Unfinished; break;

            case 1: state = WorkItem.WorkItemState.Finished; break;

            case 2: state = WorkItem.WorkItemState.Canceled; break;

            default: state = WorkItem.WorkItemState.Unspecified; break;
            }
            return(state);
        }
 public JsonResult GetMyWorkItem(PagerInfo pagerInfo, string FunctionCode, int State, string WorkflowCode, DateTime?StartTime, DateTime?EndTime)
 {
     return(this.ExecuteFunctionRun(() =>
     {
         WorkItem.WorkItemState workitemState = GetWorkItemState(State);
         total_Workitem total_workitem = this.GetWorkItemTable(pagerInfo, workitemState, WorkflowCode,
                                                               StartTime, EndTime);
         DataTable dtWorkitem = total_workitem.dt;
         int total = total_workitem.total;
         string[] columns = new string[] { WorkItem.WorkItem.PropertyName_OrgUnit };
         List <WorkItemViewModel> griddata = this.Getgriddata(dtWorkitem, columns);
         GridViewModel <WorkItemViewModel> result = new GridViewModel <WorkItemViewModel>(total, griddata, pagerInfo.sEcho);
         return Json(result, JsonRequestBehavior.AllowGet);
     }));
 }
Beispiel #5
0
        private static bool IsValidStatesTransition(WorkItem.WorkItemState currentState, WorkItem.WorkItemState nextState)
        {
            bool result = false;

            switch (currentState)
            {
            case WorkItem.WorkItemState.InQueue:
                result = (WorkItem.WorkItemState.InProgress == nextState || WorkItem.WorkItemState.Canceled == nextState);
                break;

            case WorkItem.WorkItemState.InProgress:
                result = (WorkItem.WorkItemState.Completed == nextState || WorkItem.WorkItemState.Canceled == nextState);
                break;
            }
            return(result);
        }
Beispiel #6
0
 private WorkItem.WorkItemState GetWorkItemState()
 {
     Monitor.Enter(this);
     WorkItem.WorkItemState result;
     try
     {
         if (WorkItem.WorkItemState.Completed == this._workItemState)
         {
             result = this._workItemState;
         }
         else
         {
             long ticks = DateTime.UtcNow.Ticks;
             if (WorkItem.WorkItemState.Canceled != this._workItemState && ticks > this._expirationTime)
             {
                 this._workItemState = WorkItem.WorkItemState.Canceled;
             }
             if (WorkItem.WorkItemState.InProgress == this._workItemState)
             {
                 result = this._workItemState;
             }
             else
             {
                 if (this.CanceledSmartThreadPool.IsCanceled || this.CanceledWorkItemsGroup.IsCanceled)
                 {
                     result = WorkItem.WorkItemState.Canceled;
                 }
                 else
                 {
                     result = this._workItemState;
                 }
             }
         }
     }
     finally
     {
         Monitor.Exit(this);
     }
     return(result);
 }
        private total_Workitem GetWorkItemTable(PagerInfo pagerInfo, WorkItem.WorkItemState State, string WorkflowCode, DateTime?StartTime, DateTime?EndTime)
        {
            total_Workitem total_workitem = new total_Workitem();

            if (State == WorkItem.WorkItemState.Unspecified)
            {
                string[] conditions = Engine.PortalQuery.GetWorkItemConditions(this.UserValidator.UserID,
                                                                               StartTime == null ? DateTime.MinValue : StartTime.Value,
                                                                               EndTime == null ? DateTime.MaxValue : EndTime.Value,
                                                                               State,
                                                                               string.Empty,
                                                                               OThinker.Data.BoolMatchValue.Unspecified,
                                                                               WorkflowCode,
                                                                               true,
                                                                               WorkItem.WorkItem.TableName);
                string OrderBy = "ORDER BY " +
                                 WorkItem.WorkItem.TableName + "." + WorkItem.WorkItem.PropertyName_Priority + " DESC," +
                                 WorkItem.WorkItem.TableName + "." + WorkItem.WorkItem.PropertyName_ReceiveTime + " DESC";
                DataTable dtWorkitem = Engine.PortalQuery.QueryWorkItem(conditions, pagerInfo.StartIndex, pagerInfo.EndIndex, OrderBy, WorkItem.WorkItem.TableName);
                int       total      = Engine.PortalQuery.CountWorkItem(conditions, WorkItem.WorkItem.TableName); // 记录总数

                string[] conditions1 = Engine.PortalQuery.GetWorkItemConditions(this.UserValidator.UserID,
                                                                                StartTime == null ? DateTime.MinValue : StartTime.Value,
                                                                                EndTime == null ? DateTime.MaxValue : EndTime.Value,
                                                                                State,
                                                                                string.Empty,
                                                                                OThinker.Data.BoolMatchValue.Unspecified,
                                                                                WorkflowCode,
                                                                                true,
                                                                                WorkItem.WorkItemFinished.TableName);
                string OrderBy1 = "ORDER BY " +
                                  WorkItem.WorkItemFinished.TableName + "." + WorkItem.WorkItemFinished.PropertyName_Priority + " DESC," +
                                  WorkItem.WorkItemFinished.TableName + "." + WorkItem.WorkItemFinished.PropertyName_ReceiveTime + " DESC";
                DataTable dtWorkitem1 = Engine.PortalQuery.QueryWorkItem(conditions1, pagerInfo.StartIndex, pagerInfo.EndIndex, OrderBy1, WorkItem.WorkItemFinished.TableName);
                total = total + Engine.PortalQuery.CountWorkItem(conditions1, WorkItem.WorkItemFinished.TableName); // 记录总数
                if (dtWorkitem != null)
                {
                    dtWorkitem.Merge(dtWorkitem1);
                }
                else
                {
                    dtWorkitem = dtWorkitem1;
                }

                total_workitem.total = total;
                total_workitem.dt    = dtWorkitem;
                return(total_workitem);
            }
            else
            {
                string   TableName  = State == WorkItem.WorkItemState.Finished ? WorkItem.WorkItemFinished.TableName : WorkItem.WorkItem.TableName;
                string[] conditions = Engine.PortalQuery.GetWorkItemConditions(this.UserValidator.UserID,
                                                                               StartTime == null ? DateTime.MinValue : StartTime.Value,
                                                                               EndTime == null ? DateTime.MaxValue : EndTime.Value,
                                                                               State,
                                                                               string.Empty,
                                                                               OThinker.Data.BoolMatchValue.Unspecified,
                                                                               WorkflowCode,
                                                                               true,
                                                                               TableName);
                string OrderBy = "ORDER BY " +
                                 WorkItem.WorkItemFinished.TableName + "." + WorkItem.WorkItemFinished.PropertyName_Priority + " DESC," +
                                 WorkItem.WorkItemFinished.TableName + "." + WorkItem.WorkItemFinished.PropertyName_ReceiveTime + " DESC";
                DataTable dtWorkitem = Engine.PortalQuery.QueryWorkItem(conditions, pagerInfo.StartIndex, pagerInfo.EndIndex, OrderBy, TableName);
                int       total      = Engine.PortalQuery.CountWorkItem(conditions, TableName); // 记录总数
                var       result     = new
                {
                    total      = total,
                    dtWorkitem = dtWorkitem
                };
                total_workitem.total = total;
                total_workitem.dt    = dtWorkitem;
                return(total_workitem);
            }
        }
        /// <summary>
        /// 查询任务,不同状态的任务处于不同的表
        /// </summary>
        /// <param name="pagerInfo"></param>
        /// <param name="instanceName"></param>
        /// <param name="workflowCode"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="userName"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public JsonResult QueryParticipantWorkItems(PagerInfo pagerInfo, string instanceName, string workflowCode, string participant, DateTime?startTime, DateTime?endTime, int state)
        {
            return(this.ExecuteFunctionRun(() =>
            {
                List <WorkItemViewModel> griddata = new List <WorkItemViewModel>();
                GridViewModel <WorkItemViewModel> result = new GridViewModel <WorkItemViewModel>(0, griddata, pagerInfo.sEcho);
                // 验证权限
                string[] workflowCodeArray = string.IsNullOrEmpty(workflowCode) ? null : workflowCode.Split(',');
                string[] participantArray = string.IsNullOrEmpty(participant) ? null : participant.Split(',');
                var queryAcl = this.GetQueryAcl(ref workflowCodeArray, ref participantArray);
                if (workflowCodeArray != null)
                {
                    workflowCode = string.Join(",", workflowCodeArray);
                }
                if (participantArray != null)
                {
                    participant = string.Join(",", participantArray);
                }

                if (!queryAcl.Success && (workflowCodeArray == null || workflowCodeArray.Length == 0) && (participantArray == null || participantArray.Length == 0))
                {
                    result.ExtendProperty = queryAcl;
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                //if (string.IsNullOrEmpty(participant))
                //{
                //    var extend = new
                //    {
                //        Success = false,
                //        Message = "QueryParticipantWorkItem_NoParticipant"
                //    };
                //    result.ExtendProperty = extend;
                //    return Json(result, JsonRequestBehavior.AllowGet);
                //}
                //if (participant == this.UserValidator.User.ObjectID)
                //{ }
                //else if (this.UserValidator.ValidateAdministrator())
                //{ }
                //else if (this.UserValidator.ValidateOrgView(participant))
                //{ }
                //else if (!string.IsNullOrEmpty(workflowCode) &&
                //   this.UserValidator.ValidateWFInsView(workflowCode,
                //   participant))
                //{ }
                //else
                //{
                //    var extend = new
                //    {
                //        Success = false,
                //        Message = "DataFilter_NotEnoughAuth"
                //    };
                //    result.ExtendProperty = extend;
                //    return Json(result, JsonRequestBehavior.AllowGet);
                //}

                WorkItem.WorkItemState workitemState = GetWorkItemState(state);
                string tableName = "";
                switch (workitemState)
                {
                //此处取消 的表取确认
                case WorkItem.WorkItemState.Unfinished: tableName = WorkItem.WorkItem.TableName; break;

                case WorkItem.WorkItemState.Finished: tableName = WorkItem.WorkItemFinished.TableName; break;

                default: tableName = WorkItem.WorkItemFinished.TableName; break;
                }

                string[] conditions = Engine.PortalQuery.GetWorkItemConditions(participant,
                                                                               startTime == null ? DateTime.MinValue : startTime.Value,
                                                                               endTime == null ? DateTime.MaxValue : endTime.Value.AddDays(1),
                                                                               workitemState, instanceName, OThinker.Data.BoolMatchValue.Unspecified, workflowCode, true, tableName);

                string orderBy = "";
                switch (workitemState)
                {
                //case 0: state = WorkItem.WorkItemState.Unfinished; break;
                case WorkItem.WorkItemState.Unfinished: orderBy = " ORDER BY " + tableName + "." + WorkItem.WorkItem.PropertyName_ReceiveTime + " DESC "; break;

                case WorkItem.WorkItemState.Finished: orderBy = " ORDER BY " + tableName + "." + WorkItem.WorkItem.PropertyName_FinishTime + " DESC "; break;

                case WorkItem.WorkItemState.Canceled: orderBy = " ORDER BY " + tableName + "." + WorkItem.WorkItem.PropertyName_FinishTime + " DESC "; break;
                }
                DataTable dtWorkitem = Engine.PortalQuery.QueryWorkItem(conditions, pagerInfo.StartIndex, pagerInfo.EndIndex, orderBy, tableName);
                int total = Engine.PortalQuery.CountWorkItem(conditions, tableName); // 记录总数
                string[] columns = new string[] { WorkItem.WorkItem.PropertyName_OrgUnit, WorkItem.WorkItem.PropertyName_WorkflowCode };
                griddata = this.Getgriddata(dtWorkitem, columns);
                result = new GridViewModel <WorkItemViewModel>(total, griddata, pagerInfo.sEcho);

                if (!queryAcl.Success)
                {
                    result.ExtendProperty = queryAcl;
                }
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }