예제 #1
0
        protected override void Execute(NativeActivityContext context)
        {
            DesignService designService = new DesignService();

            //启动事务
            using (TransactionScope trans = new TransactionScope())
            {
                //添加工作流活动实例
                DynEntity workflowfActivityInstance = new DynEntity("WorkflowActivityInstance");
                workflowfActivityInstance["WorkflowActivityInstanceID"]   = designService.GetNextID("WorkflowActivityInstance");
                workflowfActivityInstance["WorkflowInstanceID"]           = context.GetValue(WorkflowInstanceID);
                workflowfActivityInstance["WorkflowActivityID"]           = WorkflowActivityID;
                workflowfActivityInstance["WorkflowActivityInstanceName"] = DisplayName;
                workflowfActivityInstance["State"]     = "已退回";
                workflowfActivityInstance["StartTime"] = DateTime.Now;
                designService.AddDynEntity(workflowfActivityInstance);

                //获取工作流实例
                DynEntity workflowInstance = designService.GetDynEntityByID("WorkflowInstance", context.GetValue(WorkflowInstanceID));
                int       workflowID;
                if (workflowInstance != null)
                {
                    workflowID = Convert.ToInt32(workflowInstance["WorkflowID"]);
                }
                else
                {
                    throw new ApplicationException(string.Format("{0}实例下的活动{1},根据工作流实例ID获取工作流实例不正常", context.GetValue(WorkflowInstanceID), DisplayName));
                }

                //添加待做任务清单
                DynEntity task = new DynEntity("WorkflowToDoList");

                task["WorkflowToDoListID"] = designService.GetNextID("WorkflowToDoList");
                task["Type"]       = context.GetValue(Type).ToString();
                task["Item"]       = context.GetValue(Item).ToString();
                task["Position"]   = context.GetValue(Position).ToString();
                task["FirstActor"] = context.GetValue(FirstActor);
                task["LastActor"]  = context.GetValue(LastActor);

                string command = context.GetValue(Command);
                Dictionary <string, object> inParams = this.ExchangeParams.Get(context) as Dictionary <string, object>;
                foreach (string key in inParams.Keys)
                {
                    if (inParams[key] != null)
                    {
                        command = command.Replace("@" + key + "@", inParams[key].ToString());
                    }
                }

                task["WorkflowToDoListName"]       = DisplayName;
                task["WorkflowID"]                 = workflowID;
                task["WorkflowInstanceID"]         = context.GetValue(WorkflowInstanceID);
                task["WorkflowActivityInstanceID"] = workflowfActivityInstance["WorkflowActivityInstanceID"];
                task["Expression"]                 = context.GetValue(Expression);
                task["BookmarkName"]               = workflowfActivityInstance["WorkflowActivityInstanceID"].ToString();
                task["Command"] = command;
                task["Comment"] = context.GetValue(Description);
                task["State"]   = "已退回";

                if (inParams.ContainsKey("TableName"))
                {
                    task["TableName"] = inParams["TableName"].ToString();
                }
                if (inParams.ContainsKey("TableKey"))
                {
                    task["TableKey"] = inParams["TableKey"].ToString();
                }

                designService.AddDynEntity(task);

                if (inParams.ContainsKey("TableName") && inParams.ContainsKey("TableKey"))
                {
                    designService.TerminateWorkflow(inParams["TableName"].ToString(), inParams["TableKey"].ToString());
                }

                workflowInstance["EndTime"] = DateTime.Now;
                workflowInstance["State"]   = "已结束";

                designService.ModifyDynEntity(workflowInstance);

                trans.Complete();
            }
        }
예제 #2
0
        protected override void Execute(NativeActivityContext context)
        {
            DesignService designService = new DesignService();

            //启动事务
            using (TransactionScope trans = new TransactionScope())
            {
                //获取传入的参数集合
                Dictionary <string, object> inParams = this.ExchangeParams.Get(context) as Dictionary <string, object>;
                //添加工作流活动实例
                DynEntity workflowfActivityInstance = new DynEntity("WorkflowActivityInstance");
                workflowfActivityInstance["WorkflowActivityInstanceID"]   = designService.GetNextID("WorkflowActivityInstance");
                workflowfActivityInstance["WorkflowInstanceID"]           = context.GetValue(WorkflowInstanceID);
                workflowfActivityInstance["WorkflowActivityID"]           = WorkflowActivityID;
                workflowfActivityInstance["WorkflowActivityInstanceName"] = DisplayName;
                if (inParams.ContainsKey("ObjType"))
                {
                    workflowfActivityInstance["ObjType"] = inParams["ObjType"].ToString();
                }
                if (inParams.ContainsKey("ObjID"))
                {
                    workflowfActivityInstance["ObjID"] = inParams["ObjID"].ToString();
                }
                workflowfActivityInstance["State"]     = "正在执行";
                workflowfActivityInstance["StartTime"] = DateTime.Now;
                designService.AddDynEntity(workflowfActivityInstance);

                //获取工作流实例
                DynEntity workflowInstance = designService.GetDynEntityByID("WorkflowInstance", context.GetValue(WorkflowInstanceID));
                int       workflowID;
                if (workflowInstance != null)
                {
                    workflowID = Convert.ToInt32(workflowInstance["WorkflowID"]);
                }
                else
                {
                    throw new ApplicationException(string.Format("{0}实例下的活动{1},根据工作流实例ID获取工作流实例不正常", context.GetValue(WorkflowInstanceID), DisplayName));
                }

                //添加待做任务清单
                DynEntity task = new DynEntity("WorkflowToDoList");
                task["WorkflowToDoListID"] = designService.GetNextID("WorkflowToDoList");
                //task["Actor"] = context.GetValue(Actor);



                task["WorkflowToDoListName"]       = DisplayName;
                task["WorkflowID"]                 = workflowID;
                task["WorkflowInstanceID"]         = context.GetValue(WorkflowInstanceID);
                task["WorkflowActivityInstanceID"] = workflowfActivityInstance["WorkflowActivityInstanceID"];
                task["BookmarkName"]               = workflowfActivityInstance["WorkflowActivityInstanceID"].ToString();
                task["State"] = "待处理";

                if (inParams.ContainsKey("ObjType"))
                {
                    task["ObjType"] = inParams["ObjType"].ToString();
                }
                if (inParams.ContainsKey("ObjID"))
                {
                    task["ObjID"] = inParams["ObjID"].ToString();
                }
                designService.AddDynEntity(task);
                context.CreateBookmark(workflowfActivityInstance["WorkflowActivityInstanceID"].ToString(), new BookmarkCallback(BookmarkCallbackMethod));

                trans.Complete();
            }
        }