/// <summary>
 /// 得到当前的流程实例
 /// </summary>
 /// <returns></returns>
 public WorkflowInstance GetWorkflowInstance()
 {
     if (_workflowInstance == null)
     {
         _workflowInstance = this.GetContext().Store.GetWorkflowInstance(this.WorkflowInstanceGuid);
         _workflowInstance.SetContext(this.GetContext());
     }
     return _workflowInstance;
 }
 public bool SetWorkflowInstance(WorkflowInstance wfi, eStoreType storeType)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// 保存工作流实例
 /// </summary>
 /// <param name="wfi"></param>
 /// <param name="storeType"></param>
 /// <returns></returns>
 bool SetWorkflowInstance(WorkflowInstance wfi, eStoreType storeType)
 {
     return this.Context.Store.SetWorkflowInstance(wfi, storeType);
 }
        /// <summary>
        /// 用途:创建流程实例并返回首个流程活动工作项
        /// 约定:
        /// 1、一个流程有且仅有一个根活动
        /// 2、代理人不能发起委托人的新流程,只能处理委托日期后正在流转的流程数据
        /// 3、有发起流程模型权限方可以操作
        /// </summary>
        /// <param name="workflowGuid">流程模型guid</param>
        /// <returns>首个流程活动工作项</returns>
        public ResponseByWorkitem CreateWorkflowInstance(string workflowGuid, string name = null)
        {
            ///创建流程实例
            WorkflowInstance wfi = new WorkflowInstance(workflowGuid, name);
            //wfi.Guid ...
            //wfi.Name ...
            //wfi.WorkflowGuid ...
            wfi.Author = this.Context.CurUser;
            //wfi.WorkflowState ...
            //wfi.Participator ...
            //wfi.Locker ...
            //wfi.BeginTime ...;
            //wfi.EndTime ...;
            //wfi.DataEntity ...

            wfi.SetContext(this.Context);

            ///加入权限控制
            if (!(this.Context.CurUser.IsAdministrator()//是否大管理员
                  || wfi.GetWorkflow().IsAdministrators(this.Context.CurUser)//是否流程模型管理员
                  || wfi.GetWorkflow().IsLegalAuthor(this.Context.CurUser)//流程的合法发起用户
                  ))
            { return new ResponseByWorkitem() { CallBackMessage = new ResultMessage() { State = false, Message = "不能发起流程!" } }; }

            ///开启流程实例服务
            wfi.Start();
            wfi.Save();

            //创建活动实例
            WorkitemInstance wii = new WorkitemInstance(wfi.Guid, wfi.GetWorkflow().GetStartNode());
            //wii.Guid ...
            //wii.Name ...
            //wii.ActivityGuid ...
            //wii.WorkflowInstanceGuid ...
            //wii.AduitContent = "";
            //wii.AduitSign = "";
            //wii.ReadTime = null;
            //wii.NextActivities = null;
            wii.User = this.Context.CurUser;
            //wii.ProxyUser = null;
            //wii.IsProxy = false;
            //wii.WorkitemInstanceState ...
            //wii.FromWorkitemInstanceGuid = "";
            //wii.AttachmentTrainsitions = null;
            //wii.SelectVoteItem = "";
            //wii.OtherVoteItemContent = "";
            //wii.BeginTime ...;
            //wii.EndTime ...;
            //wii.DataEntity ...

            wii.SetContext(this.Context);
            ///开启活动实例
            wii.Start();
            wii.Save();
            ///活动前事件处理
            var rm = wii.BeforeTrigger();

            ResponseByWorkitem response;

            ///如果不满足
            if (!rm.State)
            {
                response = new ResponseByWorkitem()
                {
                    ActivityInstance = wii,
                    //NextMaybeActivities=null,
                    UIRight = this.Context.Config.RightByReadOnly,
                    CallBackMessage = rm,
                };
            }
            else
            {
                response = new ResponseByWorkitem()
                {
                    ActivityInstance = wii,
                    NextMaybeActivities = wii.GetNextEffectiveActivities(),
                    UIRight = wii.GetActivity().UIRight,
                    CallBackMessage = new ResultMessage() { State = true, Message = "" },
                };
            }
            return response;
        }